Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merged s2-quickstart-groups into s2-quickstart with the --groupClassN…

…ame flag
  • Loading branch information...
commit 78f3e2c4dee6c82b2b15e2bff391b87ef1bd31d5 1 parent 825804f
@burtbeckwith burtbeckwith authored
View
27 scripts/S2Quickstart.groovy
@@ -17,11 +17,13 @@ import grails.util.GrailsNameUtils
includeTargets << new File(springSecurityCorePluginDir, 'scripts/_S2Common.groovy')
USAGE = """
-Usage: grails s2-quickstart <domain-class-package> <user-class-name> <role-class-name> [requestmap-class-name]
+Usage: grails s2-quickstart <domain-class-package> <user-class-name> <role-class-name> [requestmap-class-name] [--groupClassName=group-class-name]
-Creates a user and role class (and optionally a requestmap class) in the specified package
+Creates a user and role class (and optionally a requestmap class) in the specified package.
+If you specify a role-group name with the groupClassName argument, role/group classes will also be generated.
Example: grails s2-quickstart com.yourapp User Role
+Example: grails s2-quickstart com.yourapp User Role --groupClassName=RoleGroup
Example: grails s2-quickstart com.yourapp Person Authority Requestmap
"""
@@ -31,6 +33,7 @@ packageName = ''
userClassName = ''
roleClassName = ''
requestmapClassName = ''
+groupClassName = ''
target(s2Quickstart: 'Creates artifacts for the Spring Security plugin') {
depends(checkVersion, configureProxy, packageApp, classpath)
@@ -71,7 +74,9 @@ private boolean configure() {
userClassProperty: GrailsNameUtils.getPropertyName(userClassName),
roleClassName: roleClassName,
roleClassProperty: GrailsNameUtils.getPropertyName(roleClassName),
- requestmapClassName: requestmapClassName]
+ requestmapClassName: requestmapClassName,
+ groupClassName: groupClassName,
+ groupClassProperty: groupClassName ? GrailsNameUtils.getPropertyName(groupClassName) : null]
true
}
@@ -85,6 +90,11 @@ private void createDomains() {
if (requestmapClassName) {
generateFile "$templateDir/Requestmap.groovy.template", "$appDir/domain/${dir}${requestmapClassName}.groovy"
}
+ if (groupClassName) {
+ generateFile "$templateDir/AuthorityGroup.groovy.template", "$appDir/domain/${dir}${groupClassName}.groovy"
+ generateFile "$templateDir/PersonAuthorityGroup.groovy.template", "$appDir/domain/${dir}${userClassName}${groupClassName}.groovy"
+ generateFile "$templateDir/AuthorityGroupAuthority.groovy.template", "$appDir/domain/${dir}${groupClassName}${roleClassName}.groovy"
+ }
}
private void updateConfig() {
@@ -101,6 +111,10 @@ private void updateConfig() {
writer.writeLine "grails.plugin.springsecurity.userLookup.userDomainClassName = '${packageName}.$userClassName'"
writer.writeLine "grails.plugin.springsecurity.userLookup.authorityJoinClassName = '${packageName}.$userClassName$roleClassName'"
writer.writeLine "grails.plugin.springsecurity.authority.className = '${packageName}.$roleClassName'"
+ if (groupClassName) {
+ writer.writeLine "grails.plugin.springsecurity.authority.groupAuthorityNameField = 'authorities'"
+ writer.writeLine "grails.plugin.springsecurity.useRoleGroups = true"
+ }
if (requestmapClassName) {
writer.writeLine "grails.plugin.springsecurity.requestMap.className = '${packageName}.$requestmapClassName'"
writer.writeLine "grails.plugin.springsecurity.securityConfigType = 'Requestmap'"
@@ -122,13 +136,16 @@ private void updateConfig() {
private parseArgs() {
def args = argsMap.params
+ groupClassName = argsMap.groupClassName
+ String groupClassNameMessage = groupClassName ? ", and role/group classes for $groupClassName" : ''
+
if (3 == args.size()) {
- printMessage "Creating User class ${args[1]} and Role class ${args[2]} in package ${args[0]}"
+ printMessage "Creating User class ${args[1]} and Role class ${args[2]}$groupClassNameMessage in package ${args[0]}"
return args
}
if (4 == args.size()) {
- printMessage "Creating User class ${args[1]}, Role class ${args[2]}, and Requestmap class ${args[3]} in package ${args[0]}"
+ printMessage "Creating User class ${args[1]}, Role class ${args[2]}, and Requestmap class ${args[3]}$groupClassNameMessage in package ${args[0]}"
return args
}
View
146 scripts/S2QuickstartGroups.groovy
@@ -1,146 +0,0 @@
-/* Copyright 2006-2013 SpringSource.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import grails.util.GrailsNameUtils
-
-includeTargets << new File(springSecurityCorePluginDir, 'scripts/_S2Common.groovy')
-
-USAGE = """
-Usage: grails s2-quickstart-groups <domain-class-package> <user-class-name> <role-class-name> <group-class-name> [requestmap-class-name]
-
-Creates a user, role and role group class (and optionally a requestmap class) in the specified package
-
-Example: grails s2-quickstart-groups com.yourapp User Role RoleGroup
-Example: grails s2-quickstart-groups com.yourapp Person Authority AuthorityGroup Requestmap
-"""
-
-includeTargets << grailsScript('_GrailsBootstrap')
-
-packageName = ''
-userClassName = ''
-roleClassName = ''
-groupClassName = ''
-requestmapClassName = ''
-
-target(s2QuickstartGroups: 'Creates artifacts for the Spring Security plugin') {
- depends(checkVersion, configureProxy, packageApp, classpath)
-
- if (!configure()) {
- return 1
- }
-
- createDomains()
- updateConfig()
-
- printMessage """
-*******************************************************
-* Created security-related domain classes. Your *
-* grails-app/conf/Config.groovy has been updated with *
-* the class names of the configured domain classes; *
-* please verify that the values are correct. *
-*******************************************************
-"""
-}
-
-private boolean configure() {
-
- def argValues = parseArgs()
- if (!argValues) {
- return false
- }
-
- if (argValues.size() == 5) {
- (packageName, userClassName, roleClassName, groupClassName, requestmapClassName) = argValues
- }
- else {
- (packageName, userClassName, roleClassName, groupClassName) = argValues
- }
-
- templateAttributes = [packageName: packageName,
- userClassName: userClassName,
- userClassProperty: GrailsNameUtils.getPropertyName(userClassName),
- roleClassName: roleClassName,
- roleClassProperty: GrailsNameUtils.getPropertyName(roleClassName),
- groupClassName: groupClassName,
- groupClassProperty: GrailsNameUtils.getPropertyName(groupClassName),
- requestmapClassName: requestmapClassName]
-
- true
-}
-
-private void createDomains() {
-
- String dir = packageToDir(packageName)
- generateFile "$templateDir/Person.groovy.template", "$appDir/domain/${dir}${userClassName}.groovy"
- generateFile "$templateDir/Authority.groovy.template", "$appDir/domain/${dir}${roleClassName}.groovy"
- generateFile "$templateDir/AuthorityGroup.groovy.template", "$appDir/domain/${dir}${groupClassName}.groovy"
- generateFile "$templateDir/PersonAuthorityGroup.groovy.template", "$appDir/domain/${dir}${userClassName}${groupClassName}.groovy"
- generateFile "$templateDir/AuthorityGroupAuthority.groovy.template", "$appDir/domain/${dir}${groupClassName}${roleClassName}.groovy"
- if (requestmapClassName) {
- generateFile "$templateDir/Requestmap.groovy.template", "$appDir/domain/${dir}${requestmapClassName}.groovy"
- }
-}
-
-private void updateConfig() {
-
- def configFile = new File(appDir, 'conf/Config.groovy')
- if (!configFile.exists()) {
- return
- }
-
- configFile.withWriterAppend { BufferedWriter writer ->
- writer.newLine()
- writer.newLine()
- writer.writeLine '// Added by the Spring Security Core plugin:'
- writer.writeLine "grails.plugin.springsecurity.userLookup.userDomainClassName = '${packageName}.$userClassName'"
- writer.writeLine "grails.plugin.springsecurity.userLookup.authorityJoinClassName = '${packageName}.$userClassName$roleClassName'"
- writer.writeLine "grails.plugin.springsecurity.authority.className = '${packageName}.$roleClassName'"
- writer.writeLine "grails.plugin.springsecurity.authority.groupAuthorityNameField = 'authorities'"
- writer.writeLine "grails.plugin.springsecurity.useRoleGroups = true"
- if (requestmapClassName) {
- writer.writeLine "grails.plugin.springsecurity.requestMap.className = '${packageName}.$requestmapClassName'"
- writer.writeLine "grails.plugin.springsecurity.securityConfigType = 'Requestmap'"
- }
- writer.writeLine 'grails.plugin.springsecurity.controllerAnnotations.staticRules = ['
- writer.writeLine "\t'/': ['permitAll'],"
- writer.writeLine "\t'/index': ['permitAll'],"
- writer.writeLine "\t'/index.gsp': ['permitAll'],"
- writer.writeLine "\t'/**/js/**': ['permitAll'],"
- writer.writeLine "\t'/**/css/**': ['permitAll'],"
- writer.writeLine "\t'/**/images/**': ['permitAll'],"
- writer.writeLine "\t'/**/favicon.ico': ['permitAll']"
-
- writer.writeLine ']'
- writer.newLine()
- }
-}
-
-private parseArgs() {
- def args = argsMap.params
-
- if (4 == args.size()) {
- printMessage "Creating User class ${args[1]}, Role class ${args[2]}, and Role Group class ${args[3]} in package ${args[0]}"
- return args
- }
-
- if (5 == args.size()) {
- printMessage "Creating User class ${args[1]}, Role class ${args[2]}, Role Group class ${args[3]} and Requestmap class ${args[3]} in package ${args[0]}"
- return args
- }
-
- errorMessage USAGE
- null
-}
-
-setDefaultTarget 's2QuickstartGroups'
View
15 scripts/_Install.groovy
@@ -1,10 +1,9 @@
println '''
-**********************************************************
-* You've installed the Spring Security Core plugin. *
-* *
-* Next run the "s2-quickstart" or "s2-quickstart-groups" *
-* script to initialize Spring Security and create your *
-* domain classes. *
-* *
-**********************************************************
+*******************************************************
+* You've installed the Spring Security Core plugin. *
+* *
+* Next run the "s2-quickstart" script to initialize *
+* Spring Security and create your domain classes. *
+* *
+*******************************************************
'''
View
2  src/docs/guide/domainClasses.gdoc
@@ -4,4 +4,4 @@ To use the standard user lookup you'll need at a minimum a 'person' and an 'auth
To use the user/group lookup you'll also need a 'group' domain class. If you are using the recommended approach for mapping many-to-many relationship between 'person' and 'group' and between 'group' and 'authority' you'll need a domain class for each to map the join tables. You can still additionally use 'requestmap' with this approach.
-The [s2-quickstart|Scripts] and [s2-quickstart-groups|Scripts] scripts create initial domain classes for you. You specify the package and class names, and it creates the corresponding domain classes. After that you can customize them as you like. You can add unlimited fields, methods, and so on, as long as the core security-related functionality remains.
+The [s2-quickstart|Scripts] script creates initial domain classes for you. You specify the package and class names, and it creates the corresponding domain classes. After that you can customize them as you like. You can add unlimited fields, methods, and so on, as long as the core security-related functionality remains.
View
20 src/docs/ref/Scripts/s2-quickstart-groups.gdoc
@@ -1,20 +0,0 @@
-h1. s2-quickstart-groups
-
-h2. Purpose
-
-Creates a user, group, role class (and optionally a requestmap class) in the specified package. It will also create the join classes for a many to many relationship between user and group as well as group and role. The general format is:
-
-bc.
-grails s2-quickstart-groups DOMAIN_CLASS_PACKAGE USER_CLASS_NAME ROLE_CLASS_NAME GROUP_CLASS_NAME \[REQUESTMAP_CLASS_NAME\]
-
-h2. Examples
-
-bc.
-grails s2-quickstart-groups com.yourapp User Role Group
-
-bc.
-grails s2-quickstart-groups com.yourapp Person Authority Group Requestmap
-
-h2. Description
-
-* creates domain classes in @grails-app/domain@
View
10 src/docs/ref/Scripts/s2-quickstart.gdoc
@@ -2,10 +2,13 @@ h1. s2-quickstart
h2. Purpose
-Creates a user and role class (and optionally a requestmap class) in the specified package. The general format is:
+Creates a user and role class (and optionally a requestmap class) in the specified package.
+If you specify a role-group name with the groupClassName argument, role/group classes will also be generated.
+
+The general format is:
bc.
-grails s2-quickstart DOMAIN_CLASS_PACKAGE USER_CLASS_NAME ROLE_CLASS_NAME \[REQUESTMAP_CLASS_NAME\]
+grails s2-quickstart DOMAIN_CLASS_PACKAGE USER_CLASS_NAME ROLE_CLASS_NAME \[REQUESTMAP_CLASS_NAME\] \[\-\-groupClassName=GROUP_CLASS_NAME\]
h2. Examples
@@ -13,6 +16,9 @@ bc.
grails s2-quickstart com.yourapp User Role
bc.
+grails s2-quickstart com.yourapp User Role --groupClassName=RoleGroup
+
+bc.
grails s2-quickstart com.yourapp Person Authority Requestmap
h2. Description

1 comment on commit 78f3e2c

@th3morg

This is definitely a better approach than where I went with it. Thanks.

Please sign in to comment.
Something went wrong with that request. Please try again.