Last change
on this file since 1364 was
1364,
checked in by work@…, 11 years ago
|
- and another one for issue #219, moved authentication to the environment specific configuration files
|
File size:
1.4 KB
|
Line | |
---|
1 | import dbnp.authentication.* |
---|
2 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
3 | |
---|
4 | /** |
---|
5 | * @Author Jeroen Wesbeek <work@osx.eu> |
---|
6 | * @Since 20101111 |
---|
7 | * |
---|
8 | * Revision information: |
---|
9 | * $Rev$ |
---|
10 | * $Author$ |
---|
11 | * $Date$ |
---|
12 | */ |
---|
13 | class BootStrapAuthentication { |
---|
14 | /** |
---|
15 | * set up the initial roles and users if required |
---|
16 | * @visibility public |
---|
17 | * @void |
---|
18 | */ |
---|
19 | public static void initDefaultAuthentication(springSecurityService) { |
---|
20 | "setting up default authentication".grom() |
---|
21 | |
---|
22 | // user work variable |
---|
23 | def user=null |
---|
24 | |
---|
25 | // get configuration |
---|
26 | def config = ConfigurationHolder.config |
---|
27 | |
---|
28 | // create the admin role |
---|
29 | def adminRole = SecRole.findByAuthority('ROLE_ADMIN') ?: new SecRole(authority: 'ROLE_ADMIN').save() |
---|
30 | |
---|
31 | // iterate through default users, see |
---|
32 | // - grails-app/conf/config-environment.properties |
---|
33 | // - ~/.grails-config/environment-gscf.properties |
---|
34 | config.authentication.users.each { key, values -> |
---|
35 | // make sure we do not add duplicate users |
---|
36 | if (!SecUser.findAllByUsername(values.username)) { |
---|
37 | // create user instance |
---|
38 | user = new SecUser( |
---|
39 | username:values.username, |
---|
40 | password:springSecurityService.encodePassword( values.password , values.username ), |
---|
41 | email:values.email, |
---|
42 | userConfirmed: true, |
---|
43 | adminConfirmed: true |
---|
44 | ).save(failOnError: true) |
---|
45 | |
---|
46 | // is this user an administrator? |
---|
47 | if (values.administrator == 'true') { |
---|
48 | SecUserSecRole.create(user, adminRole, true) |
---|
49 | } |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.