Search in sources :

Example 1 with SimbaRoleR

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

the class SimbaRoleService method findRoleByName.

public SimbaRoleR findRoleByName(String ssoToken, String rolename) {
    ClientResponse clientResponse = getSimbaResource().path("role").path("findAll").accept(MediaType.APPLICATION_JSON).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).cookie(new Cookie(AuthenticationConstants.SIMBA_SSO_TOKEN, ssoToken)).get(ClientResponse.class);
    handleError("findRole", rolename, null, clientResponse, logger);
    List<SimbaRoleR> roles = Lists.newArrayList(clientResponse.getEntity(SimbaRoleR[].class));
    Optional<SimbaRoleR> result = FluentIterable.from(roles).firstMatch(withRoleName(rolename));
    if (!result.isPresent()) {
        throw new IllegalArgumentException(String.format("No role found for name %s.", rolename));
    } else {
        return result.get();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Cookie(javax.ws.rs.core.Cookie) SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR)

Example 2 with SimbaRoleR

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

the class SimbaManagerRestGatewayTest method isSimbaRestManagerAlive_WhenRoleServiceCallWasSuccessfulAndRoleExists_ThenSimbaManagerIsAlive.

@Test
public void isSimbaRestManagerAlive_WhenRoleServiceCallWasSuccessfulAndRoleExists_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 3 with SimbaRoleR

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

the class SimbaRoleServiceTest method findRoleByName_WhenRoleFoundInSimbaRoles_ReturnsFoundRole.

@Test
public void findRoleByName_WhenRoleFoundInSimbaRoles_ReturnsFoundRole() throws Exception {
    String anExistingRolename = "simba-manager";
    SimbaRoleR actual = simbaRoleService.findRoleByName(getValidSSOToken(), anExistingRolename);
    assertThat(actual.getName()).isEqualTo(anExistingRolename);
    assertThat(actual.getId()).isNotNull();
    assertThat(actual.getVersion()).isNotNull();
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) Test(org.junit.Test)

Example 4 with SimbaRoleR

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

the class SimbaRoleServiceTest method removeRoleFromUser_WhenBothRoleAndUserNotNull_RoleWasRemovedFromUser.

@Test
public void removeRoleFromUser_WhenBothRoleAndUserNotNull_RoleWasRemovedFromUser() throws Exception {
    String anExistingRolename = "simba-manager";
    SimbaRoleR simbaRole = simbaRoleService.findRoleByName(getValidSSOToken(), anExistingRolename);
    SimbaUserR user = simbaUserService.findUserByName(getValidSSOToken(), DUMMY_TEST_USER);
    simbaRoleService.addRoleToUser(getValidSSOToken(), simbaRole, user);
    simbaDatabaseRule.assertUserRoleExists(DUMMY_TEST_USER, anExistingRolename);
    // get them again because otherwise we get OptimizedLockException (since the version of the User and Role was updated after assigning the role)
    simbaRole = simbaRoleService.findRoleByName(getValidSSOToken(), anExistingRolename);
    user = simbaUserService.findUserByName(getValidSSOToken(), DUMMY_TEST_USER);
    simbaRoleService.removeRoleFromUser(getValidSSOToken(), simbaRole, user);
    simbaDatabaseRule.assertUserRoleDoesNotExist(DUMMY_TEST_USER, anExistingRolename);
}
Also used : SimbaRoleR(org.simbasecurity.dwclient.gateway.representations.SimbaRoleR) SimbaUserR(org.simbasecurity.dwclient.gateway.representations.SimbaUserR) Test(org.junit.Test)

Example 5 with SimbaRoleR

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

the class SimbaRoleServiceTest method removeRoleFromUser_WhenUserIsNull_ThrowsIllegalArgumentException.

@Test
public void removeRoleFromUser_WhenUserIsNull_ThrowsIllegalArgumentException() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("User cannot be null.");
    simbaRoleService.removeRoleFromUser(getValidSSOToken(), new SimbaRoleR(), null);
}
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