[AAF-21] Initial code import
[aaf/cadi.git] / cass / src / test / java / com / att / aaf / cass / JU_CASS.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.att.aaf.cass;\r
25 \r
26 import java.util.HashMap;\r
27 import java.util.Map;\r
28 import java.util.Set;\r
29 \r
30 import org.apache.cassandra.auth.AuthenticatedUser;\r
31 import org.apache.cassandra.auth.IResource;\r
32 import org.apache.cassandra.auth.Permission;\r
33 import org.junit.AfterClass;\r
34 import org.junit.Assert;\r
35 import org.junit.BeforeClass;\r
36 import org.junit.Test;\r
37 \r
38 import com.att.cadi.aaf.cass.AAFAuthenticator;\r
39 import com.att.cadi.aaf.cass.AAFAuthorizer;\r
40 \r
41 public class JU_CASS {\r
42 \r
43         private static AAFAuthenticator aa;\r
44         private static AAFAuthorizer an;\r
45 \r
46         @BeforeClass\r
47         public static void setUpBeforeClass() throws Exception {\r
48                 System.setProperty("cadi_prop_files", "etc/cadi.properties");\r
49                 \r
50                 aa = new AAFAuthenticator();\r
51                 an = new AAFAuthorizer();\r
52 \r
53                 aa.setup();\r
54                 an.setup(); // does nothing after aa.\r
55                 \r
56                 aa.validateConfiguration();\r
57                 \r
58         }\r
59 \r
60         @AfterClass\r
61         public static void tearDownAfterClass() throws Exception {\r
62         }\r
63 \r
64         @Test\r
65         public void test() throws Exception {\r
66                         Map<String,String> creds = new HashMap<String,String>();\r
67                         creds.put("username", "XXX@NS");\r
68                         creds.put("password", "enc:???");\r
69                         AuthenticatedUser aaf = aa.authenticate(creds);\r
70 \r
71                         // Test out "aaf_default_domain\r
72                         creds.put("username", "XX");\r
73                         aaf = aa.authenticate(creds);\r
74                         \r
75                         IResource resource = new IResource() {\r
76                                 public String getName() {\r
77                                         return "data/authz";\r
78                                 }\r
79 \r
80                                 public IResource getParent() {\r
81                                         return null;\r
82                                 }\r
83 \r
84                                 public boolean hasParent() {\r
85                                         return false;\r
86                                 }\r
87 \r
88                                 public boolean exists() {\r
89                                         return true;\r
90                                 }\r
91                                 \r
92                         };\r
93                         \r
94                         Set<Permission> perms = an.authorize(aaf, resource);\r
95                         \r
96                         // Test out "AAF" access\r
97                         creds.put("username", "XXX@NS");\r
98                         creds.put("password", "enc:???");\r
99                         aaf = aa.authenticate(creds);\r
100                         perms = an.authorize(aaf, resource);\r
101                         Assert.assertFalse(perms.isEmpty());\r
102 \r
103                         perms = an.authorize(aaf, resource);\r
104                         Assert.assertFalse(perms.isEmpty());\r
105                         \r
106         }\r
107 \r
108 }\r