|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.providers.cas; |
|
17 |
| |
|
18 |
| import org.acegisecurity.GrantedAuthority; |
|
19 |
| import org.acegisecurity.providers.AbstractAuthenticationToken; |
|
20 |
| import org.acegisecurity.userdetails.UserDetails; |
|
21 |
| |
|
22 |
| import org.springframework.util.Assert; |
|
23 |
| |
|
24 |
| import java.io.Serializable; |
|
25 |
| |
|
26 |
| import java.util.List; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public class CasAuthenticationToken extends AbstractAuthenticationToken |
|
36 |
| implements Serializable { |
|
37 |
| |
|
38 |
| |
|
39 |
| private List proxyList; |
|
40 |
| private Object credentials; |
|
41 |
| private Object principal; |
|
42 |
| private String proxyGrantingTicketIou; |
|
43 |
| private UserDetails userDetails; |
|
44 |
| private GrantedAuthority[] authorities; |
|
45 |
| private boolean authenticated; |
|
46 |
| private int keyHash; |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
28
| public CasAuthenticationToken(String key, Object principal,
|
|
71 |
| Object credentials, GrantedAuthority[] authorities, |
|
72 |
| UserDetails userDetails, List proxyList, String proxyGrantingTicketIou) { |
|
73 |
28
| if ((key == null) || ("".equals(key)) || (principal == null)
|
|
74 |
| || "".equals(principal) || (credentials == null) |
|
75 |
| || "".equals(credentials) || (authorities == null) |
|
76 |
| || (userDetails == null) || (proxyList == null) |
|
77 |
| || (proxyGrantingTicketIou == null)) { |
|
78 |
7
| throw new IllegalArgumentException(
|
|
79 |
| "Cannot pass null or empty values to constructor"); |
|
80 |
| } |
|
81 |
| |
|
82 |
21
| for (int i = 0; i < authorities.length; i++) {
|
|
83 |
41
| Assert.notNull(authorities[i],
|
|
84 |
| "Granted authority element " + i |
|
85 |
| + " is null - GrantedAuthority[] cannot contain any null elements"); |
|
86 |
| } |
|
87 |
| |
|
88 |
20
| this.keyHash = key.hashCode();
|
|
89 |
20
| this.principal = principal;
|
|
90 |
20
| this.credentials = credentials;
|
|
91 |
20
| this.authorities = authorities;
|
|
92 |
20
| this.userDetails = userDetails;
|
|
93 |
20
| this.proxyList = proxyList;
|
|
94 |
20
| this.proxyGrantingTicketIou = proxyGrantingTicketIou;
|
|
95 |
20
| this.authenticated = true;
|
|
96 |
| } |
|
97 |
| |
|
98 |
1
| protected CasAuthenticationToken() {
|
|
99 |
1
| throw new IllegalArgumentException("Cannot use default constructor");
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
1
| public void setAuthenticated(boolean isAuthenticated) {
|
|
105 |
1
| this.authenticated = isAuthenticated;
|
|
106 |
| } |
|
107 |
| |
|
108 |
16
| public boolean isAuthenticated() {
|
|
109 |
16
| return this.authenticated;
|
|
110 |
| } |
|
111 |
| |
|
112 |
102
| public GrantedAuthority[] getAuthorities() {
|
|
113 |
102
| return this.authorities;
|
|
114 |
| } |
|
115 |
| |
|
116 |
21
| public Object getCredentials() {
|
|
117 |
21
| return this.credentials;
|
|
118 |
| } |
|
119 |
| |
|
120 |
12
| public int getKeyHash() {
|
|
121 |
12
| return this.keyHash;
|
|
122 |
| } |
|
123 |
| |
|
124 |
20
| public Object getPrincipal() {
|
|
125 |
20
| return this.principal;
|
|
126 |
| } |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
14
| public String getProxyGrantingTicketIou() {
|
|
135 |
14
| return proxyGrantingTicketIou;
|
|
136 |
| } |
|
137 |
| |
|
138 |
12
| public List getProxyList() {
|
|
139 |
12
| return proxyList;
|
|
140 |
| } |
|
141 |
| |
|
142 |
1
| public UserDetails getUserDetails() {
|
|
143 |
1
| return userDetails;
|
|
144 |
| } |
|
145 |
| |
|
146 |
8
| public boolean equals(Object obj) {
|
|
147 |
8
| if (!super.equals(obj)) {
|
|
148 |
1
| return false;
|
|
149 |
| } |
|
150 |
| |
|
151 |
7
| if (obj instanceof CasAuthenticationToken) {
|
|
152 |
6
| CasAuthenticationToken test = (CasAuthenticationToken) obj;
|
|
153 |
| |
|
154 |
| |
|
155 |
6
| if (!this.getProxyGrantingTicketIou().equals(test
|
|
156 |
| .getProxyGrantingTicketIou())) { |
|
157 |
1
| return false;
|
|
158 |
| } |
|
159 |
| |
|
160 |
| |
|
161 |
5
| if (!this.getProxyList().equals(test.getProxyList())) {
|
|
162 |
1
| return false;
|
|
163 |
| } |
|
164 |
| |
|
165 |
4
| if (this.getKeyHash() != test.getKeyHash()) {
|
|
166 |
1
| return false;
|
|
167 |
| } |
|
168 |
| |
|
169 |
3
| return true;
|
|
170 |
| } |
|
171 |
| |
|
172 |
1
| return false;
|
|
173 |
| } |
|
174 |
| |
|
175 |
1
| public String toString() {
|
|
176 |
1
| StringBuffer sb = new StringBuffer();
|
|
177 |
1
| sb.append(super.toString());
|
|
178 |
1
| sb.append("; Credentials (Service/Proxy Ticket): " + this.credentials);
|
|
179 |
1
| sb.append("; Proxy-Granting Ticket IOU: " + this.proxyGrantingTicketIou);
|
|
180 |
1
| sb.append("; Proxy List: " + this.proxyList.toString());
|
|
181 |
| |
|
182 |
1
| return sb.toString();
|
|
183 |
| } |
|
184 |
| } |