+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi.lur.aaf.test;\r
-\r
-import java.security.Principal;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.onap.aaf.cadi.Access;\r
-import org.onap.aaf.cadi.Permission;\r
-import org.onap.aaf.cadi.PropAccess;\r
-import org.onap.aaf.cadi.aaf.AAFPermission;\r
-import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;\r
-import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;\r
-import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;\r
-import org.onap.aaf.cadi.config.Config;\r
-import org.onap.aaf.cadi.locator.PropertyLocator;\r
-\r
-public class JU_MultiThreadPermHit {\r
- public static void main(String args[]) {\r
- // Link or reuse to your Logging mechanism\r
- PropAccess myAccess = new PropAccess(); // \r
- \r
- // \r
- try {\r
- AAFConHttp con = new AAFConHttp(myAccess,new PropertyLocator("https://mithrilcsp.sbc.com:8100"));\r
- \r
- // AAFLur has pool of DME clients as needed, and Caches Client lookups\r
- final AAFLurPerm aafLur = con.newLur();\r
- aafLur.setDebug("m12345@aaf.att.com");\r
-\r
- // Note: If you need both Authn and Authz construct the following:\r
- AAFAuthn<?> aafAuthn = con.newAuthn(aafLur);\r
- \r
- // Do not set Mech ID until after you construct AAFAuthn,\r
- // because we initiate "401" info to determine the Realm of \r
- // of the service we're after.\r
- final String id = myAccess.getProperty(Config.AAF_MECHID,null);\r
- final String pass = myAccess.decrypt(myAccess.getProperty(Config.AAF_MECHPASS,null),false);\r
- if(id!=null && pass!=null) {\r
- try {\r
- \r
- // Normally, you obtain Principal from Authentication System.\r
- // // For J2EE, you can ask the HttpServletRequest for getUserPrincipal()\r
- // // If you use CADI as Authenticator, it will get you these Principals from\r
- // // CSP or BasicAuth mechanisms.\r
- // String id = "cluster_admin@gridcore.att.com";\r
- //\r
- // // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason.\r
- String ok;\r
- ok = aafAuthn.validate(id, pass);\r
- if(ok!=null) {\r
- System.out.println(ok);\r
- }\r
-\r
- List<Permission> pond = new ArrayList<Permission>();\r
- for(int i=0;i<20;++i) {\r
- pond.clear();\r
- aafLur.fishAll(i+id, pond);\r
- if(ok!=null && i%1000==0) {\r
- System.out.println(i + " " + ok);\r
- }\r
- }\r
-\r
- for(int i=0;i<1000000;++i) {\r
- ok = aafAuthn.validate( i+ id, "wrongPass");\r
- if(ok!=null && i%1000==0) {\r
- System.out.println(i + " " + ok);\r
- }\r
- }\r
- \r
- final AAFPermission perm = new AAFPermission("com.att.aaf.access","*","*");\r
- \r
- // Now you can ask the LUR (Local Representative of the User Repository about Authorization\r
- // With CADI, in J2EE, you can call isUserInRole("com.att.mygroup|mytype|write") on the Request Object \r
- // instead of creating your own LUR\r
- for(int i=0;i<4;++i) {\r
- if(aafLur.fish(id, perm)) {\r
- System.out.println("Yes, " + id + " has permission for " + perm.getKey());\r
- } else {\r
- System.out.println("No, " + id + " does not have permission for " + perm.getKey());\r
- }\r
- }\r
- \r
- \r
- // Or you can all for all the Permissions available\r
- List<Permission> perms = new ArrayList<Permission>();\r
- \r
- \r
- aafLur.fishAll(id,perms);\r
- System.out.println("Perms for " + id);\r
- for(Permission prm : perms) {\r
- System.out.println(prm.getKey());\r
- }\r
- \r
- System.out.println("Press any key to continue");\r
- System.in.read();\r
- \r
- for(int j=0;j<5;++j) {\r
- new Thread(new Runnable() {\r
- @Override\r
- public void run() {\r
- for(int i=0;i<20;++i) {\r
- if(aafLur.fish(id, perm)) {\r
- System.out.println("Yes, " + id + " has permission for " + perm.getKey());\r
- } else {\r
- System.out.println("No, " + id + " does not have permission for " + perm.getKey());\r
- }\r
- }\r
- }\r
- }).start();\r
- }\r
- \r
- \r
- } finally {\r
- aafLur.destroy();\r
- }\r
- } else { // checked on IDs\r
- System.err.println(Config.AAF_MECHID + " and/or " + Config.AAF_MECHPASS + " are not set.");\r
- }\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-}\r