AT&T 2.0.19 Code drop, stage 2
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / stillNeed / X509Test.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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 package org.onap.aaf.stillNeed;
22
23 import java.security.Principal;
24
25 import org.onap.aaf.cadi.PropAccess;
26 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
27 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
28 import org.onap.aaf.cadi.client.Future;
29 import org.onap.aaf.cadi.locator.DNSLocator;
30 import org.onap.aaf.cadi.lur.LocalPermission;
31
32 //TODO Needs running service to TEST
33
34 public class X509Test {
35         public static void main(String args[]) {
36                 // Link or reuse to your Logging mechanism
37                 
38                 PropAccess myAccess = new PropAccess();
39                 
40                 // 
41                 try {
42                         AAFConHttp con = new AAFConHttp(myAccess, 
43                                         new DNSLocator(myAccess,"https","mithrilcsp.sbc.com","8100"));
44                         
45                         // AAFLur has pool of DME clients as needed, and Caches Client lookups
46                         AAFLurPerm aafLur = con.newLur();
47                         
48                         // Note: If you need both Authn and Authz construct the following:
49 //                      AAFAuthn<?> aafAuthn = con.newAuthn(aafLur);
50                         
51                         // con.x509Alias("aaf.att"); // alias in keystore
52
53                         try {
54                                 
55                                 // Normally, you obtain Principal from Authentication System.
56 //                              // For J2EE, you can ask the HttpServletRequest for getUserPrincipal()
57 //                              // If you use CADI as Authenticator, it will get you these Principals from
58 //                              // CSP or BasicAuth mechanisms.
59 //                              String id = "cluster_admin@gridcore.att.com";
60 //
61 //                              // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason.
62                                 Future<String> fs = 
63                                                 con.client("2.0").read("/authz/perms/com.att.aaf.ca","application/Perms+json");
64                                 if(fs.get(3000)) {
65                                         System.out.println(fs.value);
66                                 } else {
67                                         System.out.println("Error: "  + fs.code() + ':' + fs.body());
68                                 }
69                                 
70                                 // Check on Perms with LUR
71                                 if(aafLur.fish(new Principal() {
72                                         @Override
73                                         public String getName() {
74                                                 return "m12345@aaf.att.com";
75                                         }
76                                 }, new LocalPermission("org.osaaf.aaf.ca|aaf|request"))) {
77                                         System.out.println("Has Perm");
78                                 } else {
79                                         System.out.println("Does NOT Have Perm");
80                                 }
81                         } finally {
82                                 aafLur.destroy();
83                         }
84                 } catch (Exception e) {
85                         e.printStackTrace();
86                 }
87
88         }
89 }