Search in sources :

Example 1 with ProxyPentahoRole

use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.

the class UserRoleDelegateTest method createRole_CreatesSuccessfully_WhenNameDiffersInCase.

@Test(expected = KettleException.class)
public void createRole_CreatesSuccessfully_WhenNameDiffersInCase() throws Exception {
    final String name = "role";
    final String upperCased = name.toUpperCase();
    IRole existing = new EERoleInfo(upperCased);
    when(roleWebService.getRoles()).thenReturn(new ProxyPentahoRole[] { convertToPentahoProxyRole(existing) });
    delegate.createRole(new EERoleInfo(name));
    verify(roleWebService).createRole(any(ProxyPentahoRole.class));
}
Also used : IRole(org.pentaho.di.repository.pur.model.IRole) ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) EERoleInfo(org.pentaho.di.repository.pur.model.EERoleInfo) Test(org.junit.Test)

Example 2 with ProxyPentahoRole

use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.

the class UserRoleDelegate method createRole.

public void createRole(IRole newRole) throws KettleException {
    ensureHasPermissions();
    ProxyPentahoRole role = UserRoleHelper.convertToPentahoProxyRole(newRole);
    try {
        ProxyPentahoRole[] existingRoles = userRoleWebService.getRoles();
        if (existsAmong(existingRoles, role)) {
            throw roleExistsException();
        }
    } catch (UserRoleException e) {
        throw cannotCreateRoleException(newRole, e);
    }
    try {
        userRoleWebService.createRole(role);
        userRoleWebService.setUsers(role, UserRoleHelper.convertToPentahoProxyUsers(newRole.getUsers()));
        lookupCache.insertRoleToLookupSet(newRole);
        fireUserRoleListChange();
    } catch (UserRoleException e) {
        throw cannotCreateRoleException(newRole, e);
    } 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 roleExistsException();
        }
    }
}
Also used : ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) KettleException(org.pentaho.di.core.exception.KettleException) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) JSONException(org.json.JSONException)

Example 3 with ProxyPentahoRole

use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.

the class UserRoleDelegate method deleteRole.

public void deleteRole(String name) throws KettleException {
    ensureHasPermissions();
    try {
        ProxyPentahoRole roleToDelete = UserRoleHelper.getProxyPentahoRole(userRoleWebService, name);
        if (roleToDelete != null) {
            ProxyPentahoRole[] roleArray = new ProxyPentahoRole[1];
            roleArray[0] = roleToDelete;
            userRoleWebService.deleteRoles(roleArray);
            fireUserRoleListChange();
        } else {
            throw new KettleException(BaseMessages.getString(UserRoleDelegate.class, "UserRoleDelegate.ERROR_0013_UNABLE_TO_DELETE_ROLE", // $NON-NLS-1$
            name));
        }
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(UserRoleDelegate.class, "UserRoleDelegate.ERROR_0013_UNABLE_TO_DELETE_ROLE", name), // $NON-NLS-1$
        e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) KettleException(org.pentaho.di.core.exception.KettleException) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) JSONException(org.json.JSONException)

Example 4 with ProxyPentahoRole

use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.

the class UserRoleHelper method convertToPentahoProxyRoles.

public static ProxyPentahoRole[] convertToPentahoProxyRoles(List<IRole> roles) {
    ProxyPentahoRole[] proxyRoles = new ProxyPentahoRole[roles.size()];
    int i = 0;
    for (IRole role : roles) {
        proxyRoles[i++] = convertToPentahoProxyRole(role);
    }
    return proxyRoles;
}
Also used : IRole(org.pentaho.di.repository.pur.model.IRole) ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole)

Example 5 with ProxyPentahoRole

use of org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole in project pentaho-kettle by pentaho.

the class UserRoleHelper method getProxyPentahoRole.

public static ProxyPentahoRole getProxyPentahoRole(IUserRoleWebService userRoleWebService, String name) throws UserRoleException {
    ProxyPentahoRole roleToFind = null;
    ProxyPentahoRole[] roles = userRoleWebService.getRoles();
    if (roles != null && roles.length > 0) {
        for (ProxyPentahoRole role : roles) {
            if (role.getName().equals(name)) {
                roleToFind = role;
                break;
            }
        }
    }
    return roleToFind;
}
Also used : ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole)

Aggregations

ProxyPentahoRole (org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole)21 Test (org.junit.Test)12 UserRoleException (org.pentaho.platform.security.userroledao.ws.UserRoleException)12 IUserRoleWebService (org.pentaho.platform.security.userroledao.ws.IUserRoleWebService)11 IRole (org.pentaho.di.repository.pur.model.IRole)6 ProxyPentahoUser (org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser)4 ArrayList (java.util.ArrayList)3 KettleException (org.pentaho.di.core.exception.KettleException)3 JSONException (org.json.JSONException)2 UserRoleWebService (org.pentaho.platform.security.userroledao.ws.UserRoleWebService)2 UserToRoleAssignment (org.pentaho.platform.security.userroledao.ws.UserToRoleAssignment)2 HashSet (java.util.HashSet)1 EERoleInfo (org.pentaho.di.repository.pur.model.EERoleInfo)1 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)1 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)1