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);
}
}
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();
}
}
}
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;
}
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());
}
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);
}
Aggregations