source: trunk/grails-app/services/dbnp/authentication/AuthenticationService.groovy @ 1939

Last change on this file since 1939 was 1939, checked in by robert@…, 12 years ago

Updated module notification so that it also sends authentication to modules.

  • Property svn:keywords set to Rev Author Date
File size: 2.0 KB
Line 
1/**
2 * AuthenticationService
3 *
4 * Is used for keeping track of the logged in user
5 *
6 * @author      robert@isdat.nl (Robert Horlings
7 * @since       20101021
8 * @package     dbnp.authentication
9 *
10 * Revision information:
11 * $Rev: 1939 $
12 * $Author: robert@isdat.nl $
13 * $Date: 2011-06-24 10:56:22 +0000 (vr, 24 jun 2011) $
14 */
15package dbnp.authentication
16
17import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser
18
19class AuthenticationService {
20    def springSecurityService
21        def remoteAuthenticationService
22
23    static transactional = true
24
25    public boolean isLoggedIn() {
26        return springSecurityService.isLoggedIn();
27    }
28
29    public SecUser getLoggedInUser() {
30      def principal = springSecurityService.getPrincipal()
31
32      // If the user is logged in, the principal should be a GrailsUser object.
33      // If the user is not logged in, the principal is the 'anonymous username'
34      // i.e. a string
35      if( principal instanceof GrailsUser ) {
36          return SecUser.findByUsername( principal.username );
37      }
38
39      return null;
40    }
41
42    /**
43     * Logs a user in for a remote session
44     */
45    public boolean logInRemotely( String consumer, String token, SecUser user ) {
46                remoteAuthenticationService.logInRemotely( consumer, token, user );
47    }
48   
49    public boolean logOffRemotely( String consumer, String token ) {
50                remoteAuthenticationService.logOffRemotely( consumer, token );
51    }
52
53    /**
54     * Checks whether a user is logged in from a remote consumer with the
55     * given token
56     */
57    public boolean isRemotelyLoggedIn( String consumer, String token ) {
58                remoteAuthenticationService.isRemotelyLoggedIn( consumer, token );
59    }
60
61    /**
62     * Returns the user that is logged in remotely
63     */
64    public SecUser getRemotelyLoggedInUser( String consumer, String token ) {
65                remoteAuthenticationService.getRemotelyLoggedInUser( consumer, token );
66    }
67       
68        /**
69         * Remove all remote sessions for a user
70         * @param user
71         */
72        public void deleteRemoteSessions( SecUser user ) {
73                remoteAuthenticationService.deleteRemoteSessions( user );
74        }
75}
Note: See TracBrowser for help on using the repository browser.