Search in sources :

Example 6 with SimbaRoleR

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

the class SimbaManagerRestGatewayTest method isSimbaRestManagerAlive_WhenRoleServiceCallWasSuccessfulAndRoleDoesNotExist_ThenSimbaManagerIsAlive.

@Test
public void isSimbaRestManagerAlive_WhenRoleServiceCallWasSuccessfulAndRoleDoesNotExist_ThenSimbaManagerIsAlive() throws Exception {
    String ssoToken = logInWithValidUser();
    when(simbaRoleServiceMock.findRoleByName(ssoToken, APP_USER_ROLE)).thenReturn(new SimbaRoleR());
    boolean actual = simbaManagerRestGateway.isSimbaRestManagerAlive();
    assertThat(actual).isTrue();
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) Test(org.junit.Test)

Example 7 with SimbaRoleR

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

the class SimbaManagerRestGatewayTest method assignRoleToUser_AssignsLookedUpSimbaRoleToLookedUpSimbaUser.

@Test
public void assignRoleToUser_AssignsLookedUpSimbaRoleToLookedUpSimbaUser() 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.assignRoleToUser(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)).addRoleToUser(ssoToken, simbaRole, simbaUser);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR) Test(org.junit.Test)

Example 8 with SimbaRoleR

use of org.simbasecurity.dwclient.gateway.representations.SimbaRoleR 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 9 with SimbaRoleR

use of org.simbasecurity.dwclient.gateway.representations.SimbaRoleR 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 10 with SimbaRoleR

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

the class SimbaManagerRestGatewayTest method assignRoleToUser_WhenUsernameDoesNotExist_ThrowsIllegalArgumentException.

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

Aggregations

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