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