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;
}
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations