Ignore:
Timestamp:
Feb 17, 2017, 11:15:35 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2043: Activating/deactivating roles on the fly in a login session

Implemented support for setting a role as inactive in the core. New public methods are in the SessionControl class.

The getRoles() method has been deprecated and replaced with other methods (since this method return ALL roles including inactive). Code that uses this method for permission checking may experience PermissionDeniedExceptions if a users has de-activated a role.

The "User" menu to the far right has been updated to include a section with roles where the user can toggle the active/inactive status.

The settings are not (yet) remebered between sessions. All roles start out in the active state after logging in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/include/menu.jsp

    r7158 r7294  
    5353  import="net.sf.basedb.core.ItemResultList"
    5454  import="net.sf.basedb.core.Type"
     55  import="net.sf.basedb.core.Role"
    5556  import="net.sf.basedb.core.query.Orders"
    5657  import="net.sf.basedb.core.query.Order"
     
    11621163    final boolean hasImpersonate =
    11631164      !sc.isImpersonated() && sc.hasSystemPermission(Permission.ACT_AS_ANOTHER_USER);
     1165   
     1166    List<Role> roles = null;
     1167    Set<Integer> roleIds = sc.getAllRoles();
     1168    if (roleIds != null && roleIds.size() > 0)
     1169    {
     1170      ItemQuery<Role> roleQuery = Role.getQuery();
     1171      roleQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("roles")));
     1172      roleQuery.setParameter("roles", roleIds, Type.INT);
     1173      roleQuery.order(Orders.asc(Hql.property("name")));
     1174      roles = roleQuery.list(dc);
     1175    }
    11641176    %>
    11651177    <m:menu
     
    11861198        tooltip="<%=menu.getString("logout.tooltip")%>"
    11871199      />
     1200      <%
     1201      if (roles != null && roles.size() > 0)
     1202      {
     1203        %>
     1204        <m:menuseparator />
     1205        <m:menuitem
     1206          title="<%=menu.getString("myroles.title")%>"
     1207          subclass="menusection"
     1208          enabled="false"
     1209        />
     1210        <m:menuseparator />
     1211        <%
     1212        for (Role r : roles)
     1213        {
     1214          boolean isInactive = sc.isRoleInactive(r.getId());
     1215          %>
     1216          <m:menuitem
     1217            title="<%=r.getName() %>"
     1218            tooltip="<%=menu.getString("myroles.tooltip", isInactive)%>"
     1219            icon="<%=isInactive ? "option_unselected.png" : "option_selected.png"%>"
     1220            url="<%=root+"my_base/toggle_active_role.jsp?ID="+ID+"&role_id="+r.getId()%>"
     1221            data-popup="ActivateRole, 300, 200"
     1222          />
     1223          <%
     1224        }
     1225      }
     1226      %>
    11881227    </m:menu>
    11891228    <%
Note: See TracChangeset for help on using the changeset viewer.