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