use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser 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());
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleWebService method getUser.
@Override
public ProxyPentahoUser getUser(String pUserName) throws UserRoleException {
ProxyPentahoUser proxyPentahoUser = null;
IPentahoUser user = getDao().getUser(null, pUserName);
if (user != null) {
proxyPentahoUser = ProxyPentahoUserRoleHelper.toProxyUser(user);
}
return proxyPentahoUser;
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleWebService method getRolesForUser.
@Override
public ProxyPentahoRole[] getRolesForUser(ProxyPentahoUser proxyUser) throws UserRoleException {
List<ProxyPentahoRole> proxyRoles = new ArrayList<ProxyPentahoRole>();
IPentahoUser user = getDao().getUser(proxyUser.getTenant(), proxyUser.getName());
if (user != null) {
for (IPentahoRole role : getDao().getUserRoles(proxyUser.getTenant(), proxyUser.getName())) {
proxyRoles.add(ProxyPentahoUserRoleHelper.toProxyRole(role));
}
} else {
throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0004_FAILED_TO_FIND_USER", // $NON-NLS-1$
proxyUser.getName()));
}
return proxyRoles.toArray(new ProxyPentahoRole[0]);
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleWebService method setRoles.
@Override
public void setRoles(ProxyPentahoUser proxyUser, ProxyPentahoRole[] assignedRoles) throws UserRoleException {
IPentahoUser user = getDao().getUser(proxyUser.getTenant(), proxyUser.getName());
if (user == null) {
throw new UserRoleException(Messages.getInstance().getErrorString("UserRoleWebService.ERROR_0004_FAILED_TO_FIND_USER", // $NON-NLS-1$
proxyUser.getName()));
}
ArrayList<String> roles = new ArrayList<String>();
for (ProxyPentahoRole assignedRole : assignedRoles) {
roles.add(assignedRole.getName());
}
getDao().setUserRoles(proxyUser.getTenant(), proxyUser.getName(), roles.toArray(new String[0]));
}
use of org.pentaho.platform.api.engine.security.userroledao.IPentahoUser in project pentaho-platform by pentaho.
the class UserRoleWebService method getUsers.
@Override
public ProxyPentahoUser[] getUsers() throws UserRoleException {
List<IPentahoUser> users = getDao().getUsers();
if (users != null) {
ProxyPentahoUser[] proxyUsers = new ProxyPentahoUser[users.size()];
int i = 0;
for (IPentahoUser user : users) {
proxyUsers[i++] = ProxyPentahoUserRoleHelper.toProxyUser(user);
}
return proxyUsers;
}
return null;
}
Aggregations