Package com.adito.security

Examples of com.adito.security.Role


        Role[] currentRoles = getDefaultUserDatabase().listAllRoles(UserDatabase.WILDCARD_SEARCH, Integer.MAX_VALUE);
        int currentNumberOfRoles = currentRoles.length;
        assertEquals("There should only be the 1 role 'Users'.", getDefaultUserDatabase().listAllRoles(
            UserDatabase.WILDCARD_SEARCH, Integer.MAX_VALUE).length, 1);
        // create 6 roles
        Role role1 = createRole("aaaa");
        Role role2 = createRole("abbb");
        Role role3 = createRole("aabb");
        Role role4 = createRole("aaab");
        Role role5 = createRole("bbbb");
        Role role6 = createRole("xaax");
        assertEquals("There should be the seven roles.", getDefaultUserDatabase().listAllRoles(UserDatabase.WILDCARD_SEARCH,
            Integer.MAX_VALUE).length, currentNumberOfRoles + 6);
        assertEquals("There should be the five roles.", getDefaultUserDatabase().listAllRoles("a*", Integer.MAX_VALUE).length, 4);
        assertEquals("There should be the three roles.", getDefaultUserDatabase().listAllRoles("aa*", Integer.MAX_VALUE).length, 3);
        assertEquals("There should be the two roles.", getDefaultUserDatabase().listAllRoles("aaa*", Integer.MAX_VALUE).length, 2);
View Full Code Here


     * @throws Exception on any error
     */
    public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
      UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(getSessionInfo(request).getUser().getRealm());
        Role r = udb.getRole(
                        ((ShowAvailableRolesForm) form).getSelectedItem());
        request.setAttribute(Constants.EDITING_ITEM, r);
        return mapping.findForward("edit");
    }
View Full Code Here

    public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
      PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_DELETE, request);
      UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(getSessionInfo(request).getUser().getRealm());
        String rolename = request.getParameter("rolename");
        Role role = udb.getRole(rolename);
        SessionInfo info = this.getSessionInfo(request);
        try {
            // Revoke all polices from the user
            PolicyDatabaseFactory.getInstance().revokeAllPoliciesFromPrincipal(role);
           
View Full Code Here

    @Test
    public void attachDetachPolicyToRole() throws Exception {
        Realm realm = getUserService().getDefaultRealm();
        Policy policy = createPolicy(realm);
        User user = createAccount();
        Role role = createRole("Group1");
        user = updateAccountRoles(user, Collections.singleton(role));
        getPolicyService().grantPolicyToPrincipal(policy, role);
        assertTrue("The policy should be granted", PolicyDatabaseFactory.getInstance().isPolicyGrantedToUser(policy, user));
        getPolicyService().revokePolicyFromPrincipal(policy, role);
        assertFalse("The policy should not be granted", PolicyDatabaseFactory.getInstance().isPolicyGrantedToUser(policy, user));
View Full Code Here

     * @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");
    }
View Full Code Here

    }

    private void createRole(RoleForm roleForm, SessionInfo sessionInfo) throws Exception {
        UserDatabase userDatabase = UserDatabaseManager.getInstance().getUserDatabase(sessionInfo.getUser().getRealm());
        try {
            Role role = userDatabase.createRole(roleForm.getRolename());
            List<String> selectedUsers = roleForm.getUserList();
            updateUserRoles(role, selectedUsers, userDatabase.getRealm());
            fireSuccessfulEvent(sessionInfo, CoreEventConstants.GROUP_CREATED, role, selectedUsers);
        } catch (Exception expt) {
            fireUnsuccessfulEvent(roleForm, sessionInfo, CoreEventConstants.GROUP_CREATED, expt);
View Full Code Here

    }
   
    private String[] updateRole(RoleForm roleForm, SessionInfo sessionInfo) throws Exception {
        UserDatabase userDatabase = UserDatabaseManager.getInstance().getUserDatabase(sessionInfo.getUser().getRealm());
        try {
            Role role = userDatabase.getRole(roleForm.getRolename());
            List<String> selectedUsers = roleForm.getUserList();
            String[] usersNotRemoved = updateUserRoles(role, selectedUsers, userDatabase.getRealm());
            fireSuccessfulEvent(sessionInfo, CoreEventConstants.GROUP_UPDATED, role, selectedUsers);
            return usersNotRemoved;
        } catch (Exception expt) {
View Full Code Here

    }
   
    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()]);
    }
View Full Code Here

            ps.setInt(2, u.getRealm().getResourceId());
      ResultSet r2 = ps.executeQuery();
      List<Role> roles = new ArrayList<Role>();
      try {
        while (r2.next()) {
          Role r = getRole(r2.getString("rolename"));
          roles.add(r);
        }
      } finally {
        r2.close();
      }
View Full Code Here

        }
    }

    private void sendByRole(MessageSender sender, Recipient recipient) throws Exception, RoleNotFoundException, UserDatabaseException {
        UserDatabase userDatabase = UserDatabaseManager.getInstance().getUserDatabase(recipient.getRealmName());
        Role role = userDatabase.getRole(recipient.getRecipientAlias());
        sendByRole(sender, userDatabase, role);
    }
View Full Code Here

TOP

Related Classes of com.adito.security.Role

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.