Search in sources :

Example 11 with UserRoleException

use of org.pentaho.platform.security.userroledao.ws.UserRoleException in project pentaho-platform by pentaho.

the class UserRoleWebServiceBase method testGetUsers.

@Test
public void testGetUsers() throws Exception {
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    try {
        service.getUsers();
        Assert.fail();
    } catch (UserRoleException e) {
        // should this be 0001, not admin?
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    ProxyPentahoUser[] userObjs = service.getUsers();
    Assert.assertNotNull(userObjs);
    Assert.assertEquals(2, userObjs.length);
}
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) Test(org.junit.Test)

Example 12 with UserRoleException

use of org.pentaho.platform.security.userroledao.ws.UserRoleException 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 13 with UserRoleException

use of org.pentaho.platform.security.userroledao.ws.UserRoleException in project pentaho-kettle by pentaho.

the class UserRoleHelper method convertFromProxyPentahoUser.

public static IUser convertFromProxyPentahoUser(IUserRoleWebService userRoleWebService, ProxyPentahoUser user, UserRoleLookupCache lookupCache, IRoleSupportSecurityManager rsm) {
    IUser userInfo = null;
    try {
        userInfo = rsm.constructUser();
        userInfo.setDescription(user.getDescription());
        userInfo.setPassword(user.getPassword());
        userInfo.setLogin(user.getName());
        userInfo.setName(user.getName());
        try {
            if (userInfo instanceof IEEUser) {
                ((IEEUser) userInfo).setRoles(convertToSetFromProxyPentahoRoles(userRoleWebService.getRolesForUser(user), lookupCache));
            }
        } catch (UserRoleException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (KettleException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    return userInfo;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IUser(org.pentaho.di.repository.IUser) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) IEEUser(org.pentaho.di.repository.pur.model.IEEUser)

Example 14 with UserRoleException

use of org.pentaho.platform.security.userroledao.ws.UserRoleException in project pentaho-platform by pentaho.

the class UserRoleWebServiceBase method testGetUsersForRole.

@Test
public void testGetUsersForRole() throws UserRoleException {
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    ProxyPentahoRole roleObj = new ProxyPentahoRole("testRole1");
    try {
        service.getUsersForRole(roleObj);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    ProxyPentahoUser[] userObjs = service.getUsersForRole(roleObj);
    Assert.assertEquals(1, userObjs.length);
}
Also used : ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) Test(org.junit.Test)

Example 15 with UserRoleException

use of org.pentaho.platform.security.userroledao.ws.UserRoleException in project pentaho-platform by pentaho.

the class UserRoleWebServiceBase method testUpdateRoleObject.

@Test
public void testUpdateRoleObject() throws UserRoleException {
    UserRoleDaoMock userRoleDao = PentahoSystem.get(UserRoleDaoMock.class, USER_ROLE_DAO_TXN, null);
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    ProxyPentahoRole roleObj = new ProxyPentahoRole("testRole1");
    roleObj.setDescription("testUpdateRoleObject");
    try {
        service.updateRoleObject(roleObj);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    Assert.assertEquals("test role", userRoleDao.getRole(null, "testRole1").getDescription());
    service.updateRoleObject(roleObj);
    Assert.assertEquals("testUpdateRoleObject", userRoleDao.getRole(null, "testRole1").getDescription());
}
Also used : ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) Test(org.junit.Test)

Aggregations

UserRoleException (org.pentaho.platform.security.userroledao.ws.UserRoleException)21 Test (org.junit.Test)17 IUserRoleWebService (org.pentaho.platform.security.userroledao.ws.IUserRoleWebService)17 ProxyPentahoRole (org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole)11 ProxyPentahoUser (org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser)11 KettleException (org.pentaho.di.core.exception.KettleException)4 JSONException (org.json.JSONException)2 IEEUser (org.pentaho.di.repository.pur.model.IEEUser)2 UserRoleWebService (org.pentaho.platform.security.userroledao.ws.UserRoleWebService)2 ArrayList (java.util.ArrayList)1 IUser (org.pentaho.di.repository.IUser)1 IRole (org.pentaho.di.repository.pur.model.IRole)1 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)1 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)1 UserRoleSecurityInfo (org.pentaho.platform.security.userroledao.ws.UserRoleSecurityInfo)1