Search in sources :

Example 6 with Role

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

the class UserMaintenanceForm method processExcludes.

private boolean processExcludes(HttpServletRequest request, Collection userRole) {
    boolean valid = true;
    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 (userRole.contains(role.getName())) {
                    List excludes = role.getExclude();
                    if ((excludes != null) && (!foundExcludedRole)) {
                        StringBuffer excludedRoles = new StringBuffer();
                        for (Iterator it2 = excludes.iterator(); it2.hasNext(); ) {
                            Exclude excludedObject = (Exclude) it2.next();
                            String excludeName = excludedObject.getName();
                            if (userRole.contains(excludeName)) {
                                foundExcludedRole = true;
                                valid = false;
                            }
                            if (excludedRoles.length() == 0)
                                excludedRoles.append(excludeName);
                            else
                                excludedRoles.append("," + excludeName);
                        }
                        if (foundExcludedRole)
                            raiseError(request, "roles", new ActionMessage("error.Jaffa.Admin.UserMaintenance.ExcludedRolesSelection", "" + role.getName(), "" + excludedRoles));
                    }
                }
            }
        }
    }
    return valid;
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) Exclude(org.jaffa.security.securityrolesdomain.Exclude) ActionMessage(org.apache.struts.action.ActionMessage) Roles(org.jaffa.security.securityrolesdomain.Roles)

Example 7 with Role

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

the class RoleManager method unregisterResource.

/**
 * unregisterResource - Unregisters the roles from the role repository using the roles.xml files found in META-INF/roles.xml
 * that exist in the classpath. This is used to return the repository to its original state before a custom
 * configuration was added.
 * @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 unregisterResource(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);
            unregisterRole(key);
        }
    }
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) ContextKey(org.jaffa.loader.ContextKey) Roles(org.jaffa.security.securityrolesdomain.Roles)

Example 8 with Role

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

the class RoleManager method buildRoleMap.

/**
 * buildRoleMap - Builds a hashmap of name-grantfunctionAccess lists for use in the PolicyCache.
 *
 * @return A Map of Role names as keys and values that contain a List of GrantFunctionAccess.
 */
public Map<String, List<String>> buildRoleMap() {
    Map<String, List<String>> nameGrantFunctionAccessMap = new HashMap<>();
    List<Role> roleList = getAllRoles();
    for (Role role : roleList) {
        if (log.isDebugEnabled())
            log.debug("Processing Role: " + role.getName());
        List<GrantFunctionAccess> access = role.getGrantFunctionAccess();
        List<String> funcs = null;
        if (access != null) {
            funcs = new LinkedList<>();
            // Add all the names in all of the GrantAccess objects to the list.
            for (GrantFunctionAccess gfa : access) {
                funcs.add(gfa.getName());
                if (log.isDebugEnabled())
                    log.debug("Processing Role: " + role.getName() + " has function " + gfa.getName());
            }
        }
        // If there are some functions, add it to the master Map
        if (funcs != null)
            nameGrantFunctionAccessMap.put(role.getName(), funcs);
    }
    return nameGrantFunctionAccessMap;
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) HashMap(java.util.HashMap) GrantFunctionAccess(org.jaffa.security.securityrolesdomain.GrantFunctionAccess) List(java.util.List) LinkedList(java.util.LinkedList)

Example 9 with Role

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

the class CheckPolicyComponent method getRoleMap.

/**
 * This creates a HashMap of role and list bussiness-functions for that role
 */
static HashMap getRoleMap() {
    // Get the roles, throws exceptions if there are issues
    Roles roles = PolicyCache.getRoles();
    m_roleBFMap.clear();
    List roleList = roles.getRole();
    // Bail if there are no roles....
    if (roleList == null) {
        return m_roleBFMap;
    }
    // Loop of all the role objects
    for (Iterator it = roleList.iterator(); it.hasNext(); ) {
        Role role = (Role) it.next();
        if (log.isDebugEnabled()) {
            log.debug("Processing Role: " + role.getName());
        }
        List access = role.getGrantFunctionAccess();
        List funcs = null;
        if (access != null) {
            funcs = new ArrayList();
            // Add all the names in all of the GrantAccess objects to the list.
            for (Iterator it2 = access.iterator(); it2.hasNext(); ) {
                GrantFunctionAccess gfa = (GrantFunctionAccess) it2.next();
                funcs.add(gfa.getName());
                if (log.isDebugEnabled()) {
                    log.debug("Processing Role: " + role.getName() + " has function " + gfa.getName());
                }
            }
        }
        // If there are some functions, add it to the master hashmap
        if (funcs != null) {
            m_roleBFMap.put(role.getName(), funcs);
        }
    }
    // Return the construsted Map
    return m_roleBFMap;
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) GrantFunctionAccess(org.jaffa.security.securityrolesdomain.GrantFunctionAccess) 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