UserRoleDaoService { public void changeUserPassword( final String userName, final String newPass, String oldPass ) throws Exception { if ( inputValid( userName, newPass, oldPass ) ) { ValidationFailedException exception = validatePasswordFormat( newPass ); if ( exception != null ) { throw exception; } final IPentahoSession pentahoSession = PentahoSessionHolder.getSession(); if ( canAdminister() || ( null != pentahoSession && userName.equals( pentahoSession.getName() ) ) ) { final IUserRoleDao roleDao = PentahoSystem.get( IUserRoleDao.class, "userRoleDaoProxy", pentahoSession ); IPentahoUser pentahoUser = roleDao.getUser( null, userName ); if ( credentialValid( pentahoUser, oldPass ) ) { SecurityHelper.getInstance().runAsSystem( new Callable<Void>() { @Override public Void call() throws Exception { roleDao.setPassword( null, userName, newPass ); return null; } } ); } else { throw new SecurityException( Messages.getInstance().getString( PASS_VALIDATION_ERROR_WRONG_PASS ) ); } } else { throw new SecurityException( Messages.getInstance().getString( PASS_VALIDATION_ERROR_WRONG_PASS ) ); } } else { throw new ValidationFailedException(); } }  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 testChangePassByAdminSuccess() 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, OTHER_USER_PASSWORD ); }
@Test public void testChangeOwnPasswordSuccess() throws Exception { setupMockSessionUser( SESSION_USER_NAME, false ); IUserRoleDao roleDao = registerMockUserRoleDao(); addMockUserToUserRoleDao( roleDao, SESSION_USER_NAME, SESSION_USER_PASSWORD ); userRoleService.changeUserPassword( SESSION_USER_NAME, A_NEW_PASSWORD, SESSION_USER_PASSWORD ); }
@Test( expected = SecurityException.class ) public void testChangePasswordNoPermissions() throws Exception { setupMockSessionUser( SESSION_USER_NAME, false ); IUserRoleDao roleDao = registerMockUserRoleDao(); addMockUserToUserRoleDao( roleDao, OTHER_USER_NAME, OTHER_USER_PASSWORD ); userRoleService.changeUserPassword( OTHER_USER_NAME, A_NEW_PASSWORD, OTHER_USER_PASSWORD ); }
@Test( expected = SecurityException.class ) public void testChangePassWrongName() throws Exception { setupMockSessionUser( SESSION_USER_NAME, false ); registerMockUserRoleDao(); userRoleService.changeUserPassword( OTHER_USER_NAME, A_NEW_PASSWORD, OTHER_USER_PASSWORD ); }
@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 ); }