2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.cadi.shiro.test;
23 import java.util.ArrayList;
25 import org.apache.shiro.authc.AuthenticationInfo;
26 import org.apache.shiro.authc.UsernamePasswordToken;
27 import org.apache.shiro.authz.AuthorizationInfo;
28 import org.apache.shiro.authz.Permission;
29 import org.apache.shiro.subject.PrincipalCollection;
30 import org.junit.Test;
31 import org.onap.aaf.cadi.aaf.AAFPermission;
32 import org.onap.aaf.cadi.config.Config;
33 import org.onap.aaf.cadi.shiro.AAFRealm;
34 import org.onap.aaf.cadi.shiro.AAFShiroPermission;
36 import junit.framework.Assert;
38 public class JU_AAFRealm {
40 // TODO: Ian - fix this test
42 // public void test() {
43 // // NOTE This is a live test. This JUnit needs to be built with "Mock"
45 // System.setProperty(Config.CADI_PROP_FILES, "/opt/app/osaaf/etc/org.osaaf.common.props");
46 // TestAAFRealm ar = new TestAAFRealm();
48 // UsernamePasswordToken upt = new UsernamePasswordToken("jonathan@people.osaaf.org", "new2You!");
49 // AuthenticationInfo ani = ar.authn(upt);
51 // AuthorizationInfo azi = ar.authz(ani.getPrincipals());
52 // // Change this to something YOU have, Sai...
54 // testAPerm(true,azi,"org.access","something","*");
55 // testAPerm(false,azi,"org.accessX","something","*");
56 // } catch (Throwable t) {
57 // t.printStackTrace();
62 private void testAPerm(boolean expect, AuthorizationInfo azi, String name, String type, String instance, String action) {
64 AAFShiroPermission testPerm = new AAFShiroPermission(new AAFPermission(type,name,instance,action,new ArrayList<String>()));
67 for(Permission p : azi.getObjectPermissions()) {
68 if(p.implies(testPerm)) {
73 Assert.assertTrue(any);
75 Assert.assertFalse(any);
82 * Note, have to create a derived class, because "doGet"... are protected
84 private class TestAAFRealm extends AAFRealm {
85 public AuthenticationInfo authn(UsernamePasswordToken upt) {
86 return doGetAuthenticationInfo(upt);
88 public AuthorizationInfo authz(PrincipalCollection pc) {
89 return doGetAuthorizationInfo(pc);