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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:03:24+00:00 2026-05-24T07:03:24+00:00

I’m trying to convert a Stripes web app to Grails. The Stripes app uses

  • 0

I’m trying to convert a Stripes web app to Grails. The Stripes app uses Spring Security, but I would like the Grails app to use the Spring Security Grails plugin.

The app already has User and Role (Java) classes that I need to reuse, i.e. I cannot use the Grails domain classes that the s2-quickstart script generates.

The Spring Security plugin docs describe how to use an existing User domain class. The steps seem to be:

  1. define a UserDetails implementation that reads from the existing User domain class
  2. define a custom UserDetailsService implementation that returns instances of (1)
  3. register an instance of (2) as a Spring bean named userDetailsService.

However the docs don’t provide any information about how to use an existing Role class and the class that represents the many-to-many relationship between User and Role.

What other steps are necessary to use existing Role, User, and UserRole classes with the Grails Spring Security plugin? Is there any reason for me to run the s2-quickstart script if I don’t want to generate any domain classes?

Follow-Up Questions to Burt’s Answer

In the end, what you need is a new GrailsUser

Presumably GrailsUser here refers to the custom UserDetails implementation? In my case I’ll probably just implement the interface directly. Does something like this seem reasonable?

class UserAdapter implements UserDetails {
  private String password  
  private Collection<GrantedAuthority> springRoles

  UserAdapter(User user) {
    this.password = user.password

    Collection<Role> roles = // load legacy Role objects
    this.springRoles = roles.collect { new GrantedAuthorityImpl(it.authority) }
  }      

  // If using password hashing, presumably this is the hashed password?
  String getPassword() {
    password  
  }

  ///////// other UserDetails methods omitted

  Collection<GrantedAuthority> getAuthorities() {
    springRoles
  }
}

I’m not storing the whole User object within UserAdapter because of your warning about storing a potentially large object in the HTTP session.

what you need is…..and a List of GrantedAuthority instances (and the id if it’s a GrailsUser)

If I use my own UserDetails implementation as above, then presumably I can ignore this comment about providing an id?

Finally, if I follow the approach outlined above, should I set these properties in Config.groovy and do I need to run the s2-quickstart script (or any others)?

  • 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-05-24T07:03:25+00:00Added an answer on May 24, 2026 at 7:03 am

    Keep in mind that Spring Security doesn’t care where the data comes from, it just needs a UserDetails instance when authenticating with the DAO auth provider and it can come from anywhere. It’s convenient to use domain classes and database tables, but it’s just one approach. Do what works for your data. In the end, what you need is a new GrailsUser (or some other impl) instance with the username and password set, the 3 booleans set, and a List of GrantedAuthority instances (and the id if it’s a GrailsUser).

    The simplest thing to do when you have legacy user and role data is to create a custom UserDetailsService. Use GORM, raw SQL queries, whatever you need to get the required data.

    Another option is to write your own AuthenticationProvider like Glen did here: http://blogs.bytecode.com.au/glen/2010/01/15/hacking-custom-authentication-providers-with-grails-spring-security.html – although that’s a larger solution that also involves a custom filter which you wouldn’t need. The DAO provider uses a UserDetailsService but it’s fine to create your own that combines the functionality into one class.

    It’s not a good idea to reuse your User domain class as the UserDetails though. Even if you implement the interface, you’d be storing a disconnected potentially large (if there are attached collections) object in the HTTP session. The POJO/POGO implementations (Spring Security’s User class, the plugin’s GrailsUser class, etc.) are very small and just a few Strings and booleans.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.