Search in sources :

Example 31 with IPentahoUser

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

the class UserRoleDaoUserDetailsServiceIT method testLoadUserByUsernameNoRoles.

@Test
public void testLoadUserByUsernameNoRoles() {
    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);
    UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
    userDetailsService.setUserRoleDao(userRoleDao);
    try {
        userDetailsService.loadUserByUsername(USER_2);
    } catch (UsernameNotFoundException unnf) {
        assertNotNull(unnf);
    }
    cleanupUserAndRoles(mainTenant_1);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) ITenant(org.pentaho.platform.api.mt.ITenant) UserRoleDaoUserDetailsService(org.pentaho.platform.security.userroledao.service.UserRoleDaoUserDetailsService) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 32 with IPentahoUser

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

the class UserRoleDaoService method changeUserPassword.

public void changeUserPassword(final String userName, final String newPass, String oldPass) throws Exception {
    if (inputValid(userName, newPass, oldPass)) {
        final IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
        // You must be either an admin or trying to change your own password
        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();
            }
        } else {
            throw new SecurityException();
        }
    } else {
        throw new ValidationFailedException();
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) AuthenticationException(org.springframework.security.core.AuthenticationException) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 33 with IPentahoUser

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

the class UserRoleDaoResource method assignAllUsersToRole.

/**
 * Associates all user to a particular role
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param roleName   (role name)
 * @return
 */
@PUT
@Path("/assignAllUsersToRole")
@Consumes({ MediaType.WILDCARD })
@Facet(name = "Unsupported")
public Response assignAllUsersToRole(@QueryParam("tenant") String tenantPath, @QueryParam("roleName") String roleName) {
    IUserRoleDao roleDao = getUserRoleDao();
    Set<String> assignedUserNames = new HashSet<String>();
    for (IPentahoUser pentahoUser : roleDao.getUsers(getTenant(tenantPath))) {
        assignedUserNames.add(pentahoUser.getUsername());
    }
    roleDao.setRoleMembers(getTenant(tenantPath), roleName, assignedUserNames.toArray(new String[0]));
    if (assignedUserNames.contains(getSession().getName())) {
        updateRolesForCurrentSession();
    }
    return Response.ok().build();
}
Also used : IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Example 34 with IPentahoUser

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

the class UserRoleDaoResourceTest method testGetRoleMembers.

@Test
public void testGetRoleMembers() throws Exception {
    String role = "Report Author";
    UserListWrapper userListWrapper = new UserListWrapper(new ArrayList<IPentahoUser>());
    when(userRoleService.getRoleMembers(role)).thenReturn(userListWrapper);
    assertEquals(userListWrapper, userRoleResource.getRoleMembers(role));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 35 with IPentahoUser

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

the class UserRoleDaoServiceTest method testDeleteUsersUncategorizedUserRoleDaoException.

@Test(expected = UncategorizedUserRoleDaoException.class)
public void testDeleteUsersUncategorizedUserRoleDaoException() {
    String users = "admin\tsuzy\t";
    setupMockSessionUser(SESSION_USER_NAME, true);
    IPentahoUser user = mock(IPentahoUser.class);
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getUser(any(ITenant.class), anyString())).thenThrow(new UncategorizedUserRoleDaoException("expectedTestException"));
    PentahoSystem.registerObject(roleDao);
    userRoleService.deleteUsers(users);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Aggregations

IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)60 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)16 ITenant (org.pentaho.platform.api.mt.ITenant)15 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)13 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)12 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)11 RepositoryException (javax.jcr.RepositoryException)8 PentahoUser (org.pentaho.platform.security.userroledao.PentahoUser)8 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)7 HashSet (java.util.HashSet)6 Matchers.anyString (org.mockito.Matchers.anyString)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 IOException (java.io.IOException)4 AccessControlException (javax.jcr.security.AccessControlException)4 Group (org.apache.jackrabbit.api.security.user.Group)4 BeansException (org.springframework.beans.BeansException)4 User (org.apache.jackrabbit.api.security.user.User)3 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)3 UserListWrapper (org.pentaho.platform.web.http.api.resources.UserListWrapper)3