|
|
|
@ -46,6 +46,8 @@ public class WebSessionServerSecurityContextRepository implements ServerSecurity |
|
|
|
|
|
|
|
|
|
|
|
private String springSecurityContextAttrName = DEFAULT_SPRING_SECURITY_CONTEXT_ATTR_NAME; |
|
|
|
private String springSecurityContextAttrName = DEFAULT_SPRING_SECURITY_CONTEXT_ATTR_NAME; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean cacheSecurityContext; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the session attribute name used to save and load the {@link SecurityContext} |
|
|
|
* Sets the session attribute name used to save and load the {@link SecurityContext} |
|
|
|
* @param springSecurityContextAttrName the session attribute name to use to save and |
|
|
|
* @param springSecurityContextAttrName the session attribute name to use to save and |
|
|
|
@ -56,6 +58,16 @@ public class WebSessionServerSecurityContextRepository implements ServerSecurity |
|
|
|
this.springSecurityContextAttrName = springSecurityContextAttrName; |
|
|
|
this.springSecurityContextAttrName = springSecurityContextAttrName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* If set to true the result of {@link #load(ServerWebExchange)} will use |
|
|
|
|
|
|
|
* {@link Mono#cache()} to prevent multiple lookups. |
|
|
|
|
|
|
|
* @param cacheSecurityContext true if {@link Mono#cache()} should be used, else |
|
|
|
|
|
|
|
* false. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setCacheSecurityContext(boolean cacheSecurityContext) { |
|
|
|
|
|
|
|
this.cacheSecurityContext = cacheSecurityContext; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) { |
|
|
|
public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) { |
|
|
|
return exchange.getSession().doOnNext((session) -> { |
|
|
|
return exchange.getSession().doOnNext((session) -> { |
|
|
|
@ -72,13 +84,14 @@ public class WebSessionServerSecurityContextRepository implements ServerSecurity |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Mono<SecurityContext> load(ServerWebExchange exchange) { |
|
|
|
public Mono<SecurityContext> load(ServerWebExchange exchange) { |
|
|
|
return exchange.getSession().flatMap((session) -> { |
|
|
|
Mono<SecurityContext> result = exchange.getSession().flatMap((session) -> { |
|
|
|
SecurityContext context = (SecurityContext) session.getAttribute(this.springSecurityContextAttrName); |
|
|
|
SecurityContext context = (SecurityContext) session.getAttribute(this.springSecurityContextAttrName); |
|
|
|
logger.debug((context != null) |
|
|
|
logger.debug((context != null) |
|
|
|
? LogMessage.format("Found SecurityContext '%s' in WebSession: '%s'", context, session) |
|
|
|
? LogMessage.format("Found SecurityContext '%s' in WebSession: '%s'", context, session) |
|
|
|
: LogMessage.format("No SecurityContext found in WebSession: '%s'", session)); |
|
|
|
: LogMessage.format("No SecurityContext found in WebSession: '%s'", session)); |
|
|
|
return Mono.justOrEmpty(context); |
|
|
|
return Mono.justOrEmpty(context); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
return (cacheSecurityContext) ? result.cache() : result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|