Search in sources :

Example 21 with ProxyPentahoUser

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

the class UserRoleWebServiceBase method testSetUsers.

@Test
public void testSetUsers() throws UserRoleException {
    UserRoleDaoMock userRoleDao = PentahoSystem.get(UserRoleDaoMock.class, USER_ROLE_DAO_TXN, null);
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    ProxyPentahoRole roleObj = new ProxyPentahoRole("testRole1");
    ProxyPentahoUser[] usersObj = new ProxyPentahoUser[1];
    usersObj[0] = new ProxyPentahoUser();
    usersObj[0].setName("test2");
    try {
        service.setUsers(roleObj, usersObj);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    Assert.assertEquals("test1", userRoleDao.getRoleMembers(null, "testRole1").get(0).getUsername());
    service.setUsers(roleObj, usersObj);
    Assert.assertEquals("test2", userRoleDao.getRoleMembers(null, "testRole1").get(0).getUsername());
}
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) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) Test(org.junit.Test)

Example 22 with ProxyPentahoUser

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

the class UserRoleWebServiceBase method testDeleteUsers.

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

Example 23 with ProxyPentahoUser

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

the class UserRoleWebServiceBase method testGetUser.

@Test
public void testGetUser() throws Exception {
    IUserRoleWebService service = getUserRoleWebService();
    mockUserAsAdmin(false);
    try {
        service.getUser(null);
        Assert.fail();
    } catch (UserRoleException e) {
        Assert.assertTrue("ERROR_0001 not found in " + e.getMessage(), e.getMessage().indexOf("ERROR_0001") >= 0);
    }
    mockUserAsAdmin(true);
    ProxyPentahoUser userObj = service.getUser("test1");
    Assert.assertNotNull(userObj);
    Assert.assertEquals("test1", userObj.getName());
}
Also used : IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) UserRoleException(org.pentaho.platform.security.userroledao.ws.UserRoleException) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) Test(org.junit.Test)

Example 24 with ProxyPentahoUser

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

the class UserRoleWebServiceBase method testCreateDuplicateUser.

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

        @Override
        protected IUserRoleDao getDao() throws UserRoleException {
            return userRoleDao;
        }
    };
    ProxyPentahoUser proxyPentahoUser = new ProxyPentahoUser();
    proxyPentahoUser.setName("test");
    proxyPentahoUser.setEnabled(true);
    proxyPentahoUser.setPassword("test");
    proxyPentahoUser.setDescription("testing");
    try {
        userRoleWebService.createUser(proxyPentahoUser);
        Assert.fail();
    } catch (AlreadyExistsException e) {
        Assert.assertEquals(0, e.getStackTrace().length);
    }
}
Also used : AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) ProxyPentahoUser(org.pentaho.platform.security.userroledao.ws.ProxyPentahoUser) UserRoleWebService(org.pentaho.platform.security.userroledao.ws.UserRoleWebService) IUserRoleWebService(org.pentaho.platform.security.userroledao.ws.IUserRoleWebService) Test(org.junit.Test)

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