use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR 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.SimbaUserR in project simba-os by cegeka.
the class SimbaUserServiceTest method findUserByName_WhenUserFound_ReturnsSimbaUser.
@Test
public void findUserByName_WhenUserFound_ReturnsSimbaUser() throws Exception {
String username = "bruce@wayneindustries.com";
simbaDatabaseRule.createUser(username);
SimbaUserR simbaUser = simbaUserService.findUserByName(getValidSSOToken(), username);
assertThat(simbaUser.getUserName()).isEqualTo(username);
}
use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR in project simba-os by cegeka.
the class SimbaUserService method findUserByName.
public SimbaUserR findUserByName(String ssoToken, String username) {
ClientResponse clientResponse = getSimbaResource().path("user").path("findAll").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).cookie(new Cookie(AuthenticationConstants.SIMBA_SSO_TOKEN, ssoToken)).get(ClientResponse.class);
handleError("findUser", username, clientResponse, logger);
List<SimbaUserR> users = Lists.newArrayList(clientResponse.getEntity(SimbaUserR[].class));
Optional<SimbaUserR> result = FluentIterable.from(users).firstMatch(withName(username));
if (!result.isPresent()) {
throw new IllegalArgumentException(String.format("No user found for name %s.", username));
} else {
return result.get();
}
}
use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR in project simba-os by cegeka.
the class SimbaManagerRestGatewayTest method assignRoleToUser_WhenRolenameDoesNotExist_ThrowsIllegalArgumentException.
@Test
public void assignRoleToUser_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.assignRoleToUser(rolename, username);
}
use of org.simbasecurity.dwclient.gateway.representations.SimbaUserR 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);
}
Aggregations