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.example;
24 import java.security.Principal;
26 import org.onap.aaf.cadi.PropAccess;
27 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
28 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
29 import org.onap.aaf.cadi.client.Future;
30 import org.onap.aaf.cadi.locator.DNSLocator;
31 import org.onap.aaf.cadi.lur.LocalPermission;
33 public class JU_X509Test {
34 public static void main(String args[]) {
35 // Link or reuse to your Logging mechanism
37 PropAccess myAccess = new PropAccess();
41 AAFConHttp con = new AAFConHttp(myAccess,
42 new DNSLocator(myAccess,"https","mithrilcsp.sbc.com","8100"));
44 // AAFLur has pool of DME clients as needed, and Caches Client lookups
45 AAFLurPerm aafLur = con.newLur();
47 // Note: If you need both Authn and Authz construct the following:
48 // AAFAuthn<?> aafAuthn = con.newAuthn(aafLur);
50 // con.x509Alias("aaf.att"); // alias in keystore
54 // Normally, you obtain Principal from Authentication System.
55 // // For J2EE, you can ask the HttpServletRequest for getUserPrincipal()
56 // // If you use CADI as Authenticator, it will get you these Principals from
57 // // CSP or BasicAuth mechanisms.
58 // String id = "cluster_admin@gridcore.att.com";
60 // // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason.
62 con.client("2.0").read("/authz/perms/com.att.aaf.ca","application/Perms+json");
64 System.out.println(fs.value);
66 System.out.println("Error: " + fs.code() + ':' + fs.body());
69 // Check on Perms with LUR
70 if(aafLur.fish(new Principal() {
72 public String getName() {
73 return "m12345@aaf.att.com";
75 }, new LocalPermission("org.osaaf.aaf.ca|aaf|request"))) {
76 System.out.println("Has Perm");
78 System.out.println("Does NOT Have Perm");
83 } catch (Exception e) {