Search in sources :

Example 1 with UserRoleException

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

the class UserRoleDelegate method createUser.

public void createUser(IUser newUser) throws KettleException {
    ensureHasPermissions();
    ProxyPentahoUser user = UserRoleHelper.convertToPentahoProxyUser(newUser);
    try {
        ProxyPentahoUser[] existingUsers = userRoleWebService.getUsers();
        if (existsAmong(existingUsers, user)) {
            throw userExistsException();
        }
    } catch (UserRoleException e) {
        throw cannotCreateUserException(newUser, e);
    }
    try {
        userRoleWebService.createUser(user);
        if (newUser instanceof IEEUser) {
            userRoleWebService.setRoles(user, UserRoleHelper.convertToPentahoProxyRoles(((IEEUser) newUser).getRoles()));
        }
        lookupCache.insertUserToLookupSet(newUser);
        fireUserRoleListChange();
    } catch (Exception e) {
        // it is the only way to determine AlreadyExistsException
        if (e.getCause().toString().contains("org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException")) {
            throw userExistsException();
        }
        throw cannotCreateUserException(newUser, e);
    }
}
Also used : UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) IEEUser(org.pentaho.di.repository.pur.model.IEEUser) KettleException(org.pentaho.di.core.exception.KettleException) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) JSONException(org.json.JSONException)

Example 2 with UserRoleException

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

the class UserRoleDelegate method createRole.

public void createRole(IRole newRole) throws KettleException {
    ensureHasPermissions();
    ProxyPentahoRole role = UserRoleHelper.convertToPentahoProxyRole(newRole);
    try {
        ProxyPentahoRole[] existingRoles = userRoleWebService.getRoles();
        if (existsAmong(existingRoles, role)) {
            throw roleExistsException();
        }
    } catch (UserRoleException e) {
        throw cannotCreateRoleException(newRole, e);
    }
    try {
        userRoleWebService.createRole(role);
        userRoleWebService.setUsers(role, UserRoleHelper.convertToPentahoProxyUsers(newRole.getUsers()));
        lookupCache.insertRoleToLookupSet(newRole);
        fireUserRoleListChange();
    } catch (UserRoleException e) {
        throw cannotCreateRoleException(newRole, e);
    } catch (Exception e) {
        // it is the only way to determine AlreadyExistsException
        if (e.getCause().toString().contains("org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException")) {
            throw roleExistsException();
        }
    }
}
Also used : ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) KettleException(org.pentaho.di.core.exception.KettleException) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) JSONException(org.json.JSONException)

Example 3 with UserRoleException

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

the class UserRoleHelper method convertFromProxyPentahoRole.

public static IRole convertFromProxyPentahoRole(IUserRoleWebService userRoleWebService, ProxyPentahoRole role, UserRoleLookupCache lookupCache, IRoleSupportSecurityManager rsm) {
    IRole roleInfo = null;
    try {
        roleInfo = rsm.constructRole();
    } catch (KettleException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    roleInfo.setDescription(role.getDescription());
    roleInfo.setName(role.getName());
    try {
        roleInfo.setUsers(convertToSetFromProxyPentahoUsers(userRoleWebService.getUsersForRole(role), lookupCache));
    } catch (UserRoleException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return roleInfo;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IRole(org.pentaho.di.repository.pur.model.IRole) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException)

Example 4 with UserRoleException

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

the class UserRoleWebServiceBase method testSetRoles.

@Test
public void testSetRoles() throws UserRoleException {
    UserRoleDaoMock userRoleDao = PentahoSystem.get(UserRoleDaoMock.class, USER_ROLE_DAO_TXN, null);
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    ProxyPentahoUser userObj = new ProxyPentahoUser();
    userObj.setName("test1");
    ProxyPentahoRole[] rolesObj = new ProxyPentahoRole[1];
    rolesObj[0] = new ProxyPentahoRole("testRole2");
    try {
        service.setRoles(userObj, rolesObj);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    userRoleDao.getUserRoles(null, "test1");
    Assert.assertEquals("testRole1", userRoleDao.getUserRoles(null, "test1").get(0).getName());
    service.setRoles(userObj, rolesObj);
    Assert.assertEquals("testRole2", userRoleDao.getUserRoles(null, "test1").get(0).getName());
}
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 5 with UserRoleException

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

the class UserRoleWebServiceBase method testGetRolesForUser.

@Test
public void testGetRolesForUser() throws UserRoleException {
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    ProxyPentahoUser userObj = new ProxyPentahoUser();
    userObj.setName("test1");
    try {
        service.getRolesForUser(userObj);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    ProxyPentahoRole[] roles = service.getRolesForUser(userObj);
    Assert.assertEquals(1, roles.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)

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