1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.aaf.cass.test;
\r
25 import java.util.HashMap;
\r
26 import java.util.Map;
\r
27 import java.util.Set;
\r
29 import org.apache.cassandra.auth.AuthenticatedUser;
\r
30 import org.apache.cassandra.auth.IResource;
\r
31 import org.apache.cassandra.auth.Permission;
\r
32 import org.junit.AfterClass;
\r
33 import org.junit.Assert;
\r
34 import org.junit.BeforeClass;
\r
35 import org.junit.Test;
\r
36 import org.onap.aaf.cadi.aaf.cass.AAFAuthenticator;
\r
37 import org.onap.aaf.cadi.aaf.cass.AAFAuthorizer;
\r
39 public class JU_CASS {
\r
41 private static AAFAuthenticator aa;
\r
42 private static AAFAuthorizer an;
\r
45 public static void setUpBeforeClass() throws Exception {
\r
46 System.setProperty("cadi_prop_files", "etc/cadi.properties");
\r
48 aa = new AAFAuthenticator();
\r
49 an = new AAFAuthorizer();
\r
52 an.setup(); // does nothing after aa.
\r
54 aa.validateConfiguration();
\r
59 public static void tearDownAfterClass() throws Exception {
\r
63 public void test() throws Exception {
\r
64 Map<String,String> creds = new HashMap<String,String>();
\r
65 creds.put("username", "XXX@NS");
\r
66 creds.put("password", "enc:???");
\r
67 AuthenticatedUser aaf = aa.authenticate(creds);
\r
69 // Test out "aaf_default_domain
\r
70 creds.put("username", "XX");
\r
71 aaf = aa.authenticate(creds);
\r
73 IResource resource = new IResource() {
\r
74 public String getName() {
\r
75 return "data/authz";
\r
78 public IResource getParent() {
\r
82 public boolean hasParent() {
\r
86 public boolean exists() {
\r
92 Set<Permission> perms = an.authorize(aaf, resource);
\r
94 // Test out "AAF" access
\r
95 creds.put("username", "XXX@NS");
\r
96 creds.put("password", "enc:???");
\r
97 aaf = aa.authenticate(creds);
\r
98 perms = an.authorize(aaf, resource);
\r
99 Assert.assertFalse(perms.isEmpty());
\r
101 perms = an.authorize(aaf, resource);
\r
102 Assert.assertFalse(perms.isEmpty());
\r