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();
}
}
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();
}
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();
}
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);
}
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);
}
Aggregations