Search in sources :

Example 6 with SimbaUserR

use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR in project simba-os by cegeka.

the class SimbaManagerRestGatewayTest method unassignRoleFromUser_WhenRolenameDoesNotExist_ThrowsIllegalArgumentException.

@Test
public void unassignRoleFromUser_WhenRolenameDoesNotExist_ThrowsIllegalArgumentException() throws Exception {
    String username = "ivar";
    String rolename = "role name";
    logInWithValidUser();
    when(simbaUserServiceMock.findUserByName(anyString(), eq(username))).thenReturn(new SimbaUserR(username));
    when(simbaRoleServiceMock.findRoleByName(anyString(), eq(rolename))).thenThrow(new IllegalArgumentException());
    expectedException.expect(IllegalArgumentException.class);
    simbaManagerRestGateway.unassignRoleFromUser(rolename, username);
}
Also used : SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR) Test(org.junit.Test)

Example 7 with SimbaUserR

use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR in project simba-os by cegeka.

the class SimbaManagerRestGateway method assignRoleToUser.

public void assignRoleToUser(String rolename, String username) throws SimbaUnavailableException {
    checkUsernameNotNull(username);
    checkRolenameNotNull(rolename);
    String appUserSSOToken = loginWithAppUser();
    SimbaRoleR simbaRole = simbaRoleService.findRoleByName(appUserSSOToken, rolename);
    SimbaUserR simbaUser = simbaUserService.findUserByName(appUserSSOToken, username);
    simbaRoleService.addRoleToUser(appUserSSOToken, simbaRole, simbaUser);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR)

Example 8 with SimbaUserR

use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR in project simba-os by cegeka.

the class SimbaManagerRestGateway method unassignRoleFromUser.

public void unassignRoleFromUser(String rolename, String username) throws SimbaUnavailableException {
    checkUsernameNotNull(username);
    checkRolenameNotNull(rolename);
    String appUserSSOToken = loginWithAppUser();
    SimbaRoleR simbaRole = simbaRoleService.findRoleByName(appUserSSOToken, rolename);
    SimbaUserR simbaUser = simbaUserService.findUserByName(appUserSSOToken, username);
    simbaRoleService.removeRoleFromUser(appUserSSOToken, simbaRole, simbaUser);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR)

Example 9 with SimbaUserR

use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR in project simba-os by cegeka.

the class SimbaManagerRestGatewayTest method unassignRoleFromUser_RemovesLookedUpSimbaRoleFromLookedUpSimbaUser.

@Test
public void unassignRoleFromUser_RemovesLookedUpSimbaRoleFromLookedUpSimbaUser() throws Exception {
    String username = "herp";
    String rolename = "derp";
    String ssoToken = logInWithValidUser();
    SimbaRoleR simbaRole = new SimbaRoleR();
    SimbaUserR simbaUser = new SimbaUserR("simbauser");
    when(simbaRoleServiceMock.findRoleByName(ssoToken, rolename)).thenReturn(simbaRole);
    when(simbaUserServiceMock.findUserByName(ssoToken, username)).thenReturn(simbaUser);
    simbaManagerRestGateway.unassignRoleFromUser(rolename, username);
    verify(simbaGatewayMock, times(1)).login(APP_USER, APP_PASSWORD);
    verify(simbaRoleServiceMock, times(1)).findRoleByName(ssoToken, rolename);
    verify(simbaUserServiceMock, times(1)).findUserByName(ssoToken, username);
    verify(simbaRoleServiceMock, times(1)).removeRoleFromUser(ssoToken, simbaRole, simbaUser);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR) Test(org.junit.Test)

Example 10 with SimbaUserR

use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR in project simba-os by cegeka.

the class SimbaRoleServiceTest method addRoleToUser_WhenRoleIsNull_ThrowsIllegalArgumentException.

@Test
public void addRoleToUser_WhenRoleIsNull_ThrowsIllegalArgumentException() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Role cannot be null.");
    simbaRoleService.addRoleToUser(getValidSSOToken(), null, new SimbaUserR());
}
Also used : SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR) Test(org.junit.Test)

Aggregations

SimbaUserR (org.simbasecurity.dwclient.gateway.representations.SimbaUserR)12 Test (org.junit.Test)9 SimbaRoleR (org.simbasecurity.dwclient.gateway.representations.SimbaRoleR)6 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 Cookie (javax.ws.rs.core.Cookie)1