Search in sources :

Example 1 with SystemRolesMap

use of org.pentaho.platform.web.http.api.resources.SystemRolesMap in project pentaho-platform by pentaho.

the class UserRoleDaoService method getRoleBindingStruct.

public SystemRolesMap getRoleBindingStruct(String locale) throws SecurityException {
    if (canAdminister()) {
        RoleBindingStruct roleBindingStruct = getRoleBindingDao().getRoleBindingStruct(locale);
        SystemRolesMap systemRolesMap = new SystemRolesMap();
        for (Map.Entry<String, String> localalizeNameEntry : roleBindingStruct.logicalRoleNameMap.entrySet()) {
            systemRolesMap.getLocalizedRoleNames().add(new LocalizedLogicalRoleName(localalizeNameEntry.getKey(), localalizeNameEntry.getValue()));
        }
        for (Map.Entry<String, List<String>> logicalRoleAssignments : roleBindingStruct.bindingMap.entrySet()) {
            systemRolesMap.getAssignments().add(new LogicalRoleAssignment(logicalRoleAssignments.getKey(), logicalRoleAssignments.getValue(), roleBindingStruct.immutableRoles.contains(logicalRoleAssignments.getKey())));
        }
        return systemRolesMap;
    } else {
        throw new SecurityException();
    }
}
Also used : LocalizedLogicalRoleName(org.pentaho.platform.web.http.api.resources.LocalizedLogicalRoleName) RoleBindingStruct(org.pentaho.platform.security.policy.rolebased.RoleBindingStruct) ArrayList(java.util.ArrayList) List(java.util.List) SystemRolesMap(org.pentaho.platform.web.http.api.resources.SystemRolesMap) Map(java.util.Map) SystemRolesMap(org.pentaho.platform.web.http.api.resources.SystemRolesMap) LogicalRoleAssignment(org.pentaho.platform.web.http.api.resources.LogicalRoleAssignment)

Example 2 with SystemRolesMap

use of org.pentaho.platform.web.http.api.resources.SystemRolesMap in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testGetRoleBindingStruct.

@Test
public void testGetRoleBindingStruct() {
    setupMockSessionUser(SESSION_USER_NAME, true);
    Map<String, String> localizedNameEntry = new HashMap<>();
    localizedNameEntry.put("testEntry", "testValue");
    Map<String, List<String>> testBindingMap = new HashMap<>();
    testBindingMap.put("testBinding", new ArrayList<>());
    RoleBindingStruct roleBindingStruct = mock(RoleBindingStruct.class);
    roleBindingStruct.logicalRoleNameMap = localizedNameEntry;
    roleBindingStruct.bindingMap = testBindingMap;
    roleBindingStruct.immutableRoles = new HashSet<>();
    IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock(IRoleAuthorizationPolicyRoleBindingDao.class);
    when(roleBindingDao.getRoleBindingStruct(nullable(String.class))).thenReturn(roleBindingStruct);
    PentahoSystem.registerObject(roleBindingDao);
    SystemRolesMap validateMap = userRoleService.getRoleBindingStruct("en");
    assert (1 == validateMap.getLocalizedRoleNames().size());
    assertEquals("testEntry", validateMap.getLocalizedRoleNames().get(0).getRoleName());
    assertEquals("testValue", validateMap.getLocalizedRoleNames().get(0).getLocalizedName());
}
Also used : IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) HashMap(java.util.HashMap) RoleBindingStruct(org.pentaho.platform.security.policy.rolebased.RoleBindingStruct) List(java.util.List) ArrayList(java.util.ArrayList) SystemRolesMap(org.pentaho.platform.web.http.api.resources.SystemRolesMap) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 RoleBindingStruct (org.pentaho.platform.security.policy.rolebased.RoleBindingStruct)2 SystemRolesMap (org.pentaho.platform.web.http.api.resources.SystemRolesMap)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 IRoleAuthorizationPolicyRoleBindingDao (org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao)1 LocalizedLogicalRoleName (org.pentaho.platform.web.http.api.resources.LocalizedLogicalRoleName)1 LogicalRoleAssignment (org.pentaho.platform.web.http.api.resources.LogicalRoleAssignment)1