Search in sources :

Example 11 with ProxyPentahoRole

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

the class UserRoleWebServiceBase method testDeleteRoles.

@Test
public void testDeleteRoles() throws Exception {
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    ProxyPentahoRole[] rolesObj = new ProxyPentahoRole[1];
    rolesObj[0] = new ProxyPentahoRole("testRole1");
    try {
        service.deleteRoles(rolesObj);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    service.deleteRoles(rolesObj);
    Assert.assertEquals(1, roles.size());
}
Also used : ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) Test(org.junit.Test)

Example 12 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(Set<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 13 with ProxyPentahoRole

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

the class UserRoleHelper method convertToListFromProxyPentahoRoles.

public static List<IRole> convertToListFromProxyPentahoRoles(UserRoleSecurityInfo info, IRoleSupportSecurityManager rsm) {
    List<IRole> roleList = new ArrayList<IRole>();
    List<ProxyPentahoRole> roles = info.getRoles();
    List<UserToRoleAssignment> assignments = info.getAssignments();
    for (ProxyPentahoRole role : roles) {
        roleList.add(convertFromProxyPentahoRole(role, assignments, rsm));
    }
    return roleList;
}
Also used : IRole(org.pentaho.di.repository.pur.model.IRole) UserToRoleAssignment(org.pentaho.platform.security.userroledao.ws.UserToRoleAssignment) ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) ArrayList(java.util.ArrayList)

Example 14 with ProxyPentahoRole

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

the class UserRoleHelper method convertToSetFromProxyPentahoRoles.

private static Set<IRole> convertToSetFromProxyPentahoRoles(ProxyPentahoRole[] roles, IRoleSupportSecurityManager rsm) {
    Set<IRole> roleSet = new HashSet<IRole>();
    for (ProxyPentahoRole role : roles) {
        IRole roleInfo = null;
        try {
            roleInfo = rsm.constructRole();
        } catch (KettleException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        roleInfo.setDescription(role.getDescription());
        roleInfo.setName(role.getName());
        roleSet.add(roleInfo);
    }
    return roleSet;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IRole(org.pentaho.di.repository.pur.model.IRole) ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) HashSet(java.util.HashSet)

Example 15 with ProxyPentahoRole

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

the class UserRoleWebServiceBase method testCreateDuplicateRole.

@Test
public void testCreateDuplicateRole() throws UserRoleException {
    UserRoleDaoMock userRoleDao = Mockito.mock(UserRoleDaoMock.class);
    Mockito.doThrow(new AlreadyExistsException("That role already exists.")).when(userRoleDao).createRole(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
    UserRoleWebService userRoleWebService = new UserRoleWebService() {

        @Override
        protected IUserRoleDao getDao() throws UserRoleException {
            return userRoleDao;
        }
    };
    ProxyPentahoRole proxyPentahoRole = new ProxyPentahoRole("testrole");
    try {
        userRoleWebService.createRole(proxyPentahoRole);
        Assert.fail();
    } catch (AlreadyExistsException e) {
        Assert.assertEquals(0, e.getStackTrace().length);
    }
}
Also used : AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) ProxyPentahoRole(org.pentaho.platform.security.userroledao.ws.ProxyPentahoRole) UserRoleWebService(org.pentaho.platform.security.userroledao.ws.UserRoleWebService) IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) Test(org.junit.Test)

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