1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.security.providers.anonymous;
17
18 import org.springframework.security.GrantedAuthority;
19
20 import org.springframework.security.providers.AbstractAuthenticationToken;
21
22 import java.io.Serializable;
23
24
25
26
27
28
29
30
31 public class AnonymousAuthenticationToken extends AbstractAuthenticationToken implements Serializable {
32
33
34 private static final long serialVersionUID = 1L;
35 private Object principal;
36 private int keyHash;
37
38
39
40
41
42
43
44
45
46
47
48
49 public AnonymousAuthenticationToken(String key, Object principal, GrantedAuthority[] authorities) {
50 super(authorities);
51
52 if ((key == null) || ("".equals(key)) || (principal == null) || "".equals(principal) || (authorities == null)
53 || (authorities.length == 0)) {
54 throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
55 }
56
57 this.keyHash = key.hashCode();
58 this.principal = principal;
59 setAuthenticated(true);
60 }
61
62
63
64 public boolean equals(Object obj) {
65 if (!super.equals(obj)) {
66 return false;
67 }
68
69 if (obj instanceof AnonymousAuthenticationToken) {
70 AnonymousAuthenticationToken test = (AnonymousAuthenticationToken) obj;
71
72 if (this.getKeyHash() != test.getKeyHash()) {
73 return false;
74 }
75
76 return true;
77 }
78
79 return false;
80 }
81
82
83
84
85
86
87 public Object getCredentials() {
88 return "";
89 }
90
91 public int getKeyHash() {
92 return this.keyHash;
93 }
94
95 public Object getPrincipal() {
96 return this.principal;
97 }
98 }