UserRoleDaoService { public void updatePassword( User user, String administratorPassword ) throws ValidationFailedException { final IPentahoSession pentahoSession = PentahoSessionHolder.getSession(); AuthenticationProvider authenticator = PentahoSystem.get( AuthenticationProvider.class, pentahoSession ); if ( authenticator == null ) { throw new SecurityException( "Authentication Provider not found, can not re-authenticate logged-in user" ); } try { Authentication authentication = authenticator.authenticate( new UsernamePasswordAuthenticationToken( pentahoSession.getName(), administratorPassword ) ); if ( authentication.isAuthenticated() ) { updatePassword( user ); } else { throw new SecurityException( "Logged-in user re-authentication failed" ); } } catch ( AuthenticationException e ) { throw new SecurityException( "Logged-in user re-authentication failed", e ); } catch ( ValidationFailedException e ) { throw e; } }  UserListWrapper getUsers(); RoleListWrapper getRolesForUser( String user ); void assignRolesToUser( String userName, String roleNames ); void removeRolesFromUser( String userName, String roleNames ); void createRole( String roleName ); RoleListWrapper getRoles(); UserListWrapper getRoleMembers( String roleName ); void createUser( User user ); void changeUserPassword( final String userName, final String newPass, String oldPass ); void deleteUsers( String userNames ); void deleteRoles( String roleNames ); SystemRolesMap getRoleBindingStruct( String locale ); void setLogicalRoles( LogicalRoleAssignments roleAssignments ); void updatePassword( User user, String administratorPassword ); void updatePassword( User user ); static final String PUC_USER_PASSWORD_LENGTH; static final String PUC_USER_PASSWORD_REQUIRE_SPECIAL_CHARACTER; }
@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 ) ); }
@Test public void testSelfUpdatePasswordWithAdminCredentials() throws Exception { setupMockSessionUser( SESSION_USER_NAME, true ); AuthenticationProvider authenticationProvider = registerMockAuthenticationProvider(); addMockUserToAuthenticationProvider( authenticationProvider, SESSION_USER_NAME, SESSION_USER_PASSWORD ); IUserRoleDao roleDao = registerMockUserRoleDao(); addMockUserToUserRoleDao( roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD ); userRoleService.updatePassword( new User( SESSION_USER_NAME, A_NEW_PASSWORD ), SESSION_USER_PASSWORD ); verify( roleDao, times( 1 ) ).setPassword( any( ITenant.class ), eq( SESSION_USER_NAME ), eq( A_NEW_PASSWORD ) ); }
@Test( expected = SecurityException.class ) public void testUpdatePasswordWithWrongAdminCredentials() 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 ), A_WRONG_PASSWORD ); }
@Test( expected = SecurityException.class ) public void testUpdatePasswordWithNotAdminCredentials() throws Exception { setupMockSessionUser( SESSION_USER_NAME, false ); 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 ); }
@Test( expected = SecurityException.class ) public void testSelfUpdatePasswordWithNotAdminCredentials() throws Exception { setupMockSessionUser( SESSION_USER_NAME, false ); AuthenticationProvider authenticationProvider = registerMockAuthenticationProvider(); addMockUserToAuthenticationProvider( authenticationProvider, SESSION_USER_NAME, SESSION_USER_PASSWORD ); IUserRoleDao roleDao = registerMockUserRoleDao(); addMockUserToUserRoleDao( roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD ); userRoleService.updatePassword( new User( SESSION_USER_NAME, A_NEW_PASSWORD ), SESSION_USER_PASSWORD ); }
@Test public void testUpdatePassword() throws Exception { setupMockSessionUser( SESSION_USER_NAME, true ); IUserRoleDao roleDao = registerMockUserRoleDao(); addMockUserToUserRoleDao( roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD ); addMockUserToUserRoleDao( roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD ); userRoleService.updatePassword( new User( OTHER_USER_NAME, A_NEW_PASSWORD ) ); verify( roleDao, times( 1 ) ).setPassword( any( ITenant.class ), eq( OTHER_USER_NAME ), eq( A_NEW_PASSWORD ) ); }
@Test public void testSelfUpdatePassword() throws Exception { setupMockSessionUser( SESSION_USER_NAME, true ); IUserRoleDao roleDao = registerMockUserRoleDao(); addMockUserToUserRoleDao( roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD ); userRoleService.updatePassword( new User( SESSION_USER_NAME, A_NEW_PASSWORD ) ); verify( roleDao, times( 1 ) ).setPassword( any( ITenant.class ), eq( SESSION_USER_NAME ), eq( A_NEW_PASSWORD ) ); }
@Test( expected = SecurityException.class ) public void testUpdatePasswordNotAdmin() throws Exception { setupMockSessionUser( SESSION_USER_NAME, false ); IUserRoleDao roleDao = registerMockUserRoleDao(); addMockUserToUserRoleDao( roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD ); addMockUserToUserRoleDao( roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD ); userRoleService.updatePassword( new User( OTHER_USER_NAME, A_NEW_PASSWORD ) ); }
@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 ) ); }