Search in sources :

Example 1 with Role

use of org.jaffa.security.securityrolesdomain.Role in project jaffa-framework by jaffa-projects.

the class RoleXmlLoadTest method testRoleRegistration.

/**
 * Verifies that we can register and unregsiter specific roles into the role repository.
 */
@Test
public void testRoleRegistration() {
    RoleManager roleManager = xmlLoaderConfig.getBean(RoleManager.class);
    assertNull(roleManager.getRole("CONTRACTOR"));
    Role contractorRole = new Role();
    GrantFunctionAccess grantFunctionAccess = new GrantFunctionAccess();
    grantFunctionAccess.setName("Function 1");
    contractorRole.getGrantFunctionAccess().add(grantFunctionAccess);
    ContextKey key = new ContextKey("CONTRACTOR", "roles.xml", VariationContext.NULL_VARIATION, "100-Highest");
    roleManager.registerRole(key, contractorRole);
    assertNotNull(roleManager.getRole("CONTRACTOR"));
    roleManager.unregisterRole(key);
    assertNull(roleManager.getRole("CONTRACTOR"));
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) ContextKey(org.jaffa.loader.ContextKey) GrantFunctionAccess(org.jaffa.security.securityrolesdomain.GrantFunctionAccess) Test(org.junit.Test)

Example 2 with Role

use of org.jaffa.security.securityrolesdomain.Role in project jaffa-framework by jaffa-projects.

the class RoleManager method registerResource.

/**
 * registerResource - Registers the roles into the role repository from the roles.xml files found in META-INF/roles.xml
 * that exist in the classpath.
 * @param resource the object that contains the xml config file.
 * @param context  key with which config file to be registered.
 * @throws JAXBException
 * @throws SAXException
 * @throws IOException
 */
@Override
public void registerResource(Resource resource, String context, String variation) throws JAXBException, SAXException, IOException {
    Roles roles = JAXBHelper.unmarshalConfigFile(Roles.class, resource, CONFIGURATION_SCHEMA_FILE);
    if (roles.getRole() != null) {
        for (final Role role : roles.getRole()) {
            ContextKey key = new ContextKey(role.getName(), resource.getURI().toString(), variation, context);
            registerRole(key, role);
        }
    }
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) ContextKey(org.jaffa.loader.ContextKey) Roles(org.jaffa.security.securityrolesdomain.Roles)

Example 3 with Role

use of org.jaffa.security.securityrolesdomain.Role in project jaffa-framework by jaffa-projects.

the class UserMaintenanceTx method performUserRoleValidations.

private void performUserRoleValidations(String[] userRole, User domain) throws ApplicationExceptions {
    ApplicationExceptions appExps = null;
    boolean foundExcludedRole = false;
    Roles root = PolicyCache.getRoles();
    if (root != null) {
        List roleObjects = root.getRole();
        if (roleObjects != null) {
            for (Iterator it = roleObjects.iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                if (Arrays.binarySearch(userRole, role.getName()) >= 0) {
                    List includes = role.getInclude();
                    if (includes != null) {
                        for (Iterator it2 = includes.iterator(); it2.hasNext(); ) {
                            Include includedObject = (Include) it2.next();
                            String includeName = includedObject.getName();
                            if (Arrays.binarySearch(userRole, includeName) < 0) {
                                if (appExps == null)
                                    appExps = new ApplicationExceptions();
                                appExps.add(new UserMaintenanceException(UserMaintenanceException.PROP_INCLUDED_ROLE_MISSING, role.getName(), includeName));
                            }
                        }
                    }
                    List excludes = role.getExclude();
                    if (excludes != null && !foundExcludedRole) {
                        for (Iterator it2 = excludes.iterator(); it2.hasNext(); ) {
                            Exclude excludedObject = (Exclude) it2.next();
                            String excludeName = excludedObject.getName();
                            if (Arrays.binarySearch(userRole, excludeName) >= 0) {
                                if (appExps == null)
                                    appExps = new ApplicationExceptions();
                                appExps.add(new UserMaintenanceException(UserMaintenanceException.PROP_EXCLUDED_ROLE_PRESENT, role.getName(), excludeName));
                                foundExcludedRole = true;
                            }
                        }
                    }
                }
            }
        }
    }
    if (appExps != null && appExps.size() > 0)
        throw appExps;
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) UserRole(org.jaffa.applications.jaffa.modules.admin.domain.UserRole) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Exclude(org.jaffa.security.securityrolesdomain.Exclude) Include(org.jaffa.security.securityrolesdomain.Include) Roles(org.jaffa.security.securityrolesdomain.Roles) UserMaintenanceException(org.jaffa.applications.jaffa.modules.admin.components.usermaintenance.tx.exceptions.UserMaintenanceException)

