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 static org.junit.Assert.assertNotNull;
22 import org.junit.Before;
23 import org.junit.Test;
24
25 import org.apache.shiro.authc.AuthenticationException;
26 import org.apache.shiro.authc.AuthenticationInfo;
27 import org.apache.shiro.authc.AuthenticationToken;
28 import org.apache.shiro.authz.AuthorizationInfo;
29 import org.apache.shiro.realm.AuthorizingRealm;
30 import org.apache.shiro.realm.Realm;
31 import org.apache.shiro.realm.SimpleAccountRealm;
32 import org.apache.shiro.subject.PrincipalCollection;
33
34
35 public class AllSuccessfulStrategyTest {
36
37 private AllSuccessfulStrategy strategy;
38
39 @Before
40 public void setUp() {
41 strategy = new AllSuccessfulStrategy();
42 }
43
44 @Test
45 public void beforeAllAttempts() {
46 AuthenticationInfo info = strategy.beforeAllAttempts(null, null);
47 assertNotNull(info);
48 }
49
50 @Test
51 public void beforeAttemptSupportingToken() {
52 new SimpleAccountRealm();
53 }
54
55 @Test(expected = UnsupportedTokenException.class)
56 public void beforeAttemptRealmDoesntSupportToken() {
57 Realm notSupportingRealm = new AuthorizingRealm() {
58
59 public boolean supports(AuthenticationToken token) {
60 return false;
61 }
62
63 protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
64 return null;
65 }
66
67 protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {
68 return null;
69 }
70
71 };
72
73 strategy.beforeAttempt(notSupportingRealm, null, null);
74 }
75
76
77 }