Last change
on this file since 494 was
396,
checked in by gav, 15 years ago
|
Add a random password generator to AuthService.
|
File size:
1.3 KB
|
Rev | Line | |
---|
[198] | 1 | /** |
---|
| 2 | * Provides a service class with some methods that integrate the Person domain class and Acegi security. |
---|
[182] | 3 | * |
---|
| 4 | */ |
---|
[291] | 5 | class AuthService { |
---|
[182] | 6 | |
---|
| 7 | boolean transactional = false |
---|
| 8 | |
---|
| 9 | def authenticateService |
---|
| 10 | |
---|
[198] | 11 | /** |
---|
| 12 | * Get the current user in a safe way to avoid a null userDomain. |
---|
| 13 | * @returns The current user or the 'system' person (Person #1) if userDomain() is not active. |
---|
| 14 | */ |
---|
[216] | 15 | def getCurrentUser() { |
---|
[182] | 16 | if(authenticateService.userDomain()) { |
---|
| 17 | return Person.get(authenticateService.userDomain().id) |
---|
| 18 | } |
---|
| 19 | else { |
---|
[198] | 20 | log.warn "userDomain not active, attempting to return Person #1." |
---|
[182] | 21 | return Person.get(1) |
---|
| 22 | } |
---|
| 23 | } |
---|
| 24 | |
---|
[198] | 25 | /** |
---|
| 26 | * Convenience wrapper around authenticateService.encodePassword(). |
---|
| 27 | * @param passClearText The clear text password to encode. |
---|
| 28 | * @returns The encoded password. |
---|
| 29 | */ |
---|
[182] | 30 | def encodePassword(passClearText) { |
---|
| 31 | authenticateService.encodePassword(passClearText) |
---|
| 32 | } |
---|
| 33 | |
---|
[396] | 34 | /** |
---|
| 35 | * Generate a random password. |
---|
| 36 | * @returns The generated password. |
---|
| 37 | */ |
---|
| 38 | def getRandomPassword() { |
---|
| 39 | def passwd = "" |
---|
| 40 | def pool = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" |
---|
| 41 | def rand = new Random(System.currentTimeMillis()) |
---|
| 42 | |
---|
| 43 | for(i in 0..10) |
---|
| 44 | passwd += pool[rand.nextInt(pool.length())] |
---|
| 45 | |
---|
| 46 | return passwd |
---|
| 47 | } |
---|
| 48 | |
---|
[182] | 49 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.