use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.
the class UserRoleDelegateTest method createRole_CreatesSuccessfully_WhenNameDiffersInCase.
@Test(expected = KettleException.class)
public void createRole_CreatesSuccessfully_WhenNameDiffersInCase() throws Exception {
final String name = "role";
final String upperCased = name.toUpperCase();
IRole existing = new EERoleInfo(upperCased);
when(roleWebService.getRoles()).thenReturn(new ProxyPentahoRole[] { convertToPentahoProxyRole(existing) });
delegate.createRole(new EERoleInfo(name));
verify(roleWebService).createRole(any(ProxyPentahoRole.class));
}
use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole 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.ProxyPentahoRole in project pentaho-kettle by pentaho.
the class UserRoleDelegate method deleteRole.
public void deleteRole(String name) throws KettleException {
ensureHasPermissions();
try {
ProxyPentahoRole roleToDelete = UserRoleHelper.getProxyPentahoRole(userRoleWebService, name);
if (roleToDelete != null) {
ProxyPentahoRole[] roleArray = new ProxyPentahoRole[1];
roleArray[0] = roleToDelete;
userRoleWebService.deleteRoles(roleArray);
fireUserRoleListChange();
} else {
throw new KettleException(BaseMessages.getString(UserRoleDelegate.class, "UserRoleDelegate.ERROR_0013_UNABLE_TO_DELETE_ROLE", // $NON-NLS-1$
name));
}
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(UserRoleDelegate.class, "UserRoleDelegate.ERROR_0013_UNABLE_TO_DELETE_ROLE", name), // $NON-NLS-1$
e);
}
}
use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.
the class UserRoleHelper method convertToPentahoProxyRoles.
public static ProxyPentahoRole[] convertToPentahoProxyRoles(List<IRole> roles) {
ProxyPentahoRole[] proxyRoles = new ProxyPentahoRole[roles.size()];
int i = 0;
for (IRole role : roles) {
proxyRoles[i++] = convertToPentahoProxyRole(role);
}
return proxyRoles;
}
use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.
the class UserRoleHelper method getProxyPentahoRole.
public static ProxyPentahoRole getProxyPentahoRole(IUserRoleWebService userRoleWebService, String name) throws UserRoleException {
ProxyPentahoRole roleToFind = null;
ProxyPentahoRole[] roles = userRoleWebService.getRoles();
if (roles != null && roles.length > 0) {
for (ProxyPentahoRole role : roles) {
if (role.getName().equals(name)) {
roleToFind = role;
break;
}
}
}
return roleToFind;
}
Aggregations