Example 4 with Role

use of org.jaffa.security.securityrolesdomain.Role in project jaffa-framework by jaffa-projects.

the class UserMaintenanceForm method initRolesGrid.

/**
 * Initialize the model for the user roles
 */
private GridModel initRolesGrid() {
    GridModel model = new GridModel();
    // Build current list of roles
    Collection userRole = new HashSet();
    UserRoleDto[] userRoleDtos = ((UserMaintenanceComponent) getComponent()).getRelatedObjectUserRoleDto();
    if (userRoleDtos != null && userRoleDtos.length > 0) {
        for (int i = 0; i < userRoleDtos.length; i++) userRole.add(userRoleDtos[i].getRoleName());
    }
    // Get all possible Roles from the roles.xml
    Roles root = PolicyCache.getRoles();
    if (root != null) {
        List roles = root.getRole();
        if (roles != null && roles.size() > 0) {
            GridModelRow row = null;
            int i = 0;
            for (Iterator itr = roles.iterator(); itr.hasNext(); ) {
                Role role = (Role) itr.next();
                // Start of new row
                if (i % USER_ROLES_COLUMNS == 0)
                    row = model.newRow();
                String suffix = "" + i % USER_ROLES_COLUMNS;
                row.addElement("rolename" + suffix, role.getName());
                row.addElement("description" + suffix, role.getDescription());
                CheckBoxModel cb = new CheckBoxModel(userRole.contains(role.getName()));
                row.addElement("checkbox" + suffix, cb);
                i++;
            }
        }
    }
    return model;
}
Also used : Roles(org.jaffa.security.securityrolesdomain.Roles) Role(org.jaffa.security.securityrolesdomain.Role)

Example 5 with Role

use of org.jaffa.security.securityrolesdomain.Role in project jaffa-framework by jaffa-projects.

the class UserMaintenanceForm method processIncludes.

private boolean processIncludes(HttpServletRequest request, Collection userRole) {
    boolean noNewElement = true;
    Roles root = PolicyCache.getRoles();
    if (root != null) {
        List roleObjects = root.getRole();
        if (roleObjects != null) {
            for (Iterator it = roleObjects.iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                if (userRole.contains(role.getName())) {
                    List includes = role.getInclude();
                    if (includes != null) {
                        for (Iterator it2 = includes.iterator(); it2.hasNext(); ) {
                            Include includedObject = (Include) it2.next();
                            String includeName = includedObject.getName();
                            if (!userRole.contains(includeName)) {
                                userRole.add(includeName);
                                updateRolesModel(includeName);
                                raiseError(request, "roles", new ActionMessage("error.Jaffa.Admin.UserMaintenance.AddRolesSelection", "" + role.getName(), "" + includeName));
                                noNewElement = false;
                            }
                        }
                    }
                }
            }
        }
    }
    return noNewElement;
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) ActionMessage(org.apache.struts.action.ActionMessage) Include(org.jaffa.security.securityrolesdomain.Include) Roles(org.jaffa.security.securityrolesdomain.Roles)

Aggregations

Role (org.jaffa.security.securityrolesdomain.Role)9 Roles (org.jaffa.security.securityrolesdomain.Roles)7 ContextKey (org.jaffa.loader.ContextKey)3 GrantFunctionAccess (org.jaffa.security.securityrolesdomain.GrantFunctionAccess)3 ActionMessage (org.apache.struts.action.ActionMessage)2 Exclude (org.jaffa.security.securityrolesdomain.Exclude)2 Include (org.jaffa.security.securityrolesdomain.Include)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 UserMaintenanceException (org.jaffa.applications.jaffa.modules.admin.components.usermaintenance.tx.exceptions.UserMaintenanceException)1 UserRole (org.jaffa.applications.jaffa.modules.admin.domain.UserRole)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 Test (org.junit.Test)1