60fd5487d55e69a36c4409f9ff87b6c03aa9c13a
[aaf/authz.git] / cadi / cass / src / test / java / org / onap / aaf / cadi / cass / JU_CASS.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
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====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.cadi.cass;
23
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Set;
27
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;
35
36 import com.att.aaf.cadi.cass.AAFAuthenticator;
37 import com.att.aaf.cadi.cass.AAFAuthorizer;
38
39 public class JU_CASS {
40
41         private static AAFAuthenticator aa;
42         private static AAFAuthorizer an;
43
44         @BeforeClass
45         public static void setUpBeforeClass() throws Exception {
46                 System.setProperty("cadi_prop_files", "etc/cadi.properties");
47                 
48                 aa = new AAFAuthenticator();
49                 an = new AAFAuthorizer();
50
51                 aa.setup();
52                 an.setup(); // does nothing after aa.
53                 
54                 aa.validateConfiguration();
55                 
56         }
57
58         @AfterClass
59         public static void tearDownAfterClass() throws Exception {
60         }
61
62         @Test
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);
68
69                         // Test out "aaf_default_domain
70                         creds.put("username", "XX");
71                         aaf = aa.authenticate(creds);
72                         
73                         IResource resource = new IResource() {
74                                 public String getName() {
75                                         return "data/authz";
76                                 }
77
78                                 public IResource getParent() {
79                                         return null;
80                                 }
81
82                                 public boolean hasParent() {
83                                         return false;
84                                 }
85
86                                 public boolean exists() {
87                                         return true;
88                                 }
89                                 
90                         };
91                         
92                         Set<Permission> perms = an.authorize(aaf, resource);
93                         
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());
100
101                         perms = an.authorize(aaf, resource);
102                         Assert.assertFalse(perms.isEmpty());
103                         
104         }
105
106 }