source: branches/TaskRewrite/src/plugins/acegi-0.5.1/scripts/_SecurityTargets.groovy @ 59

Last change on this file since 59 was 58, checked in by gav, 16 years ago

Configure BootStrap? with latest concepts.
Install and setup Acegi plugin with custom views.
Test Fixture plugin in a test app but couldn't get it to work with Acegi encodePassword() so gave up.

File size: 4.5 KB
Line 
1/* Copyright 2006-2009 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/**
17 * Shared methods/closures and initialization.
18 *
19 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a>
20 */
21
22import groovy.text.SimpleTemplateEngine
23
24grailsHome = Ant.project.properties.'environment.GRAILS_HOME'
25includeTargets << new File("$grailsHome/scripts/Init.groovy")
26
27personClassName = 'Person'
28personClassPackage = ''
29authorityClassName = 'Authority'
30authorityClassPackage = ''
31requestmapClassName = 'Requestmap'
32requestmapClassPackage = ''
33templateDir = "$acegiPluginDir/src/templates"
34appDir = "$basedir/grails-app"
35
36overwrite = true
37
38generateFile = { String templatePath, String outputPath ->
39
40        File templateFile = new File(templatePath)
41        if (!templateFile.exists()) {
42                println "$templatePath doesn't exist"
43                return
44        }
45
46        File outFile = new File(outputPath)
47        if (outFile.exists() && !overwrite) {
48            println "file *not* generated: $outFile.absolutePath"
49                return
50        }
51
52        // in case it's in a package, create dirs
53        Ant.mkdir dir: outFile.parentFile
54
55        def binding = [personClassName: personClassName,
56                       personClassPackage: '',
57                       personClass: personClassName, personClassImport: '',
58                       authorityClassName: authorityClassName,
59                       authorityClassPackage: '',
60                       authorityClass: authorityClassName, authorityClassImport: '',
61                       requestmapClassName: requestmapClassName,
62                       requestmapClassPackage: '',
63                       requestmapClass: requestmapClassName, requestmapClassImport: '']
64
65        if (personClassPackage) {
66                binding.personClass = "${personClassPackage}.$personClassName"
67                binding.personClassImport = "import $binding.personClass"
68                binding.personClassPackage = "package $personClassPackage"
69        }
70        if (authorityClassPackage) {
71                binding.authorityClass = "${authorityClassPackage}.$authorityClassName"
72                binding.authorityClassImport = "import $binding.authorityClass"
73                binding.authorityClassPackage = "package $authorityClassPackage"
74        }
75        if (requestmapClassPackage) {
76                binding.requestmapClass = "${requestmapClassPackage}.$requestmapClassName"
77                binding.requestmapClassImport = "import $binding.requestmapClass"
78                binding.requestmapClassPackage = "package $requestmapClassPackage"
79        }
80
81        outFile.withWriter { writer ->
82                def template = new SimpleTemplateEngine().createTemplate(templateFile.text)
83                template.make(binding).writeTo(writer)
84        }
85
86        println "file generated at $outFile.absolutePath"
87}
88
89copyFile = { String from, String to ->
90        Ant.copy(file: from, tofile: to, overwrite: overwrite)
91}
92
93loadConfig = {
94        GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader())
95        Class clazz = loader.parseClass(new File("$basedir/grails-app/conf/SecurityConfig.groovy"))
96        def securityConfig = new ConfigSlurper().parse(clazz)
97        splitPersonClassName securityConfig.security.loginUserDomainClass
98        splitAuthorityClassName securityConfig.security.authorityDomainClass
99        splitRequestmapClassName securityConfig.security.requestMapClass
100        println "Login user domain class: $securityConfig.security.loginUserDomainClass"
101        println "Authority domain class: $securityConfig.security.authorityDomainClass"
102        println "Request Map domain class: $securityConfig.security.requestMapClass"
103}
104
105splitClassName = { name ->
106        int index = name.lastIndexOf('.')
107        return index == -1 ? [name, ''] : [name.substring(index + 1), name.substring(0, index)]
108}
109
110splitPersonClassName = { name ->
111        def packageAndClass = splitClassName(name)
112        personClassName = packageAndClass[0]
113        personClassPackage = packageAndClass[1]
114}
115
116splitAuthorityClassName = { name ->
117        def packageAndClass = splitClassName(name)
118        authorityClassName = packageAndClass[0]
119        authorityClassPackage = packageAndClass[1]
120}
121
122splitRequestmapClassName = { name ->
123        def packageAndClass = splitClassName(name)
124        requestmapClassName = packageAndClass[0]
125        requestmapClassPackage = packageAndClass[1]
126}
Note: See TracBrowser for help on using the repository browser.