1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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 ******************************************************************************/
22 package org.onap.aaf.cadi.cass;
24 import java.util.HashMap;
28 import org.apache.cassandra.auth.AuthenticatedUser;
29 import org.apache.cassandra.auth.IResource;
30 import org.apache.cassandra.auth.Permission;
31 import org.junit.AfterClass;
32 import org.junit.Assert;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
36 import com.att.aaf.cadi.cass.AAFAuthenticator;
37 import com.att.aaf.cadi.cass.AAFAuthorizer;
39 public class JU_CASS {
41 private static AAFAuthenticator aa;
42 private static AAFAuthorizer an;
45 public static void setUpBeforeClass() throws Exception {
46 System.setProperty("cadi_prop_files", "etc/cadi.properties");
48 aa = new AAFAuthenticator();
49 an = new AAFAuthorizer();
52 an.setup(); // does nothing after aa.
54 aa.validateConfiguration();
59 public static void tearDownAfterClass() throws Exception {
63 public void test() throws Exception {
64 Map<String,String> creds = new HashMap<String,String>();
65 creds.put("username", "XXX@NS");
66 creds.put("password", "enc:???");
67 AuthenticatedUser aaf = aa.authenticate(creds);
69 // Test out "aaf_default_domain
70 creds.put("username", "XX");
71 aaf = aa.authenticate(creds);
73 IResource resource = new IResource() {
74 public String getName() {
78 public IResource getParent() {
82 public boolean hasParent() {
86 public boolean exists() {
92 Set<Permission> perms = an.authorize(aaf, resource);
94 // Test out "AAF" access
95 creds.put("username", "XXX@NS");
96 creds.put("password", "enc:???");
97 aaf = aa.authenticate(creds);
98 perms = an.authorize(aaf, resource);
99 Assert.assertFalse(perms.isEmpty());
101 perms = an.authorize(aaf, resource);
102 Assert.assertFalse(perms.isEmpty());