1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.authc.pam;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import org.apache.shiro.authc.AuthenticationException;
25 import org.apache.shiro.authc.AuthenticationInfo;
26 import org.apache.shiro.authc.AuthenticationToken;
27 import org.apache.shiro.authc.UnknownAccountException;
28 import org.apache.shiro.realm.Realm;
29
30
31
32
33
34
35
36
37
38
39
40
41 public class AllSuccessfulStrategy extends AbstractAuthenticationStrategy {
42
43
44 private static final Logger log = LoggerFactory.getLogger(AllSuccessfulStrategy.class);
45
46
47
48
49
50
51
52
53 public AuthenticationInfo.html#AuthenticationInfo">AuthenticationInfo beforeAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo info) throws AuthenticationException {
54 if (!realm.supports(token)) {
55 String msg = "Realm [" + realm + "] of type [" + realm.getClass().getName() + "] does not support " +
56 " the submitted AuthenticationToken [" + token + "]. The [" + getClass().getName() +
57 "] implementation requires all configured realm(s) to support and be able to process the submitted " +
58 "AuthenticationToken.";
59 throw new UnsupportedTokenException(msg);
60 }
61
62 return info;
63 }
64
65
66
67
68
69
70
71
72
73
74
75 public AuthenticationInfo/../../org/apache/shiro/authc/AuthenticationInfo.html#AuthenticationInfo">AuthenticationInfoo.html#AuthenticationInfo">AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo/../../org/apache/shiro/authc/AuthenticationInfo.html#AuthenticationInfo">AuthenticationInfo info, AuthenticationInfo aggregate, Throwable t)
76 throws AuthenticationException {
77 if (t != null) {
78 if (t instanceof AuthenticationException) {
79
80 throw ((AuthenticationException) t);
81 } else {
82 String msg = "Unable to acquire account data from realm [" + realm + "]. The [" +
83 getClass().getName() + " implementation requires all configured realm(s) to operate successfully " +
84 "for a successful authentication.";
85 throw new AuthenticationException(msg, t);
86 }
87 }
88 if (info == null) {
89 String msg = "Realm [" + realm + "] could not find any associated account data for the submitted " +
90 "AuthenticationToken [" + token + "]. The [" + getClass().getName() + "] implementation requires " +
91 "all configured realm(s) to acquire valid account data for a submitted token during the " +
92 "log-in process.";
93 throw new UnknownAccountException(msg);
94 }
95
96 log.debug("Account successfully authenticated using realm [{}]", realm);
97
98
99
100 merge(info, aggregate);
101
102 return aggregate;
103 }
104 }