@Override public void invalidateSession( Session session ) { cache.remove( session.getId() ); }
@Override public void updateCurrentSession() { if ( currentSession != null && currentSession.hasChanged() ) { try { configuration.getSessionStore().flush( currentSession ); } finally { currentSession.flush(); } } }
@Override public Account getAuthenticatedAccount() { return currentSession != null ? currentSession.getAuthenticatedAccount() : null; }
@Override public void setAuthenticatedAccount(Account account){ if ( getCurrentSession() != null ) { getCurrentSession().setAuthenticatedAccount(account); notifySecurityEvent( PROFILE_UPDATED ); } }
@Override public boolean authenticate() { authenticated = true; final Account account = performAuthentication(); if ( account == null ){ authenticated = false; getCurrentSession().setAuthenticatedAccount( account ); configuration.getAuthenticationFailureListener().onAuthenticationFailure( exchange, getCurrentSession(), currentAuthMechanism ); } else { getCurrentSession().setAuthenticatedAccount( account ); configuration.getAuthenticationSuccessListener().onAuthenticationSuccess(exchange, getCurrentSession(), currentAuthMechanism); notifySecurityEvent( LOGIN ); } updateCurrentSession(); return authenticated; }
@Override public void invalidateSession(Session session) { sessionCache.remove(session.getId()); }
private Account performAuthentication() { final Iterator<AuthenticationMechanism> iterator = rule.mechanisms().iterator(); Account account = getCurrentSession().getAuthenticatedAccount(); while ( account == null && iterator.hasNext() ) { currentAuthMechanism = iterator.next(); account = currentAuthMechanism.authenticate( exchange, rule.identityManagers(), getCurrentSession() ); } return account; }
@Override public void flush(Session session) { sessionCache.set(session.getId(), session); }
/** * Create a new {@link Session} and store it at the main storage. * * @param sessionId * @param exchange * @return */ default Session createAndStoreNewSession(String sessionId, HttpServerExchange exchange, SessionIdManager sessionIdManager ){ Session session = new DefaultSession( sessionId ); storeSession(session.getId(), session); sessionIdManager.attachSessionId(exchange, session.getId()); return session; }
@Override public void storeSession(String s, Session session) { if ( !session.getId().equals( SESSION_ID ) ) getSessionStore().storeSession(s, session); }