user1170646
user1170646

Reputation: 11

Grails Spring Security SecUser

can i create two different types of secuser's such as secuser and enduser ,SecRole and EndRole where my secuser and secrole will be given for admins of my hospital and doctors and enduser,endrole will be given to endusers of my hospital project

I have secuser and secrole tables with me but when i created enduser and endrole with s2-quickstart command am able to get the domain classes and i didn't overide my login and logout controllers now am not able to create a enduser object endrole object in my boot strap

class BootStrap {
   def springSecurityService
   def init = { servletContext ->

      /*
      def userRole = EndRole.findByAuthority('ROLE_USER') ?: new EndRole(authority: 'ROLE_USER').save(failOnError: true)

      def endadminUser = EndUser.findByUsername('endadmin') ?: new EndUser(
         username: 'endadmin',
         password:'endadmin',enabled: true).save(failOnError: true)

      if (!endadminUser.authorities.contains(userRole)) {
         EndUserEndRole.create endadminUser, userRole
      }
      */

      def x= new EndRole(authority: 'ROLE_USER')
      println("    new fresh      "+x.authority)
   }
   def destroy = {
   }
}

Upvotes: 0

Views: 768

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75681

You can have as many types of user as you want, but to support that you will need a custom UserDetailsService. This is a common thing to do, so there's a section in the docs for it; see section "11 Custom UserDetailsService" in http://grails-plugins.github.com/grails-spring-security-core/docs/manual/

I'm not sure why you think you need more than one role class though. Just create an instance of SecRole with a different role name for admins and doctors, e.g. new SecRole(authority: 'ROLE_DOCTOR').save(), new SecRole(authority: 'ROLE_ADMIN').save().

You probably don't need different user classes at all (at least not for security - you may need to support different attributes for non-security reasons). Just create SecUser instances and grant them whatever roles (with EndUserEndRole.create) they need, i.e. ROLE_DOCTOR or ROLE_ADMIN.

Do yourself a favor and read the plugin documentation, but also the Spring Security documentation at http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity.html - this stuff is way too important to implement if you're not comfortable with how to secure a web site.

Upvotes: 1

Related Questions