예제 #1
0
  /**
   * Edit an existing role. The role to edit must be placed in the request attribute
   *
   * @param mapping mapping
   * @param form form
   * @param request request
   * @param response response
   * @return forward
   * @throws Exception on any error
   */
  public ActionForward edit(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    Role role = (Role) request.getAttribute(Constants.EDITING_ITEM);
    if (role == null) {
      throw new Exception("No role configured for editing.");
    }
    PolicyUtil.checkPermission(
        PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE,
        PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN,
        request);
    SessionInfo sessionInfo = getSessionInfo(request);
    UserDatabase userDatabase =
        UserDatabaseManager.getInstance().getUserDatabase(sessionInfo.getUser().getRealm());
    List<User> users = Arrays.asList(userDatabase.getUsersInRole(role));

    RoleForm roleForm = (RoleForm) form;
    roleForm.initialize(users);
    roleForm.setRolename(role.getPrincipalName());
    roleForm.setReferer(CoreUtil.getReferer(request));
    roleForm.setEditing();
    CoreUtil.addRequiredFieldMessage(this, request);
    return mapping.findForward("display");
  }
예제 #2
0
 private Role[] removeRole(Role role, Role[] userRoles) {
   Collection<Role> assignedRoles = new ArrayList<Role>(Arrays.asList(userRoles));
   for (Iterator<Role> itr = assignedRoles.iterator(); itr.hasNext(); ) {
     Role assignedRole = (Role) itr.next();
     if (role.getPrincipalName().equals(assignedRole.getPrincipalName())) {
       itr.remove();
     }
   }
   return assignedRoles.toArray(new Role[assignedRoles.size()]);
 }
예제 #3
0
 private void fireSuccessfulEvent(
     SessionInfo sessionInfo, int eventId, Role role, List<String> selectedUsers) {
   CoreEvent coreEvent = new CoreEvent(this, eventId, role, sessionInfo);
   coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, role.getPrincipalName());
   if (!selectedUsers.isEmpty()) {
     for (int index = 0; index < selectedUsers.size(); index++) {
       String username = selectedUsers.get(index);
       coreEvent.addAttribute(
           CoreAttributeConstants.EVENT_ATTR_ACCOUNT + Integer.valueOf(index), username);
     }
   }
   CoreServlet.getServlet().fireCoreEvent(coreEvent);
 }