Search in sources :

Example 1 with IPentahoUser

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

the class UserRoleWebServiceBase method testCreateUser.

@Test
public void testCreateUser() throws Exception {
    UserRoleDaoMock userRoleDao = PentahoSystem.get(UserRoleDaoMock.class, USER_ROLE_DAO_TXN, null);
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    ProxyPentahoUser user = new ProxyPentahoUser();
    user.setName("test");
    user.setEnabled(true);
    user.setPassword("test");
    user.setDescription("testing");
    try {
        service.createUser(user);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    service.createUser(user);
    // the last role should have the same name and description
    IPentahoUser userVerified = userRoleDao.getUser(null, "test");
    Assert.assertNotNull(userVerified);
    Assert.assertEquals("test", userVerified.getUsername());
    Assert.assertEquals("test", userVerified.getPassword());
    Assert.assertEquals(true, userVerified.isEnabled());
    Assert.assertEquals("testing", userVerified.getDescription());
}
Also used : IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) Test(org.junit.Test)

Example 2 with IPentahoUser

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

the class UserRoleWebService method getUser.

@Override
public ProxyPentahoUser getUser(String pUserName) throws UserRoleException {
    ProxyPentahoUser proxyPentahoUser = null;
    IPentahoUser user = getDao().getUser(null, pUserName);
    if (user != null) {
        proxyPentahoUser = ProxyPentahoUserRoleHelper.toProxyUser(user);
    }
    return proxyPentahoUser;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 3 with IPentahoUser

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

the class UserRoleWebService method getRolesForUser.

@Override
public ProxyPentahoRole[] getRolesForUser(ProxyPentahoUser proxyUser) throws UserRoleException {
    List<ProxyPentahoRole> proxyRoles = new ArrayList<ProxyPentahoRole>();
    IPentahoUser user = getDao().getUser(proxyUser.getTenant(), proxyUser.getName());
    if (user != null) {
        for (IPentahoRole role : getDao().getUserRoles(proxyUser.getTenant(), proxyUser.getName())) {
            proxyRoles.add(ProxyPentahoUserRoleHelper.toProxyRole(role));
        }
    } else {
        throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0004_FAILED_TO_FIND_USER", // $NON-NLS-1$
        proxyUser.getName()));
    }
    return proxyRoles.toArray(new ProxyPentahoRole[0]);
}
Also used : ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 4 with IPentahoUser

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

the class UserRoleWebService method setRoles.

@Override
public void setRoles(ProxyPentahoUser proxyUser, ProxyPentahoRole[] assignedRoles) throws UserRoleException {
    IPentahoUser user = getDao().getUser(proxyUser.getTenant(), proxyUser.getName());
    if (user == null) {
        throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0004_FAILED_TO_FIND_USER", // $NON-NLS-1$
        proxyUser.getName()));
    }
    ArrayList<String> roles = new ArrayList<String>();
    for (ProxyPentahoRole assignedRole : assignedRoles) {
        roles.add(assignedRole.getName());
    }
    getDao().setUserRoles(proxyUser.getTenant(), proxyUser.getName(), roles.toArray(new String[0]));
}
Also used : ArrayList(java.util.ArrayList) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

Example 5 with IPentahoUser

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

the class UserRoleWebService method getUsers.

@Override
public ProxyPentahoUser[] getUsers() throws UserRoleException {
    List<IPentahoUser> users = getDao().getUsers();
    if (users != null) {
        ProxyPentahoUser[] proxyUsers = new ProxyPentahoUser[users.size()];
        int i = 0;
        for (IPentahoUser user : users) {
            proxyUsers[i++] = ProxyPentahoUserRoleHelper.toProxyUser(user);
        }
        return proxyUsers;
    }
    return null;
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)

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