Search in sources :

Example 16 with IUserRoleDao

use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testGetRoles.

@Test
public void testGetRoles() throws Exception {
    List<IPentahoRole> roleList = new ArrayList<>();
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getRoles()).thenReturn(roleList);
    PentahoSystem.registerObject(roleDao);
    IPentahoRole role = mock(IPentahoRole.class);
    when(role.getName()).thenReturn("testRole");
    roleList.add(role);
    RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
    assertEquals(wrapRoleList.getRoles(), userRoleService.getRoles().getRoles());
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Example 17 with IUserRoleDao

use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testSelfUpdatePasswordNotAdmin.

@Test(expected = SecurityException.class)
public void testSelfUpdatePasswordNotAdmin() throws Exception {
    setupMockSessionUser(SESSION_USER_NAME, false);
    IUserRoleDao roleDao = registerMockUserRoleDao();
    addMockUserToUserRoleDao(roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD);
    userRoleService.updatePassword(new User(SESSION_USER_NAME, A_NEW_PASSWORD));
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.pentaho.platform.web.http.api.resources.User) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Example 18 with IUserRoleDao

use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testRemoveRoleFromUser.

@Test
public void testRemoveRoleFromUser() {
    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");
    IPentahoRole powerUserRole = mock(IPentahoRole.class);
    when(powerUserRole.getName()).thenReturn("Power User");
    IPentahoRole businessUserRole = mock(IPentahoRole.class);
    when(businessUserRole.getName()).thenReturn("Business User");
    List<IPentahoRole> roleList = new ArrayList<>();
    roleList.add(ceoRole);
    roleList.add(ctoRole);
    roleList.add(powerUserRole);
    roleList.add(businessUserRole);
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
    PentahoSystem.registerObject(roleDao);
    userRoleService.removeRolesFromUser(userName, roleNames);
    verify(roleDao).setUserRoles(any(ITenant.class), anyString(), argThat(new UnorderedArrayMatcher(new String[] { "ceo", "cto" })));
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Example 19 with IUserRoleDao

use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testUpdatePasswordWithAdminCredentials.

@Test
public void testUpdatePasswordWithAdminCredentials() throws Exception {
    setupMockSessionUser(SESSION_USER_NAME, true);
    AuthenticationProvider authenticationProvider = registerMockAuthenticationProvider();
    addMockUserToAuthenticationProvider(authenticationProvider, SESSION_USER_NAME, SESSION_USER_PASSWORD);
    IUserRoleDao roleDao = registerMockUserRoleDao();
    addMockUserToUserRoleDao(roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD);
    userRoleService.updatePassword(new User(OTHER_USER_NAME, A_NEW_PASSWORD), SESSION_USER_PASSWORD);
    verify(roleDao, times(1)).setPassword(any(ITenant.class), eq(OTHER_USER_NAME), eq(A_NEW_PASSWORD));
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.pentaho.platform.web.http.api.resources.User) ITenant(org.pentaho.platform.api.mt.ITenant) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Example 20 with IUserRoleDao

use of org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testChangePassWrongPass.

@Test(expected = SecurityException.class)
public void testChangePassWrongPass() throws Exception {
    setupMockSessionUser(SESSION_USER_NAME, true);
    IUserRoleDao roleDao = registerMockUserRoleDao();
    addMockUserToUserRoleDao(roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD);
    userRoleService.changeUserPassword(OTHER_USER_NAME, A_NEW_PASSWORD, A_WRONG_PASSWORD);
}
Also used : IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Aggregations

IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)43 Test (org.junit.Test)28 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)21 ITenant (org.pentaho.platform.api.mt.ITenant)20 Matchers.anyString (org.mockito.Matchers.anyString)13 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)11 ArrayList (java.util.ArrayList)9 User (org.pentaho.platform.web.http.api.resources.User)9 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)8 HashSet (java.util.HashSet)6 Consumes (javax.ws.rs.Consumes)6 PUT (javax.ws.rs.PUT)6 Path (javax.ws.rs.Path)6 Facet (org.codehaus.enunciate.Facet)6 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)5 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)5 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)3 Tenant (org.pentaho.platform.core.mt.Tenant)3 UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)3 IOException (java.io.IOException)2