X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-locate%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Flocate%2FAAF_Locate.java;h=5c5f9a6c4b197fd8df8893c480ec81666f562cff;hb=a06268eb4fec6c245815f33335f807474e024ab7;hp=545b6b47168aab0a06bdde9fb8983d4cfefc5c74;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;p=aaf%2Fauthz.git diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java index 545b6b47..5c5f9a6c 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,6 +23,7 @@ package org.onap.aaf.auth.locate; import java.net.URI; +import java.net.UnknownHostException; import java.util.Map; import javax.servlet.Filter; @@ -32,6 +33,7 @@ import org.onap.aaf.auth.cache.Cache.Dated; import org.onap.aaf.auth.dao.CassAccess; import org.onap.aaf.auth.dao.cass.ConfigDAO; import org.onap.aaf.auth.dao.cass.LocateDAO; +import org.onap.aaf.auth.dao.hl.Question; import org.onap.aaf.auth.direct.DirectLocatorCreator; import org.onap.aaf.auth.direct.DirectRegistrar; import org.onap.aaf.auth.env.AuthzEnv; @@ -58,17 +60,15 @@ import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; import org.onap.aaf.cadi.aaf.v2_0.AAFTrustChecker; import org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator; import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.config.RegistrationPropHolder; import org.onap.aaf.cadi.register.Registrant; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Data; import org.onap.aaf.misc.env.Env; -import org.onap.aaf.misc.rosetta.env.RosettaEnv; import com.datastax.driver.core.Cluster; public class AAF_Locate extends AbsService { - private static final String DOT_LOCATOR = ".locator"; - private static final String USER_PERMS = "userPerms"; private LocateFacade_1_1 facade; // this is the default Facade private LocateFacade_1_1 facade_1_1_XML; @@ -81,24 +81,20 @@ public class AAF_Locate extends AbsService { public final LocateDAO locateDAO; public final ConfigDAO configDAO; private Locator dal; - private final String aaf_service_name; - private final String aaf_gui_name; - + public final Question question; /** * Construct AuthzAPI with all the Context Supporting Routes that Authz needs - * + * * @param env - * @param si - * @param dm - * @param decryptor - * @throws APIException + * @param si + * @param dm + * @param decryptor + * @throws APIException */ public AAF_Locate(final AuthzEnv env) throws Exception { super(env.access(), env); - aaf_service_name = app_name.replace(DOT_LOCATOR, ".service"); - aaf_gui_name = app_name.replace(DOT_LOCATOR, ".gui"); - + expireIn = Long.parseLong(env.getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF)); // Initialize Facade for all uses @@ -120,12 +116,13 @@ public class AAF_Locate extends AbsService { facade_1_1_XML = LocateFacadeFactory.v1_1(env,this,trans,Data.TYPE.XML); synchronized(env) { - if(cacheUser == null) { + if (cacheUser == null) { cacheUser = Cache.obtain(USER_PERMS); Cache.startCleansing(env, USER_PERMS); } } + question = new Question(trans, cluster, CassAccess.KEYSPACE); //////////////////////////////////////////////////////////////////////////// // Time Critical @@ -133,8 +130,8 @@ public class AAF_Locate extends AbsService { //////////////////////////////////////////////////////////////////////// API_AAFAccess.init(this,facade); API_Find.init(this, facade); - API_Proxy.init(this, facade); - + API_Proxy.init(this, facade, question); + //////////////////////////////////////////////////////////////////////// // Management APIs //////////////////////////////////////////////////////////////////////// @@ -148,22 +145,22 @@ public class AAF_Locate extends AbsService { // Default Function //////////////////////////////////////////////////////////////////////// API_AAFAccess.initDefault(this,facade); - + } - + /** * Setup XML and JSON implementations for each supported Version type - * + * * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties * to do Versions and Content switches - * + * */ public void route(HttpMethods meth, String path, API api, LocateCode code) throws Exception { String version = "1.0"; // Get Correct API Class from Mapper - Class respCls = facade.mapper().getClass(api); - if(respCls==null) throw new Exception("Unknown class associated with " + api.getClass().getName() + ' ' + api.name()); + Class respCls = facade.mapper().getClass(api); + if (respCls==null) throw new Exception("Unknown class associated with " + api.getClass().getName() + ' ' + api.name()); // setup Application API HTML ContentTypes for JSON and Route String application = applicationJSON(respCls, version); route(env,meth,path,code,application,"application/json;version="+version,"*/*","*"); @@ -171,11 +168,11 @@ public class AAF_Locate extends AbsService { // setup Application API HTML ContentTypes for XML and Route application = applicationXML(respCls, version); route(env,meth,path,code.clone(facade_1_1_XML,false),application,"text/xml;version="+version); - + // Add other Supported APIs here as created } - - public void routeAll(HttpMethods meth, String path, API api, LocateCode code) throws Exception { + + public void routeAll(HttpMethods meth, String path, API api, LocateCode code){ route(env,meth,path,code,""); // this will always match } @@ -186,8 +183,8 @@ public class AAF_Locate extends AbsService { @Override protected AAFConHttp _newAAFConHttp() throws CadiException { try { - if(dal==null) { - dal = AbsAAFLocator.create(aaf_service_name,Config.AAF_DEFAULT_VERSION); + if (dal==null) { + dal = AbsAAFLocator.create("%CNS.%NS.service",Config.AAF_DEFAULT_API_VERSION); } // utilize pre-constructed DirectAAFLocator return new AAFConHttp(env.access(),dal); @@ -197,8 +194,15 @@ public class AAF_Locate extends AbsService { } public Locator getGUILocator() throws LocatorException { - if(gui_locator==null) { - gui_locator = AbsAAFLocator.create(aaf_gui_name,Config.AAF_DEFAULT_VERSION); + if (gui_locator==null) { + RegistrationPropHolder rph; + try { + rph = new RegistrationPropHolder(access, 0); + } catch (UnknownHostException | CadiException e) { + throw new LocatorException(e); + } + String url = rph.getPublicEntryName("gui", rph.default_container); + gui_locator = AbsAAFLocator.create(url,Config.AAF_DEFAULT_API_VERSION); } return gui_locator; } @@ -208,7 +212,7 @@ public class AAF_Locate extends AbsService { public Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException { try { return new Filter[] { - new AuthzTransFilter(env, aafCon(), + new AuthzTransFilter(env, aafCon(), new AAFTrustChecker((Env)env) ,additionalTafLurs )}; @@ -221,14 +225,14 @@ public class AAF_Locate extends AbsService { @Override public Registrant[] registrants(final int port) throws CadiException { return new Registrant[] { - new DirectRegistrar(access,locateDAO,app_name,app_version,port) + new DirectRegistrar(access,locateDAO,port) }; } @Override public void destroy() { Cache.stopTimer(); - if(cluster!=null) { + if (cluster!=null) { cluster.close(); } super.destroy(); @@ -239,9 +243,13 @@ public class AAF_Locate extends AbsService { Log4JLogIt logIt = new Log4JLogIt(args, "locate"); PropAccess propAccess = new PropAccess(logIt,args); - AAF_Locate service = new AAF_Locate(new AuthzEnv(propAccess)); - JettyServiceStarter jss = new JettyServiceStarter(service); - jss.start(); + try { + new JettyServiceStarter( + new AAF_Locate(new AuthzEnv(propAccess)),true) + .start(); + } catch (Exception e) { + propAccess.log(e); + } } catch (Exception e) { e.printStackTrace(); }