use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class MakeCookieAction method execute.
@Override
public void execute() throws ServletException, IOException {
final SSOToken token = getActionDescriptor().getSsoToken();
assertNotNull(token, "SSOToken should be present");
Cookie cookie = new Cookie(RequestConstants.SIMBA_SSO_TOKEN, token.getToken());
cookie.setHttpOnly(true);
if (ENABLE_SECURE_COOKIES) {
cookie.setSecure(true);
}
cookie.setPath("/");
response.addCookie(cookie);
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class UserService method changePassword.
@RequestMapping("changePassword")
@ResponseBody
public void changePassword(@RequestHeader(value = SIMBA_SSO_TOKEN, required = false) String ssoTokenFromHeader, @CookieValue(value = SIMBA_SSO_TOKEN, required = false) String ssoTokenFromCookie, @RequestBody ChangePasswordDTO changePasswordDTO, HttpServletResponse response) {
String ssoToken = (ssoTokenFromHeader != null ? ssoTokenFromHeader : ssoTokenFromCookie);
if (ssoToken == null || changePasswordDTO.getUserName() == null) {
sendUnauthorizedError(response);
return;
}
Session activeSession = sessionRepository.findBySSOToken(new SSOToken(ssoToken));
if (activeSession == null) {
sendUnauthorizedError(response);
return;
} else {
User sessionUser = activeSession.getUser();
User userThatNeedsPasswordChange = userRepository.findByName(changePasswordDTO.getUserName());
if (!sessionUser.getUserName().equals(userThatNeedsPasswordChange.getUserName())) {
sendUnauthorizedError(response);
return;
} else {
try {
userThatNeedsPasswordChange.changePassword(changePasswordDTO.getNewPassword(), changePasswordDTO.getNewPasswordConfirmation());
} catch (SimbaException ex) {
sendError(ErrorSender.UNABLE_TO_CHANGE_PASSWORD_ERROR_CODE, response, ex.getMessage());
return;
}
userRepository.flush();
}
}
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class ChainContextImplTest method redirectToChangePasswordDirect_userIsInTheApplication_ClicksChangePwd.
@Test
public void redirectToChangePasswordDirect_userIsInTheApplication_ClicksChangePwd() {
when(requestDataMock.getRequestURL()).thenReturn(URL_APPLICATION);
SSOToken ssoToken = new SSOToken();
when(requestDataMock.getSsoToken()).thenReturn(ssoToken);
LoginMapping loginMapping = new LoginMappingEntity(URL_APPLICATION);
when(loginMappingServiceMock.createMapping(URL_APPLICATION)).thenReturn(loginMapping);
chainContextImpl.redirectToChangePasswordDirect();
ActionDescriptor actionDescriptor = chainContextImpl.getActionDescriptor();
Set<ActionType> actionTypes = actionDescriptor.getActionTypes();
assertEquals(2, actionTypes.size());
assertTrue(actionTypes.contains(ADD_PARAMETER_TO_TARGET));
assertTrue(actionTypes.contains(REDIRECT));
assertEquals(SIMBA_WEB_URL + SIMBA_CHANGEPASSWORD_PAGE_URL, actionDescriptor.getRedirectURL());
Map<String, String> parameterMap = actionDescriptor.getParameterMap();
assertEquals(3, parameterMap.size());
assertTrue(parameterMap.containsKey(USERNAME));
assertTrue(parameterMap.containsKey(SIMBA_SSO_TOKEN));
assertTrue(parameterMap.containsKey(LOGIN_TOKEN));
Mockito.verify(loginMappingServiceMock).createMapping(URL_APPLICATION);
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class DatabaseAuditLogProviderTest method auditEventIsPersisted_digestNotEnabled.
@Test
public void auditEventIsPersisted_digestNotEnabled() {
when(configurationServiceMock.getValue(SimbaConfigurationParameter.AUDIT_LOG_INTEGRITY_ENABLED)).thenReturn(Boolean.FALSE);
SSOToken ssoToken = new SSOToken();
AuditLogEvent event = new AuditLogEvent(AuditLogEventCategory.SESSION, "username", ssoToken, "remoteIP", "message", "userAgent", "hostServerName", "surname", "firstname", "requestURL", "CHAINID");
provider.log(event);
jdbcTemplate.query("SELECT * FROM SIMBA_AUDIT_LOG WHERE ssoToken=?", getRowMapper(true), ssoToken.getToken());
}
use of org.simbasecurity.api.service.thrift.SSOToken in project simba-os by cegeka.
the class SimbaGatewayTest method login_WithUsernameAndPassword.
@Test
public void login_WithUsernameAndPassword() throws Exception {
String username = "appUser";
String password = "appPassword";
Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
RequestData requestData = mock(RequestData.class);
SSOToken ssoToken = new SSOToken("token");
ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(ssoToken).build();
when(simbaCredentialsFactoryMock.createForLogin(username, password)).thenReturn(simbaCredentials);
when(simbaCredentials.asRequestData()).thenReturn(requestData);
when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
Optional<String> actual = simbaGateway.login(username, password);
assertThat(actual.get()).isEqualTo(ssoToken.getToken());
}
Aggregations