44import com .nimbusds .oauth2 .sdk .util .StringUtils ;
55import org .springframework .security .oauth2 .client .web .AuthorizationRequestRepository ;
66import org .springframework .security .oauth2 .core .endpoint .OAuth2AuthorizationRequest ;
7- import org .springframework .util .Assert ;
87import javax .servlet .http .HttpServletRequest ;
98import javax .servlet .http .HttpServletResponse ;
109
1110public class HttpCookieOAuth2AuthorizationRequestRepository implements AuthorizationRequestRepository <OAuth2AuthorizationRequest > {
1211 public static final String OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME = "oauth2_auth_request" ;
1312 public static final String REDIRECT_URI_PARAM_COOKIE_NAME = "redirect_uri" ;
14- private static final int cookieExpireSeconds = 120 ;
13+ private static final int cookieExpireSeconds = 180 ;
1514
1615 @ Override
1716 public OAuth2AuthorizationRequest loadAuthorizationRequest (HttpServletRequest request ) {
18- Assert .notNull (request , "request cannot be null" );
1917 return CookieUtils .getCookie (request , OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME )
2018 .map (cookie -> CookieUtils .deserialize (cookie , OAuth2AuthorizationRequest .class ))
2119 .orElse (null );
2220 }
2321
2422 @ Override
2523 public void saveAuthorizationRequest (OAuth2AuthorizationRequest authorizationRequest , HttpServletRequest request , HttpServletResponse response ) {
26- Assert .notNull (request , "request cannot be null" );
27- Assert .notNull (response , "response cannot be null" );
28- 2924 if (authorizationRequest == null ) {
3025 CookieUtils .deleteCookie (request , response , OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME );
3126 CookieUtils .deleteCookie (request , response , REDIRECT_URI_PARAM_COOKIE_NAME );
@@ -41,14 +36,13 @@ public void saveAuthorizationRequest(OAuth2AuthorizationRequest authorizationReq
4136
4237 @ Override
4338 public OAuth2AuthorizationRequest removeAuthorizationRequest (HttpServletRequest request ) {
44- Assert .notNull (request , "request cannot be null" );
4539 /*
4640 Ideally, the saved OAuth2AuthorizationRequest should be removed in this method.
4741
4842 Since we're saving the OAuth2AuthorizationRequest in cookies, we need access to the HttpServletResponse to clear them.
4943 But that is not passed to this method.
5044
51- Therefore, We'll clear the cookies in Oauth2AuthenticationSuccessHandler instead.
45+ Therefore, We'll clear the cookies in OAuth2AuthenticationSuccessHandler instead.
5246 */
5347 return loadAuthorizationRequest (request );
5448 }
0 commit comments