Search in sources :

Example 1 with GrantFunctionAccess

use of org.jaffa.security.securityrolesdomain.GrantFunctionAccess 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 GrantFunctionAccess

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

the class CheckPolicy method checkPolicy.

/**
 * checkPolicy() - Compares the business functions from the businessFunctionManager with the contents of m_compoErrors.
 */
private static synchronized void checkPolicy() {
    // Read the business function file
    List<String> bfuncs = readFunctions();
    // Get mandatory functions per component
    Map compList = ComponentManager.getComponentRequirements();
    // For Each component make sure that the business functions are valid
    for (Iterator it = compList.keySet().iterator(); it.hasNext(); ) {
        String comp = (String) it.next();
        String[] funcs = (String[]) compList.get(comp);
        if (funcs == null) {
            continue;
        }
        for (int i = 0; i < funcs.length; i++) {
            if (!bfuncs.contains(funcs[i])) {
                m_compErrors.put(comp, funcs[i]);
                log.warn("Function '" + funcs[i] + "' on Component '" + comp + "' is Not Valid!");
            }
        }
    }
    // For Each role make sure that the business functions are valid
    List<Role> allRoles = PolicyManager.getAllRoles();
    for (Role role : allRoles) {
        for (GrantFunctionAccess grantFunctionAccess : role.getGrantFunctionAccess()) {
            if (!bfuncs.contains(grantFunctionAccess.getName())) {
                m_roleErrors.put(role.getName(), grantFunctionAccess.getName());
                log.warn("Business Function '" + grantFunctionAccess.getName() + "' in Role '" + role.getName() + "' is Not Valid!");
            }
        }
    }
}
Also used : Role(org.jaffa.security.securityrolesdomain.Role) Iterator(java.util.Iterator) GrantFunctionAccess(org.jaffa.security.securityrolesdomain.GrantFunctionAccess) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with GrantFunctionAccess

use of org.jaffa.security.securityrolesdomain.GrantFunctionAccess 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 4 with GrantFunctionAccess

use of org.jaffa.security.securityrolesdomain.GrantFunctionAccess 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
    RoleManager roleManager = PolicyManager.getRoleManager();
    Roles roles = (null != roleManager) ? roleManager.getRoles() : null;
    m_roleBFMap.clear();
    if (roles == null) {
        return m_roleBFMap;
    }
    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) RoleManager(org.jaffa.loader.policy.RoleManager) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) GrantFunctionAccess(org.jaffa.security.securityrolesdomain.GrantFunctionAccess) Roles(org.jaffa.security.securityrolesdomain.Roles) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

GrantFunctionAccess (org.jaffa.security.securityrolesdomain.GrantFunctionAccess)4 Role (org.jaffa.security.securityrolesdomain.Role)4 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ContextKey (org.jaffa.loader.ContextKey)1 RoleManager (org.jaffa.loader.policy.RoleManager)1 Roles (org.jaffa.security.securityrolesdomain.Roles)1 Test (org.junit.Test)1