View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }