source: trunk/grails-app/services/dbnp/user/AuthService.groovy @ 898

Last change on this file since 898 was 898, checked in by keesvb, 10 years ago

update authentication service for REST services to also accept SHA256 hashed passwords

File size: 1.1 KB
Line 
1/**
2 * AuthService Service
3 *
4 * Checks whether a user is logged in (see also nl.metabolomicscentre.dsp.aaa.AuthService)
5 *
6 * @author  keesvb
7 * @since       20100823
8 * @package     dbnp.user
9 *
10 * Revision information:
11 * $Rev$
12 * $Author$
13 * $Date$
14 */
15package dbnp.user
16
17// Shiro
18import org.apache.shiro.SecurityUtils
19import org.apache.shiro.authc.UsernamePasswordToken
20
21
22class AuthService {
23
24        static transactional = true
25
26        def authUser(username = "", password = "") {
27                println "authenticating ${username} with password ${password}"
28                if (!username || !password){
29                        return false // required information missing to authenticate
30                }
31
32                def currentUser = SecurityUtils.getSubject()
33                def token = new UsernamePasswordToken(username, password);
34
35                try {
36                        currentUser.login( token );
37                } catch ( Exception e ) {
38                        def foundUser = User.findByUsernameAndPasswordHash(username, password)
39                        if (foundUser) {
40                                return foundUser
41                        }
42                        else {
43                                return false //username wasn't in the system, show them an error message?
44                        }
45                }
46
47                //return UserBase.get(currentUser.getPrincipal())
48                return dbnp.user.User.get(currentUser.getPrincipal())
49        }
50}
Note: See TracBrowser for help on using the repository browser.