use of org.pentaho.platform.security.policy.rolebased.RoleBindingStruct 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();
}
}
use of org.pentaho.platform.security.policy.rolebased.RoleBindingStruct in project pentaho-platform by pentaho.
the class PentahoPlatformExporterTest method testExportUsersAndRoles.
@Test
public void testExportUsersAndRoles() {
IUserRoleListService mockDao = mock(IUserRoleListService.class);
IAnyUserSettingService userSettingService = mock(IAnyUserSettingService.class);
UserDetailsService userDetailsService = mock(UserDetailsService.class);
PentahoSystem.registerObject(mockDao);
PentahoSystem.registerObject(userSettingService);
PentahoSystem.registerObject(userDetailsService);
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock(IRoleAuthorizationPolicyRoleBindingDao.class);
PentahoSystem.registerObject(roleBindingDao);
String tenantPath = "path";
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
List<String> userList = new ArrayList<String>();
String user = "testUser";
String role = "testRole";
userList.add(user);
when(mockDao.getAllUsers(any(ITenant.class))).thenReturn(userList);
List<String> roleList = new ArrayList<String>();
roleList.add(role);
when(mockDao.getAllRoles()).thenReturn(roleList);
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> permissions = new ArrayList<String>();
permissions.add("read");
map.put("testRole", permissions);
RoleBindingStruct struct = mock(RoleBindingStruct.class);
struct.bindingMap = map;
when(roleBindingDao.getRoleBindingStruct(anyString())).thenReturn(struct);
ArgumentCaptor<UserExport> userCaptor = ArgumentCaptor.forClass(UserExport.class);
ArgumentCaptor<RoleExport> roleCaptor = ArgumentCaptor.forClass(RoleExport.class);
ExportManifest manifest = mock(ExportManifest.class);
exporter.setExportManifest(manifest);
List<IUserSetting> settings = new ArrayList<>();
IUserSetting setting = mock(IUserSetting.class);
settings.add(setting);
when(userSettingService.getUserSettings(user)).thenReturn(settings);
when(userSettingService.getGlobalUserSettings()).thenReturn(settings);
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
UserDetails userDetails = new User("testUser", "testPassword", true, true, true, true, authList);
when(userDetailsService.loadUserByUsername(anyString())).thenReturn(userDetails);
exporter.exportUsersAndRoles();
verify(manifest).addUserExport(userCaptor.capture());
verify(manifest).addRoleExport(roleCaptor.capture());
verify(userSettingService).getGlobalUserSettings();
verify(manifest).addGlobalUserSetting(any(ExportManifestUserSetting.class));
assertEquals(settings.size(), userCaptor.getValue().getUserSettings().size());
UserExport userExport = userCaptor.getValue();
assertEquals("testUser", userExport.getUsername());
RoleExport roleExport = roleCaptor.getValue();
assertEquals("testRole", roleExport.getRolename());
}
use of org.pentaho.platform.security.policy.rolebased.RoleBindingStruct 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<String>());
RoleBindingStruct roleBindingStruct = mock(RoleBindingStruct.class);
roleBindingStruct.logicalRoleNameMap = localizedNameEntry;
roleBindingStruct.bindingMap = testBindingMap;
roleBindingStruct.immutableRoles = new HashSet<>();
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock(IRoleAuthorizationPolicyRoleBindingDao.class);
when(roleBindingDao.getRoleBindingStruct(anyString())).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());
}
use of org.pentaho.platform.security.policy.rolebased.RoleBindingStruct in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryAuthorizationIT method testRoleAuthorizationPolicyGetRoleBindingStruct.
/**
* Please keep this test the last of the testRoleAuthorizationPolicy* since it adds a binding that cannot be
* deleted, only set to no associated logical roles.
*/
@Test
public void testRoleAuthorizationPolicyGetRoleBindingStruct() throws Exception {
ITenant tenantAcme = null;
loginAsSysTenantAdmin();
tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
RoleBindingStruct struct = roleBindingDao.getRoleBindingStruct(Locale.getDefault().toString());
assertNotNull(struct);
assertNotNull(struct.bindingMap);
assertEquals(3, struct.bindingMap.size());
assertEquals(Arrays.asList(new String[] { RepositoryReadAction.NAME, RepositoryCreateAction.NAME, SchedulerAction.NAME, AdministerSecurityAction.NAME, PublishAction.NAME }), struct.bindingMap.get(superAdminRoleName));
assertEquals(Arrays.asList(new String[] { RepositoryReadAction.NAME, RepositoryCreateAction.NAME, SchedulerAction.NAME, AdministerSecurityAction.NAME, PublishAction.NAME }), struct.bindingMap.get(tenantAdminRoleName));
assertEquals(Arrays.asList(new String[] { RepositoryReadAction.NAME, RepositoryCreateAction.NAME, SchedulerAction.NAME }), struct.bindingMap.get(tenantAuthenticatedRoleName));
roleBindingDao.setRoleBindings("whatever", Arrays.asList("org.pentaho.p1.reader"));
struct = roleBindingDao.getRoleBindingStruct(Locale.getDefault().toString());
assertEquals(4, struct.bindingMap.size());
assertEquals(Arrays.asList(new String[] { "org.pentaho.p1.reader" }), struct.bindingMap.get("whatever"));
assertNotNull(struct.logicalRoleNameMap);
assertEquals(5, struct.logicalRoleNameMap.size());
assertEquals("Create Content", struct.logicalRoleNameMap.get(RepositoryCreateAction.NAME));
assertNotNull(struct.immutableRoles);
assertEquals(2, struct.immutableRoles.size());
assertTrue(struct.immutableRoles.contains(superAdminRoleName));
assertTrue(struct.immutableRoles.contains(tenantAdminRoleName));
}
use of org.pentaho.platform.security.policy.rolebased.RoleBindingStruct in project pentaho-platform by pentaho.
the class RoleBindingStructAdapterTest method testMarshalUnmarshal.
@Test
public void testMarshalUnmarshal() throws Exception {
final HashMap<String, String> logicalRoleNameMap = new HashMap<String, String>();
logicalRoleNameMap.put(RepositoryCreateAction.NAME, "Create Content");
final HashMap<String, List<String>> bindingMap = new HashMap<String, List<String>>();
final LinkedList<String> roles = new LinkedList<String>();
roles.add(RepositoryCreateAction.NAME);
bindingMap.put("admin", roles);
final HashSet<String> immutableRoles = new HashSet<String>();
immutableRoles.add("admin");
final RoleBindingStruct roleBindingStruct = new RoleBindingStruct(logicalRoleNameMap, bindingMap, immutableRoles);
RoleBindingStructAdapter adapter = new RoleBindingStructAdapter();
final JaxbSafeRoleBindingStruct marshaled = adapter.marshal(roleBindingStruct);
assertEquals(roleBindingStruct.bindingMap.size(), marshaled.bindingMapEntries.size());
assertEquals(roleBindingStruct.logicalRoleNameMap.size(), marshaled.logicalRoleNameMapEntries.size());
assertEquals(roleBindingStruct.immutableRoles.size(), marshaled.immutableRoles.size());
final RoleBindingStruct unmarshaled = adapter.unmarshal(marshaled);
assertEquals(roleBindingStruct.bindingMap, unmarshaled.bindingMap);
assertEquals(roleBindingStruct.logicalRoleNameMap, unmarshaled.logicalRoleNameMap);
assertEquals(roleBindingStruct.immutableRoles, unmarshaled.immutableRoles);
}
Aggregations