Search in sources :

Example 1 with IRoleSupportSecurityManager

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());
}
Also used : IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager) UserToRoleAssignment(org.pentaho.platform.security.userroledao.ws.UserToRoleAssignment) EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) UserRoleHelper.convertFromProxyPentahoUser(org.pentaho.di.repository.pur.UserRoleHelper.convertFromProxyPentahoUser) Test(org.junit.Test)

Example 2 with IRoleSupportSecurityManager

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);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager) IUser(org.pentaho.di.repository.IUser) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) UserRoleHelper.convertFromProxyPentahoUser(org.pentaho.di.repository.pur.UserRoleHelper.convertFromProxyPentahoUser) Test(org.junit.Test)

Example 3 with IRoleSupportSecurityManager

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());
}
Also used : IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager) UserRoleSecurityInfo(org.pentaho.platform.security.userroledao.ws.UserRoleSecurityInfo) IUser(org.pentaho.di.repository.IUser) Test(org.junit.Test)

Example 4 with IRoleSupportSecurityManager

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();
            }
        }
    }
}
Also used : IRole(org.pentaho.di.repository.pur.model.IRole) IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager)

Example 5 with IRoleSupportSecurityManager

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;
}
Also used : IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager) IRole(org.pentaho.di.repository.pur.model.IRole) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IUser(org.pentaho.di.repository.IUser) EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) UserInfo(org.pentaho.di.repository.UserInfo) EERoleInfo(org.pentaho.di.repository.pur.model.EERoleInfo)

Aggregations

IRoleSupportSecurityManager (org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager)8 Test (org.junit.Test)5 IUser (org.pentaho.di.repository.IUser)5 UserRoleHelper.convertFromProxyPentahoUser (org.pentaho.di.repository.pur.UserRoleHelper.convertFromProxyPentahoUser)3 ProxyPentahoUser (org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser)3 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)2 IRole (org.pentaho.di.repository.pur.model.IRole)2 IUIRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole)2 UserRoleSecurityInfo (org.pentaho.platform.security.userroledao.ws.UserRoleSecurityInfo)2 HashSet (java.util.HashSet)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 KettleException (org.pentaho.di.core.exception.KettleException)1 UserInfo (org.pentaho.di.repository.UserInfo)1 EERoleInfo (org.pentaho.di.repository.pur.model.EERoleInfo)1 IUIUser (org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)1 UserToRoleAssignment (org.pentaho.platform.security.userroledao.ws.UserToRoleAssignment)1