source: branches/TaskRewrite/src/plugins/acegi-0.5.1/scripts/CreateAuthDomains.groovy @ 58

Last change on this file since 58 was 58, checked in by gav, 15 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: 3.3 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 * Create/Copy Domains, auth.gsp, Controllers for security plugin.
18 *
19 * @author Tsuyoshi Yamamoto
20 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a>
21 */
22
23includeTargets << new File("$acegiPluginDir/scripts/_SecurityTargets.groovy")
24
25target('default': 'Creates Domain classes for Spring Security plugin') {
26        parseArgs()
27        createDomains()
28        copyViewAndControllers()
29}
30
31private void parseArgs() {
32        args = args ? args.split('\n') : []
33        switch (args.size()) {
34                case 0:
35                        println 'Creating domain classes with default names'
36                        break
37                case 3:
38                        splitPersonClassName args[0]
39                        splitAuthorityClassName args[1]
40                        splitRequestmapClassName args[2]
41                        println "Login user domain class: ${args[0]}"
42                        println "Authority domain class: ${args[1]}"
43                        println "Requestmap domain class: ${args[2]}"
44                        break
45                default:
46                        usage()
47                        break
48        }
49}
50
51private void usage() {
52        println 'usage: grails create-auth-domains <person class name> <authority class name> <request map class name>'
53        System.exit(1)
54}
55
56private void createDomains() {
57
58        // create Person domain class
59        generateFile "$templateDir/_Person.groovy",
60                "$appDir/domain/${packageToDir(personClassPackage)}${personClassName}.groovy"
61
62        // create Authority domain class
63        generateFile "$templateDir/_Authority.groovy",
64                "$appDir/domain/${packageToDir(authorityClassPackage)}${authorityClassName}.groovy"
65
66        // create Requestmap domain class
67        generateFile "$templateDir/_Requestmap.groovy",
68                "$appDir/domain/${packageToDir(requestmapClassPackage)}${requestmapClassName}.groovy"
69
70        // create SecurityConfig
71        generateFile "$templateDir/_SecurityConfig.groovy", "$appDir/conf/SecurityConfig.groovy"
72}
73
74private String packageToDir(pkg) {
75        String dir = ''
76        if (pkg) {
77                dir = pkg.replaceAll('\\.', '/') + '/'
78        }
79
80        return dir
81}
82
83private void copyViewAndControllers() {
84
85        // copy login.gsp and Login/Logout Controller example.
86        println 'copying login.gsp and Login/Logout Controller example. '
87        Ant.mkdir dir: "$appDir/views/login"
88        copyFile "$templateDir/views/login/auth.gsp", "$appDir/views/login/auth.gsp"
89        copyFile "$templateDir/views/login/openIdAuth.gsp", "$appDir/views/login/openIdAuth.gsp"
90        copyFile "$templateDir/views/login/denied.gsp", "$appDir/views/login/denied.gsp"
91        copyFile "$templateDir/controllers/LoginController.groovy", "$appDir/controllers/LoginController.groovy"
92        copyFile "$templateDir/controllers/LogoutController.groovy", "$appDir/controllers/LogoutController.groovy"
93
94        // log4j.logger.org.springframework.security='off,stdout'
95        def configFile = new File("$appDir/conf/Config.groovy")
96        if (configFile.exists()) {
97                configFile.append("\n\n//log4j.logger.org.springframework.security='off,stdout'")
98        }
99}
Note: See TracBrowser for help on using the repository browser.