Search in sources :

Example 1 with LogicalRoleAssignment

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

the class UserRoleDaoServiceTest method testSetLogicalRoles.

@Test
public void testSetLogicalRoles() {
    String roleName = "testRole";
    ArrayList<String> roleList = new ArrayList<>();
    roleList.add("org.pentaho.repository.read");
    roleList.add("org.pentaho.repository.create");
    LogicalRoleAssignment roleAssignment = mock(LogicalRoleAssignment.class);
    when(roleAssignment.getRoleName()).thenReturn(roleName);
    when(roleAssignment.getLogicalRoles()).thenReturn(roleList);
    ArrayList<LogicalRoleAssignment> roles = new ArrayList<>();
    roles.add(roleAssignment);
    LogicalRoleAssignments roleAssignments = mock(LogicalRoleAssignments.class);
    when(roleAssignments.getAssignments()).thenReturn(roles);
    setupMockSessionUser(SESSION_USER_NAME, true);
    IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock(IRoleAuthorizationPolicyRoleBindingDao.class);
    PentahoSystem.registerObject(roleBindingDao);
    userRoleService.setLogicalRoles(roleAssignments);
    verify(roleBindingDao).setRoleBindings(roleName, roleList);
}
Also used : IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) LogicalRoleAssignments(org.pentaho.platform.web.http.api.resources.LogicalRoleAssignments) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) LogicalRoleAssignment(org.pentaho.platform.web.http.api.resources.LogicalRoleAssignment) Test(org.junit.Test)

Example 2 with LogicalRoleAssignment

use of org.pentaho.platform.web.http.api.resources.LogicalRoleAssignment 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) 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)

Aggregations

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