private Mono<Map<String, OAuth2AuthorizationRequest>> getStateToAuthorizationRequest(ServerWebExchange exchange, boolean create) { Assert.notNull(exchange, "exchange cannot be null"); return getSessionAttributes(exchange) .doOnNext(sessionAttrs -> { if (create) { sessionAttrs.putIfAbsent(this.sessionAttributeName, new HashMap<String, OAuth2AuthorizationRequest>()); } }) .flatMap(sessionAttrs -> Mono.justOrEmpty(this.sessionAttrsMapStateToAuthorizationRequest(sessionAttrs))); }
@Override public Mono<OAuth2AuthorizationRequest> removeAuthorizationRequest( ServerWebExchange exchange) { String state = getStateParameter(exchange); if (state == null) { return Mono.empty(); } return exchange.getSession() .map(WebSession::getAttributes) .handle((sessionAttrs, sink) -> { Map<String, OAuth2AuthorizationRequest> stateToAuthzRequest = sessionAttrsMapStateToAuthorizationRequest(sessionAttrs); if (stateToAuthzRequest == null) { sink.complete(); return; } OAuth2AuthorizationRequest removedValue = stateToAuthzRequest.remove(state); if (stateToAuthzRequest.isEmpty()) { sessionAttrs.remove(this.sessionAttributeName); } if (removedValue == null) { sink.complete(); } else { sink.next(removedValue); } }); }
private Mono<Map<String, OAuth2AuthorizationRequest>> getStateToAuthorizationRequest(ServerWebExchange exchange, boolean create) { Assert.notNull(exchange, "exchange cannot be null"); return getSessionAttributes(exchange) .doOnNext(sessionAttrs -> { if (create) { sessionAttrs.putIfAbsent(this.sessionAttributeName, new HashMap<String, OAuth2AuthorizationRequest>()); } }) .flatMap(sessionAttrs -> Mono.justOrEmpty(this.sessionAttrsMapStateToAuthorizationRequest(sessionAttrs))); }
@Override public Mono<OAuth2AuthorizationRequest> removeAuthorizationRequest( ServerWebExchange exchange) { String state = getStateParameter(exchange); if (state == null) { return Mono.empty(); } return exchange.getSession() .map(WebSession::getAttributes) .handle((sessionAttrs, sink) -> { Map<String, OAuth2AuthorizationRequest> stateToAuthzRequest = sessionAttrsMapStateToAuthorizationRequest(sessionAttrs); if (stateToAuthzRequest == null) { sink.complete(); return; } OAuth2AuthorizationRequest removedValue = stateToAuthzRequest.remove(state); if (stateToAuthzRequest.isEmpty()) { sessionAttrs.remove(this.sessionAttributeName); } if (removedValue == null) { sink.complete(); } else { sink.next(removedValue); } }); }