|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.providers.rememberme; |
|
17 |
| |
|
18 |
| import org.acegisecurity.GrantedAuthority; |
|
19 |
| import org.acegisecurity.providers.AbstractAuthenticationToken; |
|
20 |
| |
|
21 |
| import java.io.Serializable; |
|
22 |
| |
|
23 |
| import org.springframework.util.Assert; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| public class RememberMeAuthenticationToken extends AbstractAuthenticationToken |
|
39 |
| implements Serializable { |
|
40 |
| |
|
41 |
| |
|
42 |
| private Object principal; |
|
43 |
| private GrantedAuthority[] authorities; |
|
44 |
| private int keyHash; |
|
45 |
| private boolean authenticated; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
21
| public RememberMeAuthenticationToken(String key, Object principal,
|
|
59 |
| GrantedAuthority[] authorities) { |
|
60 |
21
| if ((key == null) || ("".equals(key)) || (principal == null)
|
|
61 |
| || "".equals(principal) || (authorities == null) |
|
62 |
| || (authorities.length == 0)) { |
|
63 |
4
| throw new IllegalArgumentException(
|
|
64 |
| "Cannot pass null or empty values to constructor"); |
|
65 |
| } |
|
66 |
| |
|
67 |
17
| for (int i = 0; i < authorities.length; i++) {
|
|
68 |
28
| Assert.notNull(authorities[i], "Granted authority element "
|
|
69 |
| + i |
|
70 |
| + " is null - GrantedAuthority[] cannot contain any null elements"); |
|
71 |
| } |
|
72 |
| |
|
73 |
16
| this.keyHash = key.hashCode();
|
|
74 |
16
| this.principal = principal;
|
|
75 |
16
| this.authorities = authorities;
|
|
76 |
16
| this.authenticated = true;
|
|
77 |
| } |
|
78 |
| |
|
79 |
1
| protected RememberMeAuthenticationToken() {
|
|
80 |
1
| throw new IllegalArgumentException("Cannot use default constructor");
|
|
81 |
| } |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
1
| public void setAuthenticated(boolean isAuthenticated) {
|
|
86 |
1
| this.authenticated = isAuthenticated;
|
|
87 |
| } |
|
88 |
| |
|
89 |
9
| public boolean isAuthenticated() {
|
|
90 |
9
| return this.authenticated;
|
|
91 |
| } |
|
92 |
| |
|
93 |
58
| public GrantedAuthority[] getAuthorities() {
|
|
94 |
58
| return this.authorities;
|
|
95 |
| } |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
8
| public Object getCredentials() {
|
|
103 |
8
| return "";
|
|
104 |
| } |
|
105 |
| |
|
106 |
9
| public int getKeyHash() {
|
|
107 |
9
| return this.keyHash;
|
|
108 |
| } |
|
109 |
| |
|
110 |
11
| public Object getPrincipal() {
|
|
111 |
11
| return this.principal;
|
|
112 |
| } |
|
113 |
| |
|
114 |
5
| public boolean equals(Object obj) {
|
|
115 |
5
| if (!super.equals(obj)) {
|
|
116 |
2
| return false;
|
|
117 |
| } |
|
118 |
| |
|
119 |
3
| if (obj instanceof RememberMeAuthenticationToken) {
|
|
120 |
3
| RememberMeAuthenticationToken test = (RememberMeAuthenticationToken) obj;
|
|
121 |
| |
|
122 |
3
| if (this.getKeyHash() != test.getKeyHash()) {
|
|
123 |
1
| return false;
|
|
124 |
| } |
|
125 |
| |
|
126 |
2
| return true;
|
|
127 |
| } |
|
128 |
| |
|
129 |
0
| return false;
|
|
130 |
| } |
|
131 |
| } |