use of org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager 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.di.ui.repository.pur.services.IRoleSupportSecurityManager 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.di.ui.repository.pur.services.IRoleSupportSecurityManager in project pentaho-kettle by pentaho.
the class UserRoleHelperTest method convertFromProxyPentahoUsers_ReturnsEmptyList_WhenUsersAreAbsent.
@Test
public void convertFromProxyPentahoUsers_ReturnsEmptyList_WhenUsersAreAbsent() throws Exception {
UserRoleSecurityInfo info = new UserRoleSecurityInfo();
info.setUsers(null);
IRoleSupportSecurityManager manager = mockSecurityManager(false);
List<IUser> users = convertFromProxyPentahoUsers(info, manager);
assertNotNull(users);
assertTrue(users.isEmpty());
}
use of org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager in project pentaho-kettle by pentaho.
the class EESecurityController method addRole.
/**
* addRole method is called when user has click ok on a add role dialog. The method add the role
*
* @throws Exception
*/
private void addRole() {
if (service != null) {
try {
IRole role = securityRole.getRole((IRoleSupportSecurityManager) service);
((IRoleSupportSecurityManager) service).createRole(role);
eeSecurity.addRole(UIEEObjectRegistery.getInstance().constructUIRepositoryRole(role));
roleDialog.hide();
} catch (Throwable th) {
if (mainController == null || !mainController.handleLostRepository(th)) {
// $NON-NLS-1$
messageBox.setTitle(BaseMessages.getString(PKG, "CantCreateRoleDialog.Title"));
// $NON-NLS-1$
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Close"));
messageBox.setMessage(// $NON-NLS-1$
BaseMessages.getString(PKG, "CantCreateRoleDialog.Message", th.getLocalizedMessage()));
messageBox.open();
}
}
}
}
use of org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager in project pentaho-kettle by pentaho.
the class UserRoleHelperTest method mockSecurityManager.
private static IRoleSupportSecurityManager mockSecurityManager(final boolean eeUsers) throws KettleException {
IRoleSupportSecurityManager manager = mock(IRoleSupportSecurityManager.class);
when(manager.constructUser()).thenAnswer(new Answer<IUser>() {
@Override
public IUser answer(InvocationOnMock invocation) throws Throwable {
return eeUsers ? new EEUserInfo() : new UserInfo();
}
});
when(manager.constructRole()).thenAnswer(new Answer<IRole>() {
@Override
public IRole answer(InvocationOnMock invocation) throws Throwable {
return new EERoleInfo();
}
});
return manager;
}
Aggregations