Skip to content

Commit 16484f4

Browse files
committed
converted the scripts from Gant to the new Grails 3 format
1 parent da06fa4 commit 16484f4

10 files changed

+262
-490
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright 2006-2015 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import grails.codegen.model.Model
17+
18+
description 'Creates a persistent token domain class for the Spring Security Core plugin', {
19+
usage '''
20+
grails s2-create-persistent-token [DOMAIN CLASS NAME]
21+
22+
Example: grails s2-create-persistent-token com.yourapp.PersistentLogin
23+
'''
24+
25+
argument name: 'Domain class name', description: 'The domain class full name with package'
26+
}
27+
28+
String fullClassName = args[0]
29+
Model model = model(fullClassName)
30+
31+
addStatus "\nCreating persistent token class $fullClassName"
32+
33+
render template: template('PersistentLogin.groovy.template'),
34+
destination: file("grails-app/domain/$model.packagePath/${model.simpleName}.groovy"),
35+
model: model, overwrite: false
36+
37+
file('grails-app/conf/application.groovy').withWriterAppend { BufferedWriter writer ->
38+
writer.newLine()
39+
writer.writeLine 'grails.plugin.springsecurity.rememberMe.persistent = true'
40+
writer.writeLine "grails.plugin.springsecurity.rememberMe.persistentToken.domainClassName = '$fullClassName'"
41+
writer.newLine()
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Copyright 2015 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import grails.codegen.model.Model
17+
18+
/**
19+
* @author fpape
20+
* @author <a href='mailto:[email protected]'>Burt Beckwith</a>
21+
*/
22+
23+
description 'Creates a domain class for a persistent role hierarchy for the Spring Security Core plugin', {
24+
usage '''
25+
grails s2-create-role-hierarchy-entry [DOMAIN CLASS NAME]
26+
27+
Example: grails s2-create-role-hierarchy-entry com.yourapp.RoleHierarchyEntry
28+
'''
29+
30+
argument name: 'Domain class name', description: 'The domain class full name with package'
31+
}
32+
33+
String fullClassName = args[0]
34+
Model model = model(fullClassName)
35+
36+
addStatus "\nCreating role hierarchy entry class $fullClassName"
37+
38+
render template: template('RoleHierarchyEntry.groovy.template'),
39+
destination: file("grails-app/domain/$model.packagePath/${model.simpleName}.groovy"),
40+
model: model, overwrite: false
41+
42+
file('grails-app/conf/application.groovy').withWriterAppend { BufferedWriter writer ->
43+
writer.newLine()
44+
writer.writeLine "grails.plugin.springsecurity.roleHierarchyEntryClassName = '$fullClassName'"
45+
writer.newLine()
46+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/* Copyright 2006-2015 the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import grails.codegen.model.Model
17+
import groovy.transform.Field
18+
19+
@Field String usageMessage = '''
20+
grails s2-quickstart <domain-class-package> <user-class-name> <role-class-name> [requestmap-class-name] [--groupClassName=group-class-name]
21+
or grails s2-quickstart --uiOnly
22+
23+
Example: grails s2-quickstart com.yourapp User Role
24+
Example: grails s2-quickstart com.yourapp User Role --groupClassName=RoleGroup
25+
Example: grails s2-quickstart com.yourapp Person Authority Requestmap
26+
Example: grails s2-quickstart --uiOnly
27+
'''
28+
29+
@Field Map templateAttributes
30+
@Field boolean uiOnly
31+
32+
description 'Creates domain classes and updates config settings for the Spring Security plugin', {
33+
34+
usage usageMessage
35+
36+
argument name: 'Domain class package', description: 'The package to use for the domain classes', required: false
37+
argument name: 'User class name', description: 'The name of the User/Person class', required: false
38+
argument name: 'Role class name', description: 'The name of the Role class', required: false
39+
argument name: 'Requestmap class name', description: 'The name of the Requestmap class', required: false
40+
41+
flag name: 'groupClassName', description: 'If specified, role/group classes will also be generated using the flag value as the role-group name'
42+
flag name: 'uiOnly', description: 'If specified, no domain classes are created but the plugin settings are initialized (useful with LDAP, Mock, Shibboleth, etc.)'
43+
}
44+
45+
Model userModel
46+
Model roleModel
47+
Model requestmapModel
48+
Model groupModel
49+
uiOnly = flag('uiOnly')
50+
if (uiOnly) {
51+
addStatus '\nConfiguring Spring Security; not generating domain classes'
52+
}
53+
else {
54+
55+
if (args.size() < 3) {
56+
error 'Usage:' + usageMessage
57+
return false
58+
}
59+
60+
String packageName = args[0]
61+
String groupClassName = flag('groupClassName')
62+
String groupClassNameMessage = ''
63+
if (groupClassName) {
64+
groupModel = model(packageName + '.' + groupClassName)
65+
groupClassNameMessage = ", and role/group classes for '" + groupModel.simpleName + "'"
66+
}
67+
68+
userModel = model(packageName + '.' + args[1])
69+
roleModel = model(packageName + '.' + args[2])
70+
71+
String message = "Creating User class '" + userModel.simpleName + "'"
72+
if (4 == args.size()) {
73+
requestmapModel = model(packageName + '.' + args[3])
74+
message += ", Role class '" + roleModel.simpleName + "', and Requestmap class '" + requestmapModel.simpleName + "'" + groupClassNameMessage
75+
}
76+
else {
77+
message += " and Role class '" + roleModel.simpleName + "'" + groupClassNameMessage
78+
}
79+
message += " in package '" + packageName + "'"
80+
addStatus message
81+
82+
templateAttributes = [
83+
packageName: userModel.packageName,
84+
userClassName: userModel.simpleName,
85+
userClassProperty: userModel.modelName,
86+
roleClassName: roleModel.simpleName,
87+
roleClassProperty: roleModel.modelName,
88+
requestmapClassName: requestmapModel?.simpleName,
89+
groupClassName: groupModel?.simpleName,
90+
groupClassProperty: groupModel?.modelName]
91+
92+
createDomains userModel, roleModel, requestmapModel, groupModel
93+
}
94+
95+
updateConfig userModel?.simpleName, roleModel?.simpleName, requestmapModel?.simpleName, userModel?.packageName, groupModel != null
96+
97+
if (uiOnly) {
98+
addStatus '''
99+
************************************************************
100+
* Your grails-app/conf/application.groovy has been updated *
101+
* with security settings; please verify that the *
102+
* values are correct. *
103+
************************************************************
104+
'''
105+
}
106+
else {
107+
addStatus '''
108+
************************************************************
109+
* Created security-related domain classes. Your *
110+
* grails-app/conf/application.groovy has been updated with *
111+
* the class names of the configured domain classes; *
112+
* please verify that the values are correct. *
113+
************************************************************
114+
'''
115+
}
116+
117+
private void createDomains(Model userModel, Model roleModel, Model requestmapModel, Model groupModel) {
118+
119+
generateFile 'Person', userModel.packagePath, userModel.simpleName
120+
generateFile 'Authority', roleModel.packagePath, roleModel.simpleName
121+
generateFile 'PersonAuthority', roleModel.packagePath, userModel.simpleName + roleModel.simpleName
122+
123+
if (requestmapModel) {
124+
generateFile 'Requestmap', requestmapModel.packagePath, requestmapModel.simpleName
125+
}
126+
127+
if (groupModel) {
128+
generateFile 'AuthorityGroup', groupModel.packagePath, groupModel.simpleName
129+
generateFile 'PersonAuthorityGroup', groupModel.packagePath, userModel.simpleName + groupModel.simpleName
130+
generateFile 'AuthorityGroupAuthority', groupModel.packagePath, groupModel.simpleName + roleModel.simpleName
131+
}
132+
}
133+
134+
private void updateConfig(String userClassName, String roleClassName, String requestmapClassName, String packageName, boolean useRoleGroups) {
135+
136+
file('grails-app/conf/application.groovy').withWriterAppend { BufferedWriter writer ->
137+
writer.newLine()
138+
writer.newLine()
139+
writer.writeLine '// Added by the Spring Security Core plugin:'
140+
if (!uiOnly) {
141+
writer.writeLine "grails.plugin.springsecurity.userLookup.userDomainClassName = '${packageName}.$userClassName'"
142+
writer.writeLine "grails.plugin.springsecurity.userLookup.authorityJoinClassName = '${packageName}.$userClassName$roleClassName'"
143+
writer.writeLine "grails.plugin.springsecurity.authority.className = '${packageName}.$roleClassName'"
144+
}
145+
if (useRoleGroups) {
146+
writer.writeLine "grails.plugin.springsecurity.authority.groupAuthorityNameField = 'authorities'"
147+
writer.writeLine 'grails.plugin.springsecurity.useRoleGroups = true'
148+
}
149+
if (requestmapClassName) {
150+
writer.writeLine "grails.plugin.springsecurity.requestMap.className = '${packageName}.$requestmapClassName'"
151+
writer.writeLine "grails.plugin.springsecurity.securityConfigType = 'Requestmap'"
152+
}
153+
writer.writeLine 'grails.plugin.springsecurity.controllerAnnotations.staticRules = ['
154+
writer.writeLine "\t'/': ['permitAll'],"
155+
writer.writeLine "\t'/index': ['permitAll'],"
156+
writer.writeLine "\t'/index.gsp': ['permitAll'],"
157+
writer.writeLine "\t'/assets/**': ['permitAll'],"
158+
writer.writeLine "\t'/**/js/**': ['permitAll'],"
159+
writer.writeLine "\t'/**/css/**': ['permitAll'],"
160+
writer.writeLine "\t'/**/images/**': ['permitAll'],"
161+
writer.writeLine "\t'/**/favicon.ico': ['permitAll']"
162+
163+
writer.writeLine ']'
164+
writer.newLine()
165+
}
166+
}
167+
168+
private void generateFile(String templateName, String packagePath, String className) {
169+
render template(templateName + '.groovy.template'),
170+
file("grails-app/domain/$packagePath/${className}.groovy"),
171+
templateAttributes, false
172+
}

src/main/scripts_old/S2CreatePersistentToken.groovy

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)