Difference between revisions of "Grails Plugins"

From Blue-IT.org Wiki

(Integrade domain classes)
 
(28 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
All plugins can be downloaded at: [http://grails.org/plugins http://grails.org/plugins]
 
All plugins can be downloaded at: [http://grails.org/plugins http://grails.org/plugins]
 
== Multi Tenant ==
 
An introduction on the concept of multitenant can be found at:
 
* [http://en.wikipedia.org/wiki/Multitenancy http://en.wikipedia.org/wiki/Multitenancy]
 
* [http://www.itwissen.info/definition/lexikon/Multi-Tenancy-Architektur-multitenancy-architecture.html It-Wissen Multitenancy]
 
 
Documentation
 
* [http://multi-tenant.github.com/grails-multi-tenant-core/guide/ http://multi-tenant.github.com/grails-multi-tenant-core/guide/]
 
 
  
 
== Spring Security ==
 
== Spring Security ==
Line 30: Line 21:
  
 
  class BootStrap {
 
  class BootStrap {
 
+
 
   '''def dpringSecurityService'''
 
   '''def dpringSecurityService'''
 
   
 
   
Line 56: Line 47:
 
   
 
   
 
  '''import grails.plugins.springsecurity.Secured'''
 
  '''import grails.plugins.springsecurity.Secured'''
 
+
 
  class DomainClassController {
 
  class DomainClassController {
 
   
 
   
Line 63: Line 54:
 
         [...]
 
         [...]
 
     }
 
     }
 
+
 
  }
 
  }
  
Line 69: Line 60:
  
 
  class DomainClassController {
 
  class DomainClassController {
 
+
 
     @Secured(['ROLE_USER'])
 
     @Secured(['ROLE_USER'])
 
     def myAction = {
 
     def myAction = {
 
         def currentUser = currentuser();
 
         def currentUser = currentuser();
 
         [...]
 
         [...]
 
+
 
     }  
 
     }  
+
 
 
         [...]
 
         [...]
 
     '''private currentUser()''' {
 
     '''private currentUser()''' {
 
         '''User.get(springSecurityService.principal.id)'''
 
         '''User.get(springSecurityService.principal.id)'''
 +
 +
[[Category:Java, Groovy and Grails]]

Latest revision as of 19:50, 8 January 2012

All plugins can be downloaded at: http://grails.org/plugins

Spring Security

s2-quickstart

grails s2quickstart  your.package SecUser SecRole

creates two domain classes and corresponding controllers.

Integrade domain classes

class MyDomainClass extends SecUser {

    [...]
}

BootStrap.groovy

class BootStrap {

  def dpringSecurityService

  def init = {
    
      def userRole = SecRole.findByAuthority("ROLE_USER") ?: new SecRole(authority: "ROLE_USER").save()
      def adminRole = SecRole.findByAuthority("ROLE_ADMIN") ?: new SecRole(authority: "ROLE_ADMIN").save()
      [...]
  }
  
  def users = User.list() ?: []
  if (!users) {
     def user = new User(
         [...]
         password: springSecurityService.enodePassord("myPass")
         enabled = true
     )
  }

  SecUserSecRole.create user, userRole
 
}

Annotate the controller actions

import grails.plugins.springsecurity.Secured

class DomainClassController {

   @Secured(['ROLE_USER'])
   def myAction = {
       [...]
   }

}

Create a currentUser() method in the controller

class DomainClassController {

   @Secured(['ROLE_USER'])
   def myAction = {
       def currentUser = currentuser();
       [...]

   } 
  
       [...]
   private currentUser() {
        User.get(springSecurityService.principal.id)