|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.providers; |
|
17 |
| |
|
18 |
| import org.acegisecurity.Authentication; |
|
19 |
| import org.acegisecurity.userdetails.UserDetails; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| public abstract class AbstractAuthenticationToken implements Authentication { |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
5
| public Object getDetails() {
|
|
38 |
5
| return null;
|
|
39 |
| } |
|
40 |
| |
|
41 |
29
| public String getName() {
|
|
42 |
29
| if (this.getPrincipal() instanceof UserDetails) {
|
|
43 |
2
| return ((UserDetails) this.getPrincipal()).getUsername();
|
|
44 |
| } |
|
45 |
| |
|
46 |
27
| return this.getPrincipal().toString();
|
|
47 |
| } |
|
48 |
| |
|
49 |
51
| public boolean equals(Object obj) {
|
|
50 |
51
| if (obj instanceof AbstractAuthenticationToken) {
|
|
51 |
50
| AbstractAuthenticationToken test = (AbstractAuthenticationToken) obj;
|
|
52 |
| |
|
53 |
50
| if (!((this.getAuthorities() == null)
|
|
54 |
| && (test.getAuthorities() == null))) { |
|
55 |
45
| if ((this.getAuthorities() == null)
|
|
56 |
| || (test.getAuthorities() == null)) { |
|
57 |
2
| return false;
|
|
58 |
| } |
|
59 |
| |
|
60 |
43
| if (this.getAuthorities().length != test.getAuthorities().length) {
|
|
61 |
2
| return false;
|
|
62 |
| } |
|
63 |
| |
|
64 |
41
| for (int i = 0; i < this.getAuthorities().length; i++) {
|
|
65 |
75
| if (!this.getAuthorities()[i].equals(
|
|
66 |
| test.getAuthorities()[i])) { |
|
67 |
2
| return false;
|
|
68 |
| } |
|
69 |
| } |
|
70 |
| } |
|
71 |
| |
|
72 |
44
| return (this.getPrincipal().equals(test.getPrincipal())
|
|
73 |
| && this.getCredentials().equals(test.getCredentials()) |
|
74 |
| && (this.isAuthenticated() == test.isAuthenticated())); |
|
75 |
| } |
|
76 |
| |
|
77 |
1
| return false;
|
|
78 |
| } |
|
79 |
| |
|
80 |
9
| public String toString() {
|
|
81 |
9
| StringBuffer sb = new StringBuffer();
|
|
82 |
9
| sb.append(super.toString()).append(": ");
|
|
83 |
9
| sb.append("Username: ").append(this.getPrincipal()).append("; ");
|
|
84 |
9
| sb.append("Password: [PROTECTED]; ");
|
|
85 |
9
| sb.append("Authenticated: ").append(this.isAuthenticated()).append("; ");
|
|
86 |
9
| sb.append("Details: ").append(this.getDetails()).append("; ");
|
|
87 |
| |
|
88 |
9
| if (this.getAuthorities() != null) {
|
|
89 |
6
| sb.append("Granted Authorities: ");
|
|
90 |
| |
|
91 |
6
| for (int i = 0; i < this.getAuthorities().length; i++) {
|
|
92 |
9
| if (i > 0) {
|
|
93 |
4
| sb.append(", ");
|
|
94 |
| } |
|
95 |
| |
|
96 |
9
| sb.append(this.getAuthorities()[i].toString());
|
|
97 |
| } |
|
98 |
| } else { |
|
99 |
3
| sb.append("Not granted any authorities");
|
|
100 |
| } |
|
101 |
| |
|
102 |
9
| return sb.toString();
|
|
103 |
| } |
|
104 |
| } |