use of org.simbasecurity.core.domain.SSOTokenMapping in project simba-os by cegeka.
the class CreateSessionCommand method execute.
@Override
public State execute(ChainContext context) throws Exception {
String targetURL;
if (context.isLoginUsingJSP()) {
LoginMapping mapping = context.getLoginMapping();
if (mapping != null) {
targetURL = mapping.getTargetURL();
} else {
String successURL = credentialService.getSuccessURL(context.getUserName());
if (StringUtils.isBlank(successURL)) {
audit.log(auditLogFactory.createEventForAuthenticationForFailure(context, AuditMessages.EMPTY_SUCCESS_URL));
context.redirectWithCredentialError(SimbaMessageKey.EMPTY_SUCCESS_URL);
return State.FINISH;
}
targetURL = successURL;
}
} else if (context.isLoginUsingEID()) {
targetURL = context.getSimbaEidSuccessUrl();
} else {
targetURL = context.getRequestURL();
}
Session session = sessionService.createSession(context.getUserName(), context.getClientIpAddress(), context.getHostServerName(), context.getUserAgent(), context.getRequestURL());
SSOTokenMapping ssoMappingToken = ssoTokenMappingService.createMapping(session.getSSOToken());
targetURL = RequestUtil.addParametersToUrlAndFilterInternalParameters(targetURL, context.getRequestParameters());
if (!context.isLoginUsingJSP()) {
context.activateAction(ActionType.MAKE_COOKIE);
context.setSSOTokenForActions(session.getSSOToken());
context.setMappingTokenForActions(ssoMappingToken.getToken());
} else {
targetURL = RequestUtil.addParameterToUrl(targetURL, RequestConstants.SIMBA_SSO_TOKEN, ssoMappingToken.getToken());
}
context.activateAction(ActionType.REDIRECT);
context.setRedirectURL(targetURL);
context.setNewSession(session);
audit.log(auditLogFactory.createEventForSessionForSuccess(context, AuditMessages.SESSION_CREATED + ": SSOToken=" + session.getSSOToken().getToken()));
return State.FINISH;
}
use of org.simbasecurity.core.domain.SSOTokenMapping in project simba-os by cegeka.
the class SSOTokenMappingDatabaseRepository method findByToken.
@SuppressWarnings("unchecked")
@Override
public SSOTokenMapping findByToken(String tokenKey) {
Query query = entityManager.createQuery("SELECT tm FROM SSOTokenMappingEntity tm WHERE tm.token = :token").setParameter("token", tokenKey);
List<SSOTokenMapping> resultList = query.getResultList();
if (resultList.size() == 0) {
return null;
} else if (resultList.size() == 1) {
return resultList.get(0);
}
throw new IllegalStateException("Multiple mappings found for tokenKey: '" + tokenKey + "'");
}
Aggregations