Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:57:36+00:00 2026-06-15T22:57:36+00:00

In my grails app I have customized the post authorization workflow by writing a

  • 0

In my grails app I have customized the post authorization workflow by writing a custom auth success handler (in resources.groovy) as shown below.

authenticationSuccessHandler (MyAuthSuccessHandler) {
    def conf = SpringSecurityUtils.securityConfig
    requestCache = ref('requestCache')
    defaultTargetUrl = conf.successHandler.defaultTargetUrl
    alwaysUseDefaultTargetUrl = conf.successHandler.alwaysUseDefault
    targetUrlParameter = conf.successHandler.targetUrlParameter
    useReferer = conf.successHandler.useReferer
    redirectStrategy = ref('redirectStrategy')
    superAdminUrl = "/admin/processSuperAdminLogin"
    adminUrl = "/admin/processAdminLogin"
    userUrl = "/admin/processUserLogin"
}

As you can from the last three lines in the closure above, depending on the Role granted to the logging in User I am redirecting her to separate actions within the AdminController where a custom UserSessionBean is created and stored in the session.

It works fine for a regular login case which in my app is like so:

  1. User comes to the app via either http://localhost:8080/my-app/ OR http://localhost:8080/my-app/login/auth
  2. She enters her valid login id and password and proceeds.
  3. The app internally accesses MyAuthSuccessHandler which redirects to AdminController considering the Role granted to this User.
  4. The UserSessionBean is created and stored it in the session
  5. User is taken to the app home page

I have also written a custom MyUserDetailsService by extending GormUserDetailsService which is correctly accessed in the above flow.

PROBLEM SCENARIO:
Consider a user directly accessing a protected resource (in this case the controller is secured with @Secured annotation) within the app.

  1. User clicks http://localhost:8080/my-app/inbox/index
  2. App redirects her to http://localhost:8080/my-app/login/auth
  3. User enters her valid login id and password
  4. User is taken to http://localhost:8080/my-app/inbox/index

The MyAuthSuccessHandler is skipped entirely in this process and hence my UserSessionBean is not created leading to errors upon further use in places where the UserSessionBean is accessed.

QUESTIONS:

  1. In the problem scenario, does the app skip the MyAuthSuccessHandler because there is a target URL for it to redirect to upon login?
  2. Can we force the process to always pass through MyAuthSuccessHandler even with the target URL present?
  3. If the answer to 2 is no, is there an alternative as to how and where the UserSessionBean can still be created?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:57:38+00:00Added an answer on June 15, 2026 at 10:57 pm

    You can implement a customized eventListener to handle the post-login process, without disrupting the original user requested url.

    In config.groovy, insert a config item:

    grails.plugins.springsecurity.useSecurityEventListener = true
    

    In you resources.groovy, add a bean like this:

    import com.yourapp.auth.LoginEventListener
    beans = {
        loginEventListener(LoginEventListener)
    }
    

    And create a eventListener in src/groovy like this:

    package com.yourapp.auth
    import org.springframework.context.ApplicationListener;
    import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent
    import org.springframework.web.context.request.RequestContextHolder as RCH
    
    class LoginEventListener implements
        ApplicationListener<InteractiveAuthenticationSuccessEvent> {    
    
        //deal with successful login    
        void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
            User.withTransaction { 
                def user = User.findByUsername(event.authentication.principal.username)
                        def adminRole = Role.findByAuthority('ROLE_ADMIN')
                        def userRole = Role.findByAuthority('ROLE_USER')
                        def session = RCH.currentRequestAttributes().session      //get httpSession
                        session.user = user
                        if(user.authorities.contains(adminRole)){
                            processAdminLogin()
                        }
                        else if(user.authorities.contains(userRole)){
                            processUserLogin()
                        }
            }
        }
    
        private void processAdminLogin(){    //move admin/processAdminLogin here
              .....
        }
    
        private void processUserLogin(){    //move admin/processUserLogin here
              .....
        }
    }
    

    Done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Grails/Groovy app and I have a JSON object with a
I have a variable in my Grails app’s BootStrap.groovy : class BootStrap { def
I am writing a Grails app and I have a quick question about the
I have this domain model, grails-app/domain , named com.portal.Schedule.groovy having this properties: Subject subject
I need a custom command-line task in my grails app, so I have created
I have a grails app that uses functionality from a set of custom java
I have a Grails app that loads its data from xml files and delivers
I have upgraded my grails app from 1.3.7 to 2.0.1. I had few static
I have inherited a Grails app, which uses the Acegi 0.5.3 plugin. The application
I have a page X in my grails app which has a button to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.