Search in sources :

Example 1 with SessionEvent

use of io.jans.as.server.service.external.session.SessionEvent in project jans by JanssenProject.

the class ExpirationNotificatorTimer method remove.

public boolean remove(SessionId sessionId) {
    try {
        persistenceEntryManager.remove(sessionId.getDn());
        externalApplicationSessionService.externalEvent(new SessionEvent(SessionEventType.GONE, sessionId));
        return true;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return false;
    }
}
Also used : SessionEvent(io.jans.as.server.service.external.session.SessionEvent)

Example 2 with SessionEvent

use of io.jans.as.server.service.external.session.SessionEvent in project jans by JanssenProject.

the class SessionIdService method remove.

public boolean remove(SessionId sessionId) {
    try {
        if (isTrue(appConfiguration.getSessionIdPersistInCache())) {
            cacheService.remove(sessionId.getDn());
        } else {
            persistenceEntryManager.remove(sessionId.getDn(), SessionId.class);
        }
        localCacheService.remove(sessionId.getDn());
        externalEvent(new SessionEvent(SessionEventType.GONE, sessionId));
        return true;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return false;
    }
}
Also used : SessionEvent(io.jans.as.server.service.external.session.SessionEvent) InvalidSessionStateException(io.jans.as.server.model.exception.InvalidSessionStateException) URISyntaxException(java.net.URISyntaxException) FailedComputeSessionStateException(io.jans.as.server.service.exception.FailedComputeSessionStateException) JSONException(org.json.JSONException) AcrChangedException(io.jans.as.server.model.exception.AcrChangedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) LDAPException(com.unboundid.ldap.sdk.LDAPException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 3 with SessionEvent

use of io.jans.as.server.service.external.session.SessionEvent in project jans by JanssenProject.

the class SessionIdService method reinitLogin.

/**
 * @param session
 * @param force
 * @return returns whether session was updated
 */
public boolean reinitLogin(SessionId session, boolean force) {
    final Map<String, String> sessionAttributes = session.getSessionAttributes();
    final Map<String, String> currentSessionAttributes = getCurrentSessionAttributes(sessionAttributes);
    if (force || shouldReinitSession(sessionAttributes, currentSessionAttributes)) {
        sessionAttributes.putAll(currentSessionAttributes);
        // Reinit login
        sessionAttributes.put("c", "1");
        for (Iterator<Entry<String, String>> it = currentSessionAttributes.entrySet().iterator(); it.hasNext(); ) {
            Entry<String, String> currentSessionAttributesEntry = it.next();
            String name = currentSessionAttributesEntry.getKey();
            if (name.startsWith("auth_step_passed_")) {
                it.remove();
            }
        }
        session.setSessionAttributes(currentSessionAttributes);
        if (force) {
            // Reset state to unauthenticated
            session.setState(SessionIdState.UNAUTHENTICATED);
            externalEvent(new SessionEvent(SessionEventType.UNAUTHENTICATED, session));
        }
        boolean updateResult = updateSessionId(session, true, true, true);
        if (!updateResult) {
            log.debug("Failed to update session entry: '{}'", session.getId());
        }
        return updateResult;
    }
    return false;
}
Also used : Entry(java.util.Map.Entry) SessionEvent(io.jans.as.server.service.external.session.SessionEvent)

Example 4 with SessionEvent

use of io.jans.as.server.service.external.session.SessionEvent in project jans by JanssenProject.

the class SessionIdService method setSessionIdStateAuthenticated.

public SessionId setSessionIdStateAuthenticated(HttpServletRequest httpRequest, HttpServletResponse httpResponse, SessionId sessionId, String userDn) {
    sessionId.setUserDn(userDn);
    sessionId.setAuthenticationTime(new Date());
    sessionId.setState(SessionIdState.AUTHENTICATED);
    final User user = getUser(sessionId);
    if (user != null) {
        statService.reportActiveUser(user.getUserId());
    }
    final boolean persisted;
    if (isTrue(appConfiguration.getChangeSessionIdOnAuthentication()) && httpResponse != null) {
        final String oldSessionId = sessionId.getId();
        final String newSessionId = UUID.randomUUID().toString();
        log.debug("Changing session id from {} to {} ...", oldSessionId, newSessionId);
        remove(sessionId);
        sessionId.setId(newSessionId);
        sessionId.setDn(buildDn(newSessionId));
        sessionId.getSessionAttributes().put(SessionId.OLD_SESSION_ID_ATTR_KEY, oldSessionId);
        if (isTrue(sessionId.getIsJwt())) {
            sessionId.setJwt(generateJwt(sessionId, sessionId.getUserDn()).asString());
        }
        persisted = persistSessionId(sessionId, true);
        cookieService.createSessionIdCookie(sessionId, httpRequest, httpResponse, false);
        log.debug("Session identifier changed from {} to {} .", oldSessionId, newSessionId);
    } else {
        persisted = updateSessionId(sessionId, true, true, true);
    }
    auditLogging(sessionId);
    log.trace("Authenticated session, id = '{}', state = '{}', persisted = '{}'", sessionId.getId(), sessionId.getState(), persisted);
    if (externalApplicationSessionService.isEnabled()) {
        String userName = sessionId.getSessionAttributes().get(Constants.AUTHENTICATED_USER);
        boolean externalResult = externalApplicationSessionService.executeExternalStartSessionMethods(httpRequest, sessionId);
        log.info("Start session result for '{}': '{}'", userName, externalResult);
        if (!externalResult) {
            reinitLogin(sessionId, true);
            throw new InvalidSessionStateException("Session creation is prohibited by external session script!");
        }
        externalEvent(new SessionEvent(SessionEventType.AUTHENTICATED, sessionId).setHttpRequest(httpRequest).setHttpResponse(httpResponse));
    }
    return sessionId;
}
Also used : SessionEvent(io.jans.as.server.service.external.session.SessionEvent) User(io.jans.as.common.model.common.User) InvalidSessionStateException(io.jans.as.server.model.exception.InvalidSessionStateException) Date(java.util.Date)

Example 5 with SessionEvent

use of io.jans.as.server.service.external.session.SessionEvent in project jans by JanssenProject.

the class SessionIdService method generateAuthenticatedSessionId.

public SessionId generateAuthenticatedSessionId(HttpServletRequest httpRequest, String userDn, Map<String, String> sessionIdAttributes) throws InvalidSessionStateException {
    SessionId sessionId = generateSessionId(userDn, new Date(), SessionIdState.AUTHENTICATED, sessionIdAttributes, true);
    if (sessionId == null) {
        throw new InvalidSessionStateException("Failed to generate authenticated session.");
    }
    reportActiveUser(sessionId);
    if (externalApplicationSessionService.isEnabled()) {
        String userName = sessionId.getSessionAttributes().get(Constants.AUTHENTICATED_USER);
        boolean externalResult = externalApplicationSessionService.executeExternalStartSessionMethods(httpRequest, sessionId);
        log.info("Start session result for '{}': '{}'", userName, externalResult);
        if (!externalResult) {
            reinitLogin(sessionId, true);
            throw new InvalidSessionStateException("Session creation is prohibited by external session script!");
        }
        externalEvent(new SessionEvent(SessionEventType.AUTHENTICATED, sessionId).setHttpRequest(httpRequest));
    }
    return sessionId;
}
Also used : SessionEvent(io.jans.as.server.service.external.session.SessionEvent) SessionId(io.jans.as.server.model.common.SessionId) InvalidSessionStateException(io.jans.as.server.model.exception.InvalidSessionStateException) Date(java.util.Date)

Aggregations

SessionEvent (io.jans.as.server.service.external.session.SessionEvent)6 InvalidSessionStateException (io.jans.as.server.model.exception.InvalidSessionStateException)3 Date (java.util.Date)3 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 User (io.jans.as.common.model.common.User)1 SessionId (io.jans.as.server.model.common.SessionId)1 AcrChangedException (io.jans.as.server.model.exception.AcrChangedException)1 FailedComputeSessionStateException (io.jans.as.server.service.exception.FailedComputeSessionStateException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 Entry (java.util.Map.Entry)1 JSONException (org.json.JSONException)1