|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.concurrent; |
|
17 |
| |
|
18 |
| import org.acegisecurity.Authentication; |
|
19 |
| import org.acegisecurity.ui.WebAuthenticationDetails; |
|
20 |
| import org.acegisecurity.userdetails.UserDetails; |
|
21 |
| |
|
22 |
| import org.springframework.util.Assert; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public class SessionRegistryUtils { |
|
32 |
| |
|
33 |
| |
|
34 |
7
| public static Object obtainPrincipalFromAuthentication(Authentication auth) {
|
|
35 |
7
| Assert.notNull(auth, "Authentication required");
|
|
36 |
7
| Assert.notNull(auth.getPrincipal(),
|
|
37 |
| "Authentication.getPrincipal() required"); |
|
38 |
| |
|
39 |
7
| if (auth.getPrincipal() instanceof UserDetails) {
|
|
40 |
0
| return ((UserDetails) auth.getPrincipal()).getUsername();
|
|
41 |
| } else { |
|
42 |
7
| return auth.getPrincipal();
|
|
43 |
| } |
|
44 |
| } |
|
45 |
| |
|
46 |
7
| public static String obtainSessionIdFromAuthentication(Authentication auth) {
|
|
47 |
7
| Assert.notNull(auth, "Authentication required");
|
|
48 |
7
| Assert.notNull(auth.getDetails(), "Authentication.getDetails() required");
|
|
49 |
7
| Assert.isInstanceOf(WebAuthenticationDetails.class, auth.getDetails());
|
|
50 |
| |
|
51 |
7
| String sessionId = ((WebAuthenticationDetails) auth.getDetails())
|
|
52 |
| .getSessionId(); |
|
53 |
7
| Assert.hasText(sessionId, "WebAuthenticationDetails missing SessionId");
|
|
54 |
| |
|
55 |
7
| return sessionId;
|
|
56 |
| } |
|
57 |
| } |