1 | package dbnp.authentication |
---|
2 | |
---|
3 | import org.codehaus.groovy.grails.commons.ConfigurationHolder |
---|
4 | import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils |
---|
5 | |
---|
6 | class LogoutController { |
---|
7 | def authenticationService |
---|
8 | |
---|
9 | /** |
---|
10 | * Index action. Redirects to the Spring security logout uri. |
---|
11 | */ |
---|
12 | def index = { |
---|
13 | if( params[ SpringSecurityUtils.securityConfig.successHandler.targetUrlParameter ] ) { |
---|
14 | redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl + "?" + SpringSecurityUtils.securityConfig.successHandler.targetUrlParameter + '=' + params[ SpringSecurityUtils.securityConfig.successHandler.targetUrlParameter ] // '/j_spring_security_logout' |
---|
15 | } else { |
---|
16 | redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout' |
---|
17 | } |
---|
18 | |
---|
19 | // Remove all remote sessions for this user. |
---|
20 | def user = authenticationService.getLoggedInUser(); |
---|
21 | if( user ) |
---|
22 | authenticationService.deleteRemoteSessions( user ); |
---|
23 | |
---|
24 | // Remove all queries from session |
---|
25 | session.queries = []; |
---|
26 | } |
---|
27 | |
---|
28 | def remote = { |
---|
29 | if( params.consumer || params.token ) { |
---|
30 | // Log out the remote user |
---|
31 | authenticationService.logOffRemotely( params.consumer, params.token ) |
---|
32 | } |
---|
33 | |
---|
34 | def returnUrl; |
---|
35 | |
---|
36 | // If a returnUrl is given, use it for redirect |
---|
37 | if( params.returnUrl ) { |
---|
38 | returnUrl = params.returnUrl; |
---|
39 | } else { |
---|
40 | // Return to baseURL |
---|
41 | returnUrl = ConfigurationHolder.config.grails.serverURL |
---|
42 | } |
---|
43 | |
---|
44 | // Try to rest the redirect url |
---|
45 | if( params[ SpringSecurityUtils.securityConfig.successHandler.targetUrlParameter ] ) { |
---|
46 | redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl + "?spring-security-redirect=" + returnUrl?.encodeAsURL() + "&" + SpringSecurityUtils.securityConfig.successHandler.targetUrlParameter + '=' + params[ SpringSecurityUtils.securityConfig.successHandler.targetUrlParameter ] // '/j_spring_security_logout' |
---|
47 | } else { |
---|
48 | redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl + "?spring-security-redirect=" + returnUrl?.encodeAsURL() // '/j_spring_security_logout' |
---|
49 | } |
---|
50 | |
---|
51 | // Remove all remote sessions for this user. |
---|
52 | def user = authenticationService.getLoggedInUser(); |
---|
53 | if( user ) |
---|
54 | authenticationService.deleteRemoteSessions( user ); |
---|
55 | |
---|
56 | // Remove all queries from session |
---|
57 | session.queries = []; |
---|
58 | } |
---|
59 | } |
---|