Search in sources :

Example 1 with ProxyPentahoUser

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));
}
Also used : IUser(org.pentaho.di.repository.IUser) UserInfo(org.pentaho.di.repository.UserInfo) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) Test(org.junit.Test)

Example 2 with ProxyPentahoUser

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());
}
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 3 with ProxyPentahoUser

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);
}
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 4 with ProxyPentahoUser

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) IEEUser(org.pentaho.di.repository.pur.model.IEEUser) KettleException(org.pentaho.di.core.exception.KettleException) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) JSONException(org.json.JSONException)

Example 5 with ProxyPentahoUser

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);
    }
}
Also used : UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) IEEUser(org.pentaho.di.repository.pur.model.IEEUser) KettleException(org.pentaho.di.core.exception.KettleException) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) JSONException(org.json.JSONException)

Aggregations

ProxyPentahoUser (org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser)24 Test (org.junit.Test)15 UserRoleException (org.pentaho.platform.security.userroledao.ws.UserRoleException)14 IUserRoleWebService (org.pentaho.platform.security.userroledao.ws.IUserRoleWebService)11 IUser (org.pentaho.di.repository.IUser)7 KettleException (org.pentaho.di.core.exception.KettleException)5 JSONException (org.json.JSONException)4 UserRoleHelper.convertFromProxyPentahoUser (org.pentaho.di.repository.pur.UserRoleHelper.convertFromProxyPentahoUser)4 ProxyPentahoRole (org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole)4 IRoleSupportSecurityManager (org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager)3 IEEUser (org.pentaho.di.repository.pur.model.IEEUser)2 UserRoleWebService (org.pentaho.platform.security.userroledao.ws.UserRoleWebService)2 UserToRoleAssignment (org.pentaho.platform.security.userroledao.ws.UserToRoleAssignment)2 ArrayList (java.util.ArrayList)1 UserInfo (org.pentaho.di.repository.UserInfo)1 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)1 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)1 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)1