Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public class HttpSessionSecurityContextRepository

  1. Object
  2. HttpSessionSecurityContextRepository

ImplementsSecurityContextRepository

Keeps who is signed in in the HTTP session, under SPRING_SECURITY_CONTEXT_KEY.

What is stored is a map of plain values – the name, the authorities, whether the authentication is trusted, and its details when they are plain values too – rather than the Authentication itself. The database session store keeps what JSON can write and hands it to whichever server takes the client’s next request, so an object would not survive the trip, and a server whose sessions are in memory behaves the same way so that moving to the database changes nothing.

The consequence: on a later request the principal is a User rebuilt from the name and authorities, with no password, not the object the user store returned at sign-in.

A way of signing in whose authentication is a kind of its own – a user of another identity provider, a passkey – keeps that kind through an AuthenticationCodec, which its configurer registers with HttpSecurity.authenticationCodec; see there. A subclass that needs something else again overrides toMap and fromMap.

Fields

public static final String SPRING_SECURITY_CONTEXT_KEY = "SPRING_SECURITY_CONTEXT"The session attribute the context is stored under.

Constructors

public HttpSessionSecurityContextRepository()

Methods

public void addAuthenticationCodec(AuthenticationCodec codec)Adds a codec; see AuthenticationCodec.
public void setAllowSessionCreation(boolean allowSessionCreation)Whether saving may start a session; true unless changed.
public SecurityContext loadContext(HttpServer.Request request)The context stored for request’s client; an empty one when there is none.
public void saveContext(SecurityContext context, HttpServer.Request request)Stores context for the client’s later requests.
public boolean containsContext(HttpServer.Request request)Whether anything is stored for request’s client.
protected Map<String, Object> toMap(Authentication authentication)authentication as the plain values a session store can keep.
protected Authentication fromMap(Map stored)The authentication toMap stored, or null when stored is not one.

Inherited methods

Field details

SPRING_SECURITY_CONTEXT_KEY

public static final String SPRING_SECURITY_CONTEXT_KEY = "SPRING_SECURITY_CONTEXT"
The session attribute the context is stored under.

Constructor details

HttpSessionSecurityContextRepository

public HttpSessionSecurityContextRepository()

Method details

addAuthenticationCodec

public void addAuthenticationCodec(AuthenticationCodec codec)
Adds a codec; see AuthenticationCodec. One of a kind that is here already replaces it.

setAllowSessionCreation

public void setAllowSessionCreation(boolean allowSessionCreation)
Whether saving may start a session; true unless changed. A chain with SessionCreationPolicy.NEVER turns it off.

loadContext

public SecurityContext loadContext(HttpServer.Request request)
The context stored for request’s client; an empty one when there is none.

saveContext

public void saveContext(SecurityContext context, HttpServer.Request request)
Stores context for the client’s later requests. An empty context, or an anonymous one, removes what was stored.

containsContext

public boolean containsContext(HttpServer.Request request)
Whether anything is stored for request’s client.

toMap

protected Map<String, Object> toMap(Authentication authentication)
authentication as the plain values a session store can keep.

fromMap

protected Authentication fromMap(Map stored)
The authentication toMap stored, or null when stored is not one.