Search in sources :

Example 1 with Session

use of io.micronaut.session.Session in project micronaut-security by micronaut-projects.

the class SessionStatePersistence method persistState.

@Override
public void persistState(HttpRequest<?> request, MutableHttpResponse response, State state) {
    Session session = SessionForRequest.find(request).orElseGet(() -> SessionForRequest.create(sessionStore, request));
    session.put(SESSION_KEY, state);
}
Also used : Session(io.micronaut.session.Session)

Example 2 with Session

use of io.micronaut.session.Session in project micronaut-security by micronaut-projects.

the class SessionLogoutHandler method removeAuthenticationFromSession.

private void removeAuthenticationFromSession(HttpRequest<?> request) {
    MutableConvertibleValues<Object> attrs = request.getAttributes();
    Optional<Session> existing = attrs.get(HttpSessionFilter.SESSION_ATTRIBUTE, Session.class);
    if (existing.isPresent()) {
        Session session = existing.get();
        session.remove(SecurityFilter.AUTHENTICATION);
    }
}
Also used : Session(io.micronaut.session.Session)

Example 3 with Session

use of io.micronaut.session.Session in project micronaut-security by micronaut-projects.

the class SessionNoncePersistence method persistNonce.

@Override
public void persistNonce(HttpRequest<?> request, MutableHttpResponse response, String state) {
    Session session = SessionForRequest.find(request).orElseGet(() -> SessionForRequest.create(sessionStore, request));
    session.put(SESSION_KEY, state);
}
Also used : Session(io.micronaut.session.Session)

Example 4 with Session

use of io.micronaut.session.Session in project micronaut-security by micronaut-projects.

the class SessionAuthenticationFetcher method fetchAuthentication.

@Override
public Publisher<Authentication> fetchAuthentication(HttpRequest<?> request) {
    return Mono.<Authentication>create(emitter -> {
        Optional<Session> opt = request.getAttributes().get(HttpSessionFilter.SESSION_ATTRIBUTE, Session.class);
        if (opt.isPresent()) {
            Session session = opt.get();
            Optional<Authentication> authentication = session.get(SecurityFilter.AUTHENTICATION, Authentication.class);
            authentication.ifPresent(emitter::success);
        }
        emitter.success();
    });
}
Also used : Authentication(io.micronaut.security.authentication.Authentication) Session(io.micronaut.session.Session)

Example 5 with Session

use of io.micronaut.session.Session in project micronaut-security by micronaut-projects.

the class SessionLoginHandler method saveAuthenticationInSession.

private void saveAuthenticationInSession(Authentication authentication, HttpRequest<?> request) {
    Session session = SessionForRequest.find(request).orElseGet(() -> SessionForRequest.create(sessionStore, request));
    session.put(SecurityFilter.AUTHENTICATION, authentication);
}
Also used : Session(io.micronaut.session.Session)

Aggregations

Session (io.micronaut.session.Session)6 NonNull (io.micronaut.core.annotation.NonNull)1 TenantNotFoundException (io.micronaut.multitenancy.exceptions.TenantNotFoundException)1 Authentication (io.micronaut.security.authentication.Authentication)1 Serializable (java.io.Serializable)1