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 9244727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:06:23+00:00 2026-06-18T09:06:23+00:00

I am trying to do PreAuthentication using Spring Security Grails plugin. I read the

  • 0

I am trying to do PreAuthentication using Spring Security Grails plugin. I read the pre authentication documentation given below, but could not find anything concrete for my situation
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/preauth.html

In my situation, we have a agent which parses the SAML request and gives a map after successful authentication. Recommendation is to use this jar. Hence, I extended AbstractPreAuthenticatedProcessingFilter and try to do this

@Override 
    protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) { 
      userInfo = agent.readToken(request); 
        if (!userInfo){ 
             WebUtils.retrieveGrailsWebRequest().getCurrentResponse().sendRedirect(ssoUrl) 
        } 
        return userInfo 
}

I have placed myFilter under src/groovy and registered this filter in BootStrap

def init = { servletContext -> 
        SpringSecurityUtils.clientRegisterFilter( 
                'myFilter', SecurityFilterPosition.PRE_AUTH_FILTER.order) 
} 

Its getting loaded correctly, but filter is not issuing a redirect. First of all, I wanted to check if this is the right approach and if it is, how to get redirect working.

I have asked the same question in grails user forum

Any help is greatly appreciated.

Update:

Final configuration which worked for me

Wrote MyAuthenticationService which implements AuthenticationUserDetailsService as suggested. You also have to define preAuthenticatedAuthenticationProvider which wraps your custom service

resources.groovy

securityFilter(MySSOAuthFilters){ bean ->
    authenticationManager = ref('authenticationManager')
    grailsApplication = ref('grailsApplication')
}

customUserDetailsService(MyAuthenticationService)

preAuthenticatedAuthenticationProvider(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider) {
    preAuthenticatedUserDetailsService = ref('customUserDetailsService')
}

I was not able to do <form-login> because in Grails, this is done using
grails.plugins.springsecurity.auth.loginFormUrl config parameter which only accepts relative url.

What I ended up doing is grails.plugins.springsecurity.auth.loginFormUrl = ‘/login/index’

In LoginController

def index() {
    if(springSecurityService.isLoggedIn()){
        log.info("User is logged in")
        return redirect(controller: 'mycontroller', action: 'list')
    }
    log.info("user is not logged in...redirect to sso.")
    return redirect(url: ssoUrl)
}

Hope this helps

  • 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-18T09:06:24+00:00Added an answer on June 18, 2026 at 9:06 am

    A couple of things I see that need to be changed.

    First, do not to send a redirect in the preauth filter just simply return null. The preauth filter is only used to return a subject that your AuthenticationUserDetailsService can use to create the UserDetails object by implementing the method below in your implementation of the AuthenticationUserDetailsService .

    public UserDetails loadUserDetails(AbstractAuthenticationToken token) {
        return createUserFromSubject((Subject) token.getPrincipal());
    }
    

    Second, set the form login page as part of your configuration. This will be used to redirect to if no subject exists.

    <form-login login-page="http://url_youwanttoredirect_to_on_auth_req" authentication-failure-url="http://url_youwanttoredirect_to_on_auth_req"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.
trying to instantiate a Query in SubSonic using the below method (as it apparently
Trying to write dynamic queries using the LINQ provider for NHibernate, but I am
Trying to understand isolation levels better - using entity framework and sql server What
Trying to print the prime factors of a number using Erathosthenes sieve instead of
Trying to do a script to download a file using wget, or curl if
Trying to connect to a SQL Server 2005 instance remotely but getting the following
Trying to find the links on a page. my regex is: /<a\s[^>]*href=(\\'??)([^\\' >]*?)[^>]*>(.*)<\/a>/ but
Trying to use Net::SFTP, version 2.05 (appears to be the latest). But it fails
Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and

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.