Search in sources :

Example 1 with SSOTokenMapping

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;
}
Also used : SSOTokenMapping(org.simbasecurity.core.domain.SSOTokenMapping) LoginMapping(org.simbasecurity.core.domain.LoginMapping) Session(org.simbasecurity.core.domain.Session)

Example 2 with SSOTokenMapping

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 + "'");
}
Also used : SSOTokenMapping(org.simbasecurity.core.domain.SSOTokenMapping) Query(javax.persistence.Query)

Aggregations

SSOTokenMapping (org.simbasecurity.core.domain.SSOTokenMapping)2 Query (javax.persistence.Query)1 LoginMapping (org.simbasecurity.core.domain.LoginMapping)1 Session (org.simbasecurity.core.domain.Session)1