use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testDeleteRole.
@Test
public void testDeleteRole() {
String roles = "role1\trole2\t";
setupMockSessionUser(SESSION_USER_NAME, true);
IPentahoRole role = mock(IPentahoRole.class);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getRole(any(ITenant.class), anyString())).thenReturn(role);
PentahoSystem.registerObject(roleDao);
userRoleService.deleteRoles(roles);
verify(roleDao, times(2)).deleteRole(any(IPentahoRole.class));
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testGetRolesForUser.
@Test
public void testGetRolesForUser() throws Exception {
List<IPentahoRole> roleList = new ArrayList<>();
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
PentahoSystem.registerObject(roleDao);
RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
IPentahoSession session = mock(IPentahoSession.class);
String tenantPath = "testPath";
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
PentahoSessionHolder.setSession(session);
setupMockSessionUser(SESSION_USER_NAME, true);
assertEquals(wrapRoleList.getRoles(), userRoleService.getRolesForUser("admin").getRoles());
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testAssignRoleToUser.
@Test
public void testAssignRoleToUser() throws UserRoleListService.UnauthorizedException {
String userName = "testUser";
String roleNames = "Power User\tBusiness User\t";
setupMockSessionUser(SESSION_USER_NAME, true);
// Create session that will generate tenant
IPentahoSession session = mock(IPentahoSession.class);
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn("testTenantPath");
PentahoSessionHolder.setSession(session);
IPentahoRole ceoRole = mock(IPentahoRole.class);
when(ceoRole.getName()).thenReturn("ceo");
IPentahoRole ctoRole = mock(IPentahoRole.class);
when(ctoRole.getName()).thenReturn("cto");
List<IPentahoRole> roleList = new ArrayList<>();
roleList.add(ceoRole);
roleList.add(ctoRole);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
PentahoSystem.registerObject(roleDao);
userRoleService.assignRolesToUser(userName, roleNames);
verify(roleDao).setUserRoles(any(ITenant.class), anyString(), argThat(new UnorderedArrayMatcher(new String[] { "ceo", "cto", "Power User", "Business User" })));
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class UserRoleDaoUserDetailsServiceIT method testLoadUserByUsername.
@Test
public void testLoadUserByUsername() {
loginAsSysTenantAdmin();
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
IPentahoUser pentahoUser = userRoleDao.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
IPentahoRole pentahoRole = userRoleDao.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
pentahoRole = userRoleDao.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null);
pentahoRole = userRoleDao.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null);
userRoleDao.setUserRoles(mainTenant_1, USER_2, new String[] { ROLE_1, ROLE_2, ROLE_3 });
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
userDetailsService.setUserRoleDao(userRoleDao);
userDetailsService.setDefaultRole(tenantAuthenticatedRoleName);
UserDetails userFromService = userDetailsService.loadUserByUsername(USER_2);
assertTrue(userFromService.getUsername().equals(USER_2));
assertTrue(userFromService.getPassword() != null);
assertTrue(userFromService.isEnabled() == true);
assertTrue(userFromService.getAuthorities().size() == 4);
GrantedAuthority[] auths = new GrantedAuthority[4];
userFromService.getAuthorities().toArray(auths);
assertTrue(auths[0].getAuthority().equals(ROLE_0) || auths[0].getAuthority().equals(ROLE_3) || auths[0].getAuthority().equals(ROLE_2) || auths[0].getAuthority().equals(ROLE_1));
assertTrue(auths[1].getAuthority().equals(ROLE_0) || auths[1].getAuthority().equals(ROLE_3) || auths[1].getAuthority().equals(ROLE_2) || auths[1].getAuthority().equals(ROLE_1));
assertTrue(auths[2].getAuthority().equals(ROLE_0) || auths[2].getAuthority().equals(ROLE_3) || auths[2].getAuthority().equals(ROLE_2) || auths[2].getAuthority().equals(ROLE_1));
assertTrue(auths[3].getAuthority().equals(ROLE_0) || auths[3].getAuthority().equals(ROLE_3) || auths[3].getAuthority().equals(ROLE_2) || auths[3].getAuthority().equals(ROLE_1));
cleanupUserAndRoles(mainTenant_1);
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.
the class TestPrincipalProvider method getGroupMembership.
/**
* {@inheritDoc}
*
* <p>
* Called from {@code AbstractLoginModule.getPrincipals()}
* </p>
*/
@Override
public PrincipalIterator getGroupMembership(Principal principal) {
if (principal instanceof EveryonePrincipal) {
return PrincipalIteratorAdapter.EMPTY;
}
if (principal instanceof AclMetadataPrincipal) {
return PrincipalIteratorAdapter.EMPTY;
}
Set<Principal> principals = new HashSet<Principal>(roleAssignments.containsKey(principal.getName()) ? roleAssignments.get(principal.getName()) : new HashSet<Principal>());
principals.add(EveryonePrincipal.getInstance());
if (principal instanceof AdminPrincipal) {
principals.add(adminRolePrincipal);
} else if (principal instanceof UserPrincipal) {
if (userRoleDao != null) {
List<IPentahoRole> roles;
try {
roles = userRoleDao.getUserRoles(null, principal.getName());
for (IPentahoRole role : roles) {
principals.add(new SpringSecurityRolePrincipal(tenantedRoleNameUtils.getPrincipleId(role.getTenant(), role.getName())));
}
} catch (Exception e) {
roles = userRoleDao.getUserRoles(null, principal.getName());
for (IPentahoRole role : roles) {
principals.add(new SpringSecurityRolePrincipal(tenantedRoleNameUtils.getPrincipleId(role.getTenant(), role.getName())));
}
}
} else {
if (principal.getName() != null && (principal.getName().startsWith("admin") || principal.getName().startsWith("suzy") || principal.getName().startsWith("tiffany"))) {
ITenant tenant = tenantedUserNameUtils.getTenant(principal.getName());
principals.add(new SpringSecurityRolePrincipal(tenantedRoleNameUtils.getPrincipleId(tenant, "Authenticated")));
}
if (principal.getName() != null && principal.getName().startsWith("admin")) {
ITenant tenant = tenantedUserNameUtils.getTenant(principal.getName());
principals.add(new SpringSecurityRolePrincipal(tenantedRoleNameUtils.getPrincipleId(tenant, "TenantAdmin")));
}
if (principal.getName() != null && principal.getName().startsWith("super")) {
ITenant tenant = tenantedUserNameUtils.getTenant(principal.getName());
principals.add(new SpringSecurityRolePrincipal(tenantedRoleNameUtils.getPrincipleId(tenant, "SysAdmin")));
}
}
}
return new PrincipalIteratorAdapter(principals);
}
Aggregations