You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by sb...@apache.org on 2025/08/14 09:04:58 UTC

(grails-spring-security) branch fix/plugin-rest_pac4j_JEESessionStore created (now c749429a)

This is an automated email from the ASF dual-hosted git repository.

sbglasius pushed a change to branch fix/plugin-rest_pac4j_JEESessionStore
in repository https://gitbox.apache.org/repos/asf/grails-spring-security.git


      at c749429a Fixed usage of client.getRedirectAction by adding CallContext

This branch includes the following new commits:

     new c749429a Fixed usage of client.getRedirectAction by adding CallContext

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(grails-spring-security) 01/01: Fixed usage of client.getRedirectAction by adding CallContext

Posted by sb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sbglasius pushed a commit to branch fix/plugin-rest_pac4j_JEESessionStore
in repository https://gitbox.apache.org/repos/asf/grails-spring-security.git

commit c749429a2f28604d195d6a0f644793284bb5fe58
Author: Søren Berg Glasius <so...@glasius.dk>
AuthorDate: Thu Aug 14 11:04:51 2025 +0200

    Fixed usage of client.getRedirectAction by adding CallContext
---
 .../springsecurity/rest/RestOauthController.groovy | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/plugin-rest/spring-security-rest/grails-app/controllers/grails/plugin/springsecurity/rest/RestOauthController.groovy b/plugin-rest/spring-security-rest/grails-app/controllers/grails/plugin/springsecurity/rest/RestOauthController.groovy
index f5d59b0b..9c15b43a 100644
--- a/plugin-rest/spring-security-rest/grails-app/controllers/grails/plugin/springsecurity/rest/RestOauthController.groovy
+++ b/plugin-rest/spring-security-rest/grails-app/controllers/grails/plugin/springsecurity/rest/RestOauthController.groovy
@@ -32,10 +32,12 @@ import org.apache.commons.codec.binary.Base64
 import org.grails.plugins.codecs.URLCodec
 import org.pac4j.core.client.IndirectClient
 import org.pac4j.core.context.CallContext
-import org.pac4j.core.context.WebContext
+import org.pac4j.core.context.session.SessionStore
+import org.pac4j.core.exception.http.FoundAction
 import org.pac4j.core.exception.http.RedirectionAction
 import org.pac4j.jee.context.JEEContext
 import org.pac4j.jee.context.session.JEESessionStore
+import org.pac4j.jee.context.session.JEESessionStoreFactory
 import org.springframework.http.HttpStatus
 import org.springframework.security.core.userdetails.User
 
@@ -46,7 +48,7 @@ import java.nio.charset.StandardCharsets
 class RestOauthController {
 
     static allowedMethods = [accessToken: 'POST']
-
+    private static final SessionStore SESSION_STORE = JEESessionStoreFactory.INSTANCE.newSessionStore(null)
     final String CALLBACK_ATTR = "spring-security-rest-callback"
 
     CallbackErrorHandler callbackErrorHandler
@@ -64,8 +66,7 @@ class RestOauthController {
      */
     def authenticate(String provider, String callback) {
         IndirectClient client = restOauthService.getClient(provider)
-        WebContext context = new JEEContext(request, response)
-
+        
         if (callback) {
             try {
                 if (Base64.isBase64(callback.getBytes())){
@@ -78,9 +79,14 @@ class RestOauthController {
             }
         }
 
-        RedirectionAction redirectAction = client.getRedirectionAction(context, JEESessionStore.INSTANCE).get()
-        log.debug "Redirecting to ${redirectAction.location}"
-        redirect url: redirectAction.location
+        CallContext callContext = new CallContext(new JEEContext(request, response), SESSION_STORE)
+        RedirectionAction redirectAction = client.getRedirectionAction(callContext).get()
+        if(redirectAction instanceof FoundAction) {
+            log.debug "Redirecting to ${redirectAction.location}"
+            redirect url: redirectAction.location
+        } else {
+            response.status = redirectAction.code
+        }
     }
 
     /**
@@ -89,7 +95,7 @@ class RestOauthController {
      * frontend application can store the REST API token locally for subsequent API calls.
      */
     def callback(String provider) {
-        CallContext context = new CallContext(new JEEContext(request, response), null)
+        CallContext context = new CallContext(new JEEContext(request, response), SESSION_STORE)
         def frontendCallbackUrl
         if (session[CALLBACK_ATTR]) {
             log.debug "Found callback URL in the HTTP session"