use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser in project pentaho-kettle by pentaho.
the class UserRoleDelegateTest method createUser_CreatesSuccessfully_WhenNameDiffersInCase.
@Test
public void createUser_CreatesSuccessfully_WhenNameDiffersInCase() throws Exception {
final String name = "user";
final String upperCased = name.toUpperCase();
IUser existing = new UserInfo(upperCased);
when(roleWebService.getUsers()).thenReturn(new ProxyPentahoUser[] { convertToPentahoProxyUser(existing) });
delegate.createUser(new UserInfo(name));
verify(roleWebService).createUser(any(ProxyPentahoUser.class));
}
use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser in project pentaho-kettle by pentaho.
the class UserRoleHelperTest method convertFromProxyPentahoUser_CopiesRolesForEeUser.
@Test
public void convertFromProxyPentahoUser_CopiesRolesForEeUser() throws Exception {
IRoleSupportSecurityManager manager = mockSecurityManager(true);
ProxyPentahoUser pentahoUser = pentahoUser("name");
List<UserToRoleAssignment> assignments = Collections.singletonList(new UserToRoleAssignment("name", "role"));
EEUserInfo user = (EEUserInfo) convertFromProxyPentahoUser(pentahoUser, assignments, manager);
assertNotNull(user);
assertEquals(pentahoUser.getName(), user.getName());
assertEquals(1, user.getRoles().size());
assertEquals("role", user.getRoles().iterator().next().getName());
}
use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser in project pentaho-kettle by pentaho.
the class UserRoleHelperTest method convertFromProxyPentahoUser_RetunsNull_WhenErrorOccurs.
@Test
public void convertFromProxyPentahoUser_RetunsNull_WhenErrorOccurs() throws Exception {
IRoleSupportSecurityManager manager = mock(IRoleSupportSecurityManager.class);
when(manager.constructUser()).thenThrow(new KettleException());
IUser user = convertFromProxyPentahoUser(new ProxyPentahoUser(), Collections.<UserToRoleAssignment>emptyList(), manager);
assertNull(user);
}
use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser in project pentaho-kettle by pentaho.
the class UserRoleDelegate method updateUser.
public void updateUser(IUser user) throws KettleException {
ensureHasPermissions();
try {
ProxyPentahoUser proxyUser = UserRoleHelper.convertToPentahoProxyUser(user);
userRoleWebService.updateUser(proxyUser);
if (user instanceof IEEUser) {
userRoleWebService.setRoles(proxyUser, UserRoleHelper.convertToPentahoProxyRoles(((IEEUser) user).getRoles()));
}
lookupCache.updateUserInLookupSet(user);
fireUserRoleListChange();
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(UserRoleDelegate.class, "UserRoleDelegate.ERROR_0007_UNABLE_TO_UPDATE_USER", user.getLogin()), // $NON-NLS-1$
e);
}
}
use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser 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);
}
}
Aggregations