summaryrefslogtreecommitdiffstats
path: root/auth/auth-locate/src
diff options
context:
space:
mode:
Diffstat (limited to 'auth/auth-locate/src')
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java358
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/BasicAuthCode.java74
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/LocateCode.java28
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java444
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Api.java98
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Find.java158
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Proxy.java216
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java132
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java18
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java638
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java6
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java12
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java214
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java10
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java202
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/validation/LocateValidator.java184
-rw-r--r--auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java96
-rw-r--r--auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java46
-rw-r--r--auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java132
19 files changed, 1533 insertions, 1533 deletions
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 9f25eab7..545b6b47 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
@@ -67,183 +67,183 @@ import org.onap.aaf.misc.rosetta.env.RosettaEnv;
import com.datastax.driver.core.Cluster;
public class AAF_Locate extends AbsService<AuthzEnv, AuthzTrans> {
- 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;
- public Map<String, Dated> cacheUser;
- public final AAFAuthn<?> aafAuthn;
- public final AAFLurPerm aafLurPerm;
- private Locator<URI> gui_locator;
- public final long expireIn;
- private final Cluster cluster;
- public final LocateDAO locateDAO;
- public final ConfigDAO configDAO;
- private Locator<URI> dal;
- private final String aaf_service_name;
- private final String aaf_gui_name;
-
-
- /**
- * Construct AuthzAPI with all the Context Supporting Routes that Authz needs
- *
- * @param env
- * @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
- AuthzTrans trans = env.newTransNoAvg();
-
- cluster = org.onap.aaf.auth.dao.CassAccess.cluster(env,null);
- locateDAO = new LocateDAO(trans,cluster,CassAccess.KEYSPACE);
- configDAO = new ConfigDAO(trans,locateDAO); // same stuff
-
- // Have AAFLocator object Create DirectLocators for Location needs
- AbsAAFLocator.setCreator(new DirectLocatorCreator(env, locateDAO));
-
- aafLurPerm = aafCon().newLur();
- // Note: If you need both Authn and Authz construct the following:
- aafAuthn = aafCon().newAuthn(aafLurPerm);
-
-
- facade = LocateFacadeFactory.v1_1(env,this,trans,Data.TYPE.JSON); // Default Facade
- facade_1_1_XML = LocateFacadeFactory.v1_1(env,this,trans,Data.TYPE.XML);
-
- synchronized(env) {
- if(cacheUser == null) {
- cacheUser = Cache.obtain(USER_PERMS);
- Cache.startCleansing(env, USER_PERMS);
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////////////
- // Time Critical
- // These will always be evaluated first
- ////////////////////////////////////////////////////////////////////////
- API_AAFAccess.init(this,facade);
- API_Find.init(this, facade);
- API_Proxy.init(this, facade);
-
- ////////////////////////////////////////////////////////////////////////
- // Management APIs
- ////////////////////////////////////////////////////////////////////////
- // There are several APIs around each concept, and it gets a bit too
- // long in this class to create. The initialization of these Management
- // APIs have therefore been pushed to StandAlone Classes with static
- // init functions
- API_Api.init(this, facade);
-
- ////////////////////////////////////////////////////////////////////////
- // 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());
- // setup Application API HTML ContentTypes for JSON and Route
- String application = applicationJSON(respCls, version);
- route(env,meth,path,code,application,"application/json;version="+version,"*/*","*");
-
- // 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 {
- route(env,meth,path,code,""); // this will always match
- }
-
-
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.server.AbsServer#_newAAFConHttp()
- */
- @Override
- protected AAFConHttp _newAAFConHttp() throws CadiException {
- try {
- if(dal==null) {
- dal = AbsAAFLocator.create(aaf_service_name,Config.AAF_DEFAULT_VERSION);
- }
- // utilize pre-constructed DirectAAFLocator
- return new AAFConHttp(env.access(),dal);
- } catch (LocatorException e) {
- throw new CadiException(e);
- }
- }
-
- public Locator<URI> getGUILocator() throws LocatorException {
- if(gui_locator==null) {
- gui_locator = AbsAAFLocator.create(aaf_gui_name,Config.AAF_DEFAULT_VERSION);
- }
- return gui_locator;
- }
-
-
- @Override
- public Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException {
- try {
- return new Filter[] {
- new AuthzTransFilter(env, aafCon(),
- new AAFTrustChecker((Env)env)
- ,additionalTafLurs
- )};
- } catch (NumberFormatException e) {
- throw new CadiException("Invalid Property information", e);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException {
- return new Registrant[] {
- new DirectRegistrar(access,locateDAO,app_name,app_version,port)
- };
- }
-
- @Override
- public void destroy() {
- Cache.stopTimer();
- if(cluster!=null) {
- cluster.close();
- }
- super.destroy();
- }
-
- public static void main(final String[] args) {
- try {
- Log4JLogIt logIt = new Log4JLogIt(args, "locate");
- PropAccess propAccess = new PropAccess(logIt,args);
-
- AAF_Locate service = new AAF_Locate(new AuthzEnv(propAccess));
- JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
- jss.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ 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;
+ public Map<String, Dated> cacheUser;
+ public final AAFAuthn<?> aafAuthn;
+ public final AAFLurPerm aafLurPerm;
+ private Locator<URI> gui_locator;
+ public final long expireIn;
+ private final Cluster cluster;
+ public final LocateDAO locateDAO;
+ public final ConfigDAO configDAO;
+ private Locator<URI> dal;
+ private final String aaf_service_name;
+ private final String aaf_gui_name;
+
+
+ /**
+ * Construct AuthzAPI with all the Context Supporting Routes that Authz needs
+ *
+ * @param env
+ * @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
+ AuthzTrans trans = env.newTransNoAvg();
+
+ cluster = org.onap.aaf.auth.dao.CassAccess.cluster(env,null);
+ locateDAO = new LocateDAO(trans,cluster,CassAccess.KEYSPACE);
+ configDAO = new ConfigDAO(trans,locateDAO); // same stuff
+
+ // Have AAFLocator object Create DirectLocators for Location needs
+ AbsAAFLocator.setCreator(new DirectLocatorCreator(env, locateDAO));
+
+ aafLurPerm = aafCon().newLur();
+ // Note: If you need both Authn and Authz construct the following:
+ aafAuthn = aafCon().newAuthn(aafLurPerm);
+
+
+ facade = LocateFacadeFactory.v1_1(env,this,trans,Data.TYPE.JSON); // Default Facade
+ facade_1_1_XML = LocateFacadeFactory.v1_1(env,this,trans,Data.TYPE.XML);
+
+ synchronized(env) {
+ if(cacheUser == null) {
+ cacheUser = Cache.obtain(USER_PERMS);
+ Cache.startCleansing(env, USER_PERMS);
+ }
+ }
+
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Time Critical
+ // These will always be evaluated first
+ ////////////////////////////////////////////////////////////////////////
+ API_AAFAccess.init(this,facade);
+ API_Find.init(this, facade);
+ API_Proxy.init(this, facade);
+
+ ////////////////////////////////////////////////////////////////////////
+ // Management APIs
+ ////////////////////////////////////////////////////////////////////////
+ // There are several APIs around each concept, and it gets a bit too
+ // long in this class to create. The initialization of these Management
+ // APIs have therefore been pushed to StandAlone Classes with static
+ // init functions
+ API_Api.init(this, facade);
+
+ ////////////////////////////////////////////////////////////////////////
+ // 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());
+ // setup Application API HTML ContentTypes for JSON and Route
+ String application = applicationJSON(respCls, version);
+ route(env,meth,path,code,application,"application/json;version="+version,"*/*","*");
+
+ // 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 {
+ route(env,meth,path,code,""); // this will always match
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.server.AbsServer#_newAAFConHttp()
+ */
+ @Override
+ protected AAFConHttp _newAAFConHttp() throws CadiException {
+ try {
+ if(dal==null) {
+ dal = AbsAAFLocator.create(aaf_service_name,Config.AAF_DEFAULT_VERSION);
+ }
+ // utilize pre-constructed DirectAAFLocator
+ return new AAFConHttp(env.access(),dal);
+ } catch (LocatorException e) {
+ throw new CadiException(e);
+ }
+ }
+
+ public Locator<URI> getGUILocator() throws LocatorException {
+ if(gui_locator==null) {
+ gui_locator = AbsAAFLocator.create(aaf_gui_name,Config.AAF_DEFAULT_VERSION);
+ }
+ return gui_locator;
+ }
+
+
+ @Override
+ public Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException {
+ try {
+ return new Filter[] {
+ new AuthzTransFilter(env, aafCon(),
+ new AAFTrustChecker((Env)env)
+ ,additionalTafLurs
+ )};
+ } catch (NumberFormatException e) {
+ throw new CadiException("Invalid Property information", e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException {
+ return new Registrant[] {
+ new DirectRegistrar(access,locateDAO,app_name,app_version,port)
+ };
+ }
+
+ @Override
+ public void destroy() {
+ Cache.stopTimer();
+ if(cluster!=null) {
+ cluster.close();
+ }
+ super.destroy();
+ }
+
+ public static void main(final String[] args) {
+ try {
+ Log4JLogIt logIt = new Log4JLogIt(args, "locate");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
+ AAF_Locate service = new AAF_Locate(new AuthzEnv(propAccess));
+ JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
+ jss.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/BasicAuthCode.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/BasicAuthCode.java
index ac348f3f..c5239a5a 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/BasicAuthCode.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/BasicAuthCode.java
@@ -35,43 +35,43 @@ import org.onap.aaf.cadi.principal.BasicPrincipal;
import org.onap.aaf.cadi.principal.X509Principal;
public class BasicAuthCode extends LocateCode {
- private AAFAuthn<?> authn;
+ private AAFAuthn<?> authn;
- public BasicAuthCode(AAFAuthn<?> authn, LocateFacade facade) {
- super(facade, "AAF Basic Auth",true);
- this.authn = authn;
- }
+ public BasicAuthCode(AAFAuthn<?> authn, LocateFacade facade) {
+ super(facade, "AAF Basic Auth",true);
+ this.authn = authn;
+ }
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- Principal p = trans.getUserPrincipal();
- if(p == null) {
- trans.error().log("Transaction not Authenticated... no Principal");
- } else if (p instanceof BasicPrincipal) {
- // the idea is that if call is made with this credential, and it's a BasicPrincipal, it's ok
- // otherwise, it wouldn't have gotten here.
- resp.setStatus(HttpStatus.OK_200);
- return;
- } else if (p instanceof X509Principal) {
- // Since X509Principal has priority, BasicAuth Info might be there, but not validated.
- String ba;
- if((ba=req.getHeader("Authorization"))!=null && ba.startsWith("Basic ")) {
- ba = Symm.base64noSplit.decode(ba.substring(6));
- int colon = ba.indexOf(':');
- if(colon>=0) {
- String err;
- if((err=authn.validate(ba.substring(0, colon), ba.substring(colon+1),trans))==null) {
- resp.setStatus(HttpStatus.OK_200);
- } else {
- trans.audit().log(ba.substring(0,colon),": ",err);
- resp.setStatus(HttpStatus.UNAUTHORIZED_401);
- }
- return;
- }
- }
- }
- trans.checkpoint("Basic Auth Check Failed: This wasn't a Basic Auth Trans");
- // For Auth Security questions, we don't give any info to client on why failed
- resp.setStatus(HttpStatus.FORBIDDEN_403);
- }
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ Principal p = trans.getUserPrincipal();
+ if(p == null) {
+ trans.error().log("Transaction not Authenticated... no Principal");
+ } else if (p instanceof BasicPrincipal) {
+ // the idea is that if call is made with this credential, and it's a BasicPrincipal, it's ok
+ // otherwise, it wouldn't have gotten here.
+ resp.setStatus(HttpStatus.OK_200);
+ return;
+ } else if (p instanceof X509Principal) {
+ // Since X509Principal has priority, BasicAuth Info might be there, but not validated.
+ String ba;
+ if((ba=req.getHeader("Authorization"))!=null && ba.startsWith("Basic ")) {
+ ba = Symm.base64noSplit.decode(ba.substring(6));
+ int colon = ba.indexOf(':');
+ if(colon>=0) {
+ String err;
+ if((err=authn.validate(ba.substring(0, colon), ba.substring(colon+1),trans))==null) {
+ resp.setStatus(HttpStatus.OK_200);
+ } else {
+ trans.audit().log(ba.substring(0,colon),": ",err);
+ resp.setStatus(HttpStatus.UNAUTHORIZED_401);
+ }
+ return;
+ }
+ }
+ }
+ trans.checkpoint("Basic Auth Check Failed: This wasn't a Basic Auth Trans");
+ // For Auth Security questions, we don't give any info to client on why failed
+ resp.setStatus(HttpStatus.FORBIDDEN_403);
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/LocateCode.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/LocateCode.java
index b1aa23cc..214c9d80 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/LocateCode.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/LocateCode.java
@@ -26,19 +26,19 @@ import org.onap.aaf.auth.locate.facade.LocateFacade;
import org.onap.aaf.auth.rserv.HttpCode;
public abstract class LocateCode extends HttpCode<AuthzTrans, LocateFacade> implements Cloneable {
- public boolean useJSON;
+ public boolean useJSON;
- public LocateCode(LocateFacade facade, String description, boolean useJSON, String ... roles) {
- super(facade, description, roles);
- this.useJSON = useJSON;
- }
-
- public <D extends LocateCode> D clone(LocateFacade facade, boolean useJSON) throws Exception {
- @SuppressWarnings("unchecked")
- D d = (D)clone();
- d.useJSON = useJSON;
- d.context = facade;
- return d;
- }
-
+ public LocateCode(LocateFacade facade, String description, boolean useJSON, String ... roles) {
+ super(facade, description, roles);
+ this.useJSON = useJSON;
+ }
+
+ public <D extends LocateCode> D clone(LocateFacade facade, boolean useJSON) throws Exception {
+ @SuppressWarnings("unchecked")
+ D d = (D)clone();
+ d.useJSON = useJSON;
+ d.context = facade;
+ return d;
+ }
+
} \ No newline at end of file
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java
index 802c1b55..85cee82f 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java
@@ -55,237 +55,237 @@ import org.onap.aaf.misc.env.Env;
import org.onap.aaf.misc.env.TimeTaken;
public class API_AAFAccess {
-// private static String service, version, envContext;
+// private static String service, version, envContext;
- private static final String GET_PERMS_BY_USER = "Get Perms by User";
- private static final String USER_HAS_PERM ="User Has Perm";
-// private static final String USER_IN_ROLE ="User Has Role";
-
- /**
- * Normal Init level APIs
- *
- * @param gwAPI
- * @param facade
- * @throws Exception
- */
- public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
-
-
- gwAPI.route(HttpMethods.GET,"/authz/perms/user/:user",API.VOID,new LocateCode(facade,GET_PERMS_BY_USER, true) {
- @Override
- public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
- TimeTaken tt = trans.start(GET_PERMS_BY_USER, Env.SUB);
- try {
- final String accept = req.getHeader("ACCEPT");
- final String user = pathParam(req,":user");
- if(!user.contains("@")) {
- context.error(trans,resp,Result.ERR_BadData,"User [%s] must be fully qualified with domain",user);
- return;
- }
- final String key = trans.user() + user + (accept!=null&&accept.contains("xml")?"-xml":"-json");
- TimeTaken tt2 = trans.start("Cache Lookup",Env.SUB);
- Dated d;
- try {
- d = gwAPI.cacheUser.get(key);
- } finally {
- tt2.done();
- }
-
- if(d==null || d.data.isEmpty()) {
- tt2 = trans.start("AAF Service Call",Env.REMOTE);
- try {
- gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
- @Override
- public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
- Future<String> fp = client.read("/authz/perms/user/"+user,accept);
- if(fp.get(5000)) {
- gwAPI.cacheUser.put(key, new Dated(new User(fp.code(),fp.body()),gwAPI.expireIn));
- resp.setStatus(HttpStatus.OK_200);
- ServletOutputStream sos;
- try {
- sos = resp.getOutputStream();
- sos.print(fp.value);
- } catch (IOException e) {
- throw new CadiException(e);
- }
- } else {
- gwAPI.cacheUser.put(key, new Dated(new User(fp.code(),fp.body()),gwAPI.expireIn));
- context.error(trans,resp,fp.code(),fp.body());
- }
- return null;
- }
- });
- } finally {
- tt2.done();
- }
- } else {
- User u = (User)d.data.get(0);
- resp.setStatus(u.code);
- ServletOutputStream sos = resp.getOutputStream();
- sos.print(u.resp);
- }
- } finally {
- tt.done();
- }
- }
- });
+ private static final String GET_PERMS_BY_USER = "Get Perms by User";
+ private static final String USER_HAS_PERM ="User Has Perm";
+// private static final String USER_IN_ROLE ="User Has Role";
+
+ /**
+ * Normal Init level APIs
+ *
+ * @param gwAPI
+ * @param facade
+ * @throws Exception
+ */
+ public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
+
+
+ gwAPI.route(HttpMethods.GET,"/authz/perms/user/:user",API.VOID,new LocateCode(facade,GET_PERMS_BY_USER, true) {
+ @Override
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
+ TimeTaken tt = trans.start(GET_PERMS_BY_USER, Env.SUB);
+ try {
+ final String accept = req.getHeader("ACCEPT");
+ final String user = pathParam(req,":user");
+ if(!user.contains("@")) {
+ context.error(trans,resp,Result.ERR_BadData,"User [%s] must be fully qualified with domain",user);
+ return;
+ }
+ final String key = trans.user() + user + (accept!=null&&accept.contains("xml")?"-xml":"-json");
+ TimeTaken tt2 = trans.start("Cache Lookup",Env.SUB);
+ Dated d;
+ try {
+ d = gwAPI.cacheUser.get(key);
+ } finally {
+ tt2.done();
+ }
+
+ if(d==null || d.data.isEmpty()) {
+ tt2 = trans.start("AAF Service Call",Env.REMOTE);
+ try {
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
+ @Override
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
+ Future<String> fp = client.read("/authz/perms/user/"+user,accept);
+ if(fp.get(5000)) {
+ gwAPI.cacheUser.put(key, new Dated(new User(fp.code(),fp.body()),gwAPI.expireIn));
+ resp.setStatus(HttpStatus.OK_200);
+ ServletOutputStream sos;
+ try {
+ sos = resp.getOutputStream();
+ sos.print(fp.value);
+ } catch (IOException e) {
+ throw new CadiException(e);
+ }
+ } else {
+ gwAPI.cacheUser.put(key, new Dated(new User(fp.code(),fp.body()),gwAPI.expireIn));
+ context.error(trans,resp,fp.code(),fp.body());
+ }
+ return null;
+ }
+ });
+ } finally {
+ tt2.done();
+ }
+ } else {
+ User u = (User)d.data.get(0);
+ resp.setStatus(u.code);
+ ServletOutputStream sos = resp.getOutputStream();
+ sos.print(u.resp);
+ }
+ } finally {
+ tt.done();
+ }
+ }
+ });
- gwAPI.route(gwAPI.env,HttpMethods.GET,"/authn/basicAuth",new BasicAuthCode(gwAPI.aafAuthn,facade)
- ,"text/plain","*/*","*");
+ gwAPI.route(gwAPI.env,HttpMethods.GET,"/authn/basicAuth",new BasicAuthCode(gwAPI.aafAuthn,facade)
+ ,"text/plain","*/*","*");
- /**
- * Query User Has Perm is DEPRECATED
- *
- * Need to move towards NS declaration... is this even being used?
- * @deprecated
- */
- gwAPI.route(HttpMethods.GET,"/ask/:user/has/:type/:instance/:action",API.VOID,new LocateCode(facade,USER_HAS_PERM, true) {
- @Override
- public void handle(final AuthzTrans trans, final HttpServletRequest req, HttpServletResponse resp) throws Exception {
- try {
- String type = pathParam(req,":type");
- int idx = type.lastIndexOf('.');
- String ns = type.substring(0,idx);
- type = type.substring(idx+1);
- resp.getOutputStream().print(
- gwAPI.aafLurPerm.fish(new Principal() {
- public String getName() {
- return pathParam(req,":user");
- };
- }, new AAFPermission(
- ns,
- type,
- pathParam(req,":instance"),
- pathParam(req,":action"))));
- resp.setStatus(HttpStatus.OK_200);
- } catch(Exception e) {
- context.error(trans, resp, Result.ERR_General, e.getMessage());
- }
- }
- });
+ /**
+ * Query User Has Perm is DEPRECATED
+ *
+ * Need to move towards NS declaration... is this even being used?
+ * @deprecated
+ */
+ gwAPI.route(HttpMethods.GET,"/ask/:user/has/:type/:instance/:action",API.VOID,new LocateCode(facade,USER_HAS_PERM, true) {
+ @Override
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ try {
+ String type = pathParam(req,":type");
+ int idx = type.lastIndexOf('.');
+ String ns = type.substring(0,idx);
+ type = type.substring(idx+1);
+ resp.getOutputStream().print(
+ gwAPI.aafLurPerm.fish(new Principal() {
+ public String getName() {
+ return pathParam(req,":user");
+ };
+ }, new AAFPermission(
+ ns,
+ type,
+ pathParam(req,":instance"),
+ pathParam(req,":action"))));
+ resp.setStatus(HttpStatus.OK_200);
+ } catch(Exception e) {
+ context.error(trans, resp, Result.ERR_General, e.getMessage());
+ }
+ }
+ });
- gwAPI.route(HttpMethods.GET,"/gui/:path*",API.VOID,new LocateCode(facade,"Short Access PROD GUI for AAF", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- try {
- redirect(trans, req, resp, context,
- gwAPI.getGUILocator(),
- "gui/"+pathParam(req,":path"));
- } catch (LocatorException e) {
- context.error(trans, resp, Result.ERR_BadData, e.getMessage());
- } catch (Exception e) {
- context.error(trans, resp, Result.ERR_General, e.getMessage());
- }
- }
- });
+ gwAPI.route(HttpMethods.GET,"/gui/:path*",API.VOID,new LocateCode(facade,"Short Access PROD GUI for AAF", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ try {
+ redirect(trans, req, resp, context,
+ gwAPI.getGUILocator(),
+ "gui/"+pathParam(req,":path"));
+ } catch (LocatorException e) {
+ context.error(trans, resp, Result.ERR_BadData, e.getMessage());
+ } catch (Exception e) {
+ context.error(trans, resp, Result.ERR_General, e.getMessage());
+ }
+ }
+ });
- gwAPI.route(HttpMethods.GET,"/aaf/:version/:path*",API.VOID,new LocateCode(facade,"Access PROD GUI for AAF", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- try {
- redirect(trans, req, resp, context,
- gwAPI.getGUILocator(),
- pathParam(req,":path"));
- } catch (LocatorException e) {
- context.error(trans, resp, Result.ERR_BadData, e.getMessage());
- } catch (Exception e) {
- context.error(trans, resp, Result.ERR_General, e.getMessage());
- }
- }
- });
- }
-
- public static void initDefault(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
+ gwAPI.route(HttpMethods.GET,"/aaf/:version/:path*",API.VOID,new LocateCode(facade,"Access PROD GUI for AAF", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ try {
+ redirect(trans, req, resp, context,
+ gwAPI.getGUILocator(),
+ pathParam(req,":path"));
+ } catch (LocatorException e) {
+ context.error(trans, resp, Result.ERR_BadData, e.getMessage());
+ } catch (Exception e) {
+ context.error(trans, resp, Result.ERR_General, e.getMessage());
+ }
+ }
+ });
+ }
+
+ public static void initDefault(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
- /**
- * "login" url
- */
- gwAPI.route(HttpMethods.GET,"/login",API.VOID,new LocateCode(facade,"Access Login GUI for AAF", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- try {
- redirect(trans, req, resp, context,
- gwAPI.getGUILocator(),
- "login");
- } catch (LocatorException e) {
- context.error(trans, resp, Result.ERR_BadData, e.getMessage());
- } catch (Exception e) {
- context.error(trans, resp, Result.ERR_General, e.getMessage());
- }
- }
- });
+ /**
+ * "login" url
+ */
+ gwAPI.route(HttpMethods.GET,"/login",API.VOID,new LocateCode(facade,"Access Login GUI for AAF", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ try {
+ redirect(trans, req, resp, context,
+ gwAPI.getGUILocator(),
+ "login");
+ } catch (LocatorException e) {
+ context.error(trans, resp, Result.ERR_BadData, e.getMessage());
+ } catch (Exception e) {
+ context.error(trans, resp, Result.ERR_General, e.getMessage());
+ }
+ }
+ });
-
- /**
- * Default URL
- */
- gwAPI.route(HttpMethods.GET,"/",API.VOID,new LocateCode(facade,"Access GUI for AAF", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- try {
- redirect(trans, req, resp, context,
- gwAPI.getGUILocator(),
- "gui/home");
- } catch (Exception e) {
- context.error(trans, resp, Result.ERR_General, e.getMessage());
- }
- }
- });
-
- /**
- * Configuration
- */
- gwAPI.route(HttpMethods.GET,"/configure/:id/:type",API.CONFIG,new LocateCode(facade,"Deliver Configuration Properties to AAF", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- try {
- Result<Void> r = facade.getConfig(trans, req, resp, pathParam(req, ":id"),pathParam(req,":type"));
- switch(r.status) {
- case OK:
- resp.setStatus(HttpStatus.OK_200);
- break;
- default:
- context.error(trans,resp,r);
- }
+
+ /**
+ * Default URL
+ */
+ gwAPI.route(HttpMethods.GET,"/",API.VOID,new LocateCode(facade,"Access GUI for AAF", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ try {
+ redirect(trans, req, resp, context,
+ gwAPI.getGUILocator(),
+ "gui/home");
+ } catch (Exception e) {
+ context.error(trans, resp, Result.ERR_General, e.getMessage());
+ }
+ }
+ });
+
+ /**
+ * Configuration
+ */
+ gwAPI.route(HttpMethods.GET,"/configure/:id/:type",API.CONFIG,new LocateCode(facade,"Deliver Configuration Properties to AAF", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ try {
+ Result<Void> r = facade.getConfig(trans, req, resp, pathParam(req, ":id"),pathParam(req,":type"));
+ switch(r.status) {
+ case OK:
+ resp.setStatus(HttpStatus.OK_200);
+ break;
+ default:
+ context.error(trans,resp,r);
+ }
- } catch (Exception e) {
- context.error(trans, resp, Result.ERR_General, e.getMessage());
- }
- }
- });
- }
+ } catch (Exception e) {
+ context.error(trans, resp, Result.ERR_General, e.getMessage());
+ }
+ }
+ });
+ }
- private static void redirect(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, LocateFacade context, Locator<URI> loc, String path) throws IOException {
- try {
- if(loc.hasItems()) {
- Item item = loc.best();
- URI uri = loc.get(item);
- StringBuilder redirectURL = new StringBuilder(uri.toString());
- redirectURL.append('/');
- redirectURL.append(path);
- String str = req.getQueryString();
- if(str!=null) {
- redirectURL.append('?');
- redirectURL.append(str);
- }
- trans.info().log("Redirect to",redirectURL);
- resp.sendRedirect(redirectURL.toString());
- } else {
- context.error(trans, resp, Result.err(Result.ERR_NotFound,"No Locations found for redirection"));
- }
- } catch (LocatorException e) {
- context.error(trans, resp, Result.err(Result.ERR_NotFound,"No Endpoints found for %s",req.getPathInfo()));
- }
- }
+ private static void redirect(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, LocateFacade context, Locator<URI> loc, String path) throws IOException {
+ try {
+ if(loc.hasItems()) {
+ Item item = loc.best();
+ URI uri = loc.get(item);
+ StringBuilder redirectURL = new StringBuilder(uri.toString());
+ redirectURL.append('/');
+ redirectURL.append(path);
+ String str = req.getQueryString();
+ if(str!=null) {
+ redirectURL.append('?');
+ redirectURL.append(str);
+ }
+ trans.info().log("Redirect to",redirectURL);
+ resp.sendRedirect(redirectURL.toString());
+ } else {
+ context.error(trans, resp, Result.err(Result.ERR_NotFound,"No Locations found for redirection"));
+ }
+ } catch (LocatorException e) {
+ context.error(trans, resp, Result.err(Result.ERR_NotFound,"No Endpoints found for %s",req.getPathInfo()));
+ }
+ }
- private static class User {
- public final int code;
- public final String resp;
-
- public User(int code, String resp) {
- this.code = code;
- this.resp = resp;
- }
- }
+ private static class User {
+ public final int code;
+ public final String resp;
+
+ public User(int code, String resp) {
+ this.code = code;
+ this.resp = resp;
+ }
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Api.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Api.java
index 8e3fab56..1e60e796 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Api.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Api.java
@@ -42,56 +42,56 @@ import org.onap.aaf.cadi.Symm;
*
*/
public class API_Api {
- /**
- * Normal Init level APIs
- *
- * @param gwAPI
- * @param facade
- * @throws Exception
- */
- public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
- ////////
- // Overall APIs
- ///////
- gwAPI.route(HttpMethods.GET,"/api",API.VOID,new LocateCode(facade,"Document API", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- Result<Void> r = context.getAPI(trans,resp,gwAPI);
- switch(r.status) {
- case OK:
- resp.setStatus(HttpStatus.OK_200);
- break;
- default:
- context.error(trans,resp,r);
- }
+ /**
+ * Normal Init level APIs
+ *
+ * @param gwAPI
+ * @param facade
+ * @throws Exception
+ */
+ public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
+ ////////
+ // Overall APIs
+ ///////
+ gwAPI.route(HttpMethods.GET,"/api",API.VOID,new LocateCode(facade,"Document API", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ Result<Void> r = context.getAPI(trans,resp,gwAPI);
+ switch(r.status) {
+ case OK:
+ resp.setStatus(HttpStatus.OK_200);
+ break;
+ default:
+ context.error(trans,resp,r);
+ }
- }
- });
+ }
+ });
- ////////
- // Overall Examples
- ///////
- gwAPI.route(HttpMethods.GET,"/api/example/*",API.VOID,new LocateCode(facade,"Document API", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- String pathInfo = req.getPathInfo();
- int question = pathInfo.lastIndexOf('?');
-
- pathInfo = pathInfo.substring(13, question<0?pathInfo.length():question);// IMPORTANT, this is size of "/api/example/"
- String nameOrContextType=Symm.base64noSplit.decode(pathInfo);
-// String param = req.getParameter("optional");
- Result<Void> r = context.getAPIExample(trans,resp,nameOrContextType,
- question>=0 && "optional=true".equalsIgnoreCase(req.getPathInfo().substring(question+1))
- );
- switch(r.status) {
- case OK:
- resp.setStatus(HttpStatus.OK_200);
- break;
- default:
- context.error(trans,resp,r);
- }
- }
- });
+ ////////
+ // Overall Examples
+ ///////
+ gwAPI.route(HttpMethods.GET,"/api/example/*",API.VOID,new LocateCode(facade,"Document API", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ String pathInfo = req.getPathInfo();
+ int question = pathInfo.lastIndexOf('?');
+
+ pathInfo = pathInfo.substring(13, question<0?pathInfo.length():question);// IMPORTANT, this is size of "/api/example/"
+ String nameOrContextType=Symm.base64noSplit.decode(pathInfo);
+// String param = req.getParameter("optional");
+ Result<Void> r = context.getAPIExample(trans,resp,nameOrContextType,
+ question>=0 && "optional=true".equalsIgnoreCase(req.getPathInfo().substring(question+1))
+ );
+ switch(r.status) {
+ case OK:
+ resp.setStatus(HttpStatus.OK_200);
+ break;
+ default:
+ context.error(trans,resp,r);
+ }
+ }
+ });
- }
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Find.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Find.java
index 27bd8c3a..7ff1fceb 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Find.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Find.java
@@ -44,89 +44,89 @@ import org.onap.aaf.misc.env.util.Split;
*
*/
public class API_Find {
- /**
- * Normal Init level APIs
- *
- * @param gwAPI
- * @param facade
- * @throws Exception
- */
- public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
- ////////
- // Overall APIs
- ///////
-
- final LocateCode locationInfo = new LocateCode(facade,"Location Information", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- String service = pathParam(req, ":service");
- String version = pathParam(req, ":version");
- String other = pathParam(req, ":other");
- if(service.indexOf(':')>=0) {
- String split[] = Split.split(':', service);
- switch(split.length) {
- case 3:
- other=split[2];
- case 2:
- version = split[1];
- service = split[0];
- }
- }
- service=Define.varReplace(service);
- Result<Void> r = context.getEndpoints(trans,resp,
- req.getPathInfo(), // use as Key
- service,version,other
- );
- switch(r.status) {
- case OK:
- resp.setStatus(HttpStatus.OK_200);
- break;
- default:
- context.error(trans,resp,r);
- }
- }
- };
+ /**
+ * Normal Init level APIs
+ *
+ * @param gwAPI
+ * @param facade
+ * @throws Exception
+ */
+ public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
+ ////////
+ // Overall APIs
+ ///////
+
+ final LocateCode locationInfo = new LocateCode(facade,"Location Information", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ String service = pathParam(req, ":service");
+ String version = pathParam(req, ":version");
+ String other = pathParam(req, ":other");
+ if(service.indexOf(':')>=0) {
+ String split[] = Split.split(':', service);
+ switch(split.length) {
+ case 3:
+ other=split[2];
+ case 2:
+ version = split[1];
+ service = split[0];
+ }
+ }
+ service=Define.varReplace(service);
+ Result<Void> r = context.getEndpoints(trans,resp,
+ req.getPathInfo(), // use as Key
+ service,version,other
+ );
+ switch(r.status) {
+ case OK:
+ resp.setStatus(HttpStatus.OK_200);
+ break;
+ default:
+ context.error(trans,resp,r);
+ }
+ }
+ };
- gwAPI.route(HttpMethods.GET,"/locate/:service/:version",API.ENDPOINTS,locationInfo);
- gwAPI.route(HttpMethods.GET,"/locate/:service/:version/:other",API.ENDPOINTS,locationInfo);
- gwAPI.route(HttpMethods.GET,"/locate/:service",API.ENDPOINTS,locationInfo);
-
-
- gwAPI.route(HttpMethods.GET,"/download/agent", API.VOID, new LocateCode(facade,"Redirect to latest Agent",false) {
- @Override
- public void handle(AuthzTrans arg0, HttpServletRequest arg1, HttpServletResponse arg2) throws Exception {
- }
- });
+ gwAPI.route(HttpMethods.GET,"/locate/:service/:version",API.ENDPOINTS,locationInfo);
+ gwAPI.route(HttpMethods.GET,"/locate/:service/:version/:other",API.ENDPOINTS,locationInfo);
+ gwAPI.route(HttpMethods.GET,"/locate/:service",API.ENDPOINTS,locationInfo);
+
+
+ gwAPI.route(HttpMethods.GET,"/download/agent", API.VOID, new LocateCode(facade,"Redirect to latest Agent",false) {
+ @Override
+ public void handle(AuthzTrans arg0, HttpServletRequest arg1, HttpServletResponse arg2) throws Exception {
+ }
+ });
- gwAPI.route(HttpMethods.PUT,"/registration",API.MGMT_ENDPOINTS,new LocateCode(facade,"Put Location Information", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- Result<Void> r = context.putMgmtEndpoints(trans,req,resp);
- switch(r.status) {
- case OK:
- resp.setStatus(HttpStatus.OK_200);
- break;
- default:
- context.error(trans,resp,r);
- }
+ gwAPI.route(HttpMethods.PUT,"/registration",API.MGMT_ENDPOINTS,new LocateCode(facade,"Put Location Information", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ Result<Void> r = context.putMgmtEndpoints(trans,req,resp);
+ switch(r.status) {
+ case OK:
+ resp.setStatus(HttpStatus.OK_200);
+ break;
+ default:
+ context.error(trans,resp,r);
+ }
- }
- });
+ }
+ });
- gwAPI.route(HttpMethods.DELETE,"/registration",API.MGMT_ENDPOINTS,new LocateCode(facade,"Remove Location Information", true) {
- @Override
- public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- Result<Void> r = context.removeMgmtEndpoints(trans,req,resp);
- switch(r.status) {
- case OK:
- resp.setStatus(HttpStatus.OK_200);
- break;
- default:
- context.error(trans,resp,r);
- }
+ gwAPI.route(HttpMethods.DELETE,"/registration",API.MGMT_ENDPOINTS,new LocateCode(facade,"Remove Location Information", true) {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ Result<Void> r = context.removeMgmtEndpoints(trans,req,resp);
+ switch(r.status) {
+ case OK:
+ resp.setStatus(HttpStatus.OK_200);
+ break;
+ default:
+ context.error(trans,resp,r);
+ }
- }
- });
+ }
+ });
- }
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Proxy.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Proxy.java
index d2e4583c..8bdf479f 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Proxy.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_Proxy.java
@@ -52,112 +52,112 @@ import org.onap.aaf.misc.env.TimeTaken;
*/
public class API_Proxy {
- /**
- * Normal Init level APIs
- *
- * @param gwAPI
- * @param facade
- * @throws Exception
- */
- public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
-
- String aafurl = gwAPI.access.getProperty(Config.AAF_URL,null);
- if(aafurl==null) {
- } else {
- ////////
- // Transferring APIs
- // But DO NOT transfer BasicAuth case... wastes resources.
- ///////
- final BasicAuthCode bac = new BasicAuthCode(gwAPI.aafAuthn,facade);
-
- gwAPI.routeAll(HttpMethods.GET,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy GET", true) {
- @Override
- public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
- if("/proxy/authn/basicAuth".equals(req.getPathInfo()) && !(req.getUserPrincipal() instanceof OAuth2Principal)) {
- bac.handle(trans, req, resp);
- } else {
- TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
- try {
- gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
- @Override
- public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
- Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
- ft.get(10000); // Covers return codes and err messages
- return null;
- }
- });
-
- } catch (CadiException | APIException e) {
- trans.error().log(e);
- } finally {
- tt.done();
- }
- }
- }
- });
-
- gwAPI.routeAll(HttpMethods.POST,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy POST", true) {
- @Override
- public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
- TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
- try {
- gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
- @Override
- public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
- Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.CREATED_201);
- ft.get(10000); // Covers return codes and err messages
- return null;
- }
- });
- } catch (CadiException | APIException e) {
- trans.error().log(e);
- } finally {
- tt.done();
- }
- }
- });
-
- gwAPI.routeAll(HttpMethods.PUT,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy PUT", true) {
- @Override
- public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
- TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
- try {
- gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
- @Override
- public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
- Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
- ft.get(10000); // Covers return codes and err messages
- return null;
- }
- });
- } catch (CadiException | APIException e) {
- trans.error().log(e);
- } finally {
- tt.done();
- }
- }
- });
-
- gwAPI.routeAll(HttpMethods.DELETE,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy DELETE", true) {
- @Override
- public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
- TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
- try {
- gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
- @Override
- public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
- Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
- ft.get(10000); // Covers return codes and err messages
- return null;
- }
- });
- } catch (CadiException | APIException e) {
- trans.error().log(e);
- } finally {
- tt.done();
- }
- }
- });
- }
- }
+ /**
+ * Normal Init level APIs
+ *
+ * @param gwAPI
+ * @param facade
+ * @throws Exception
+ */
+ public static void init(final AAF_Locate gwAPI, LocateFacade facade) throws Exception {
+
+ String aafurl = gwAPI.access.getProperty(Config.AAF_URL,null);
+ if(aafurl==null) {
+ } else {
+ ////////
+ // Transferring APIs
+ // But DO NOT transfer BasicAuth case... wastes resources.
+ ///////
+ final BasicAuthCode bac = new BasicAuthCode(gwAPI.aafAuthn,facade);
+
+ gwAPI.routeAll(HttpMethods.GET,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy GET", true) {
+ @Override
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
+ if("/proxy/authn/basicAuth".equals(req.getPathInfo()) && !(req.getUserPrincipal() instanceof OAuth2Principal)) {
+ bac.handle(trans, req, resp);
+ } else {
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
+ try {
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
+ @Override
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
+ ft.get(10000); // Covers return codes and err messages
+ return null;
+ }
+ });
+
+ } catch (CadiException | APIException e) {
+ trans.error().log(e);
+ } finally {
+ tt.done();
+ }
+ }
+ }
+ });
+
+ gwAPI.routeAll(HttpMethods.POST,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy POST", true) {
+ @Override
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
+ try {
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
+ @Override
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.CREATED_201);
+ ft.get(10000); // Covers return codes and err messages
+ return null;
+ }
+ });
+ } catch (CadiException | APIException e) {
+ trans.error().log(e);
+ } finally {
+ tt.done();
+ }
+ }
+ });
+
+ gwAPI.routeAll(HttpMethods.PUT,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy PUT", true) {
+ @Override
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
+ try {
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
+ @Override
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
+ ft.get(10000); // Covers return codes and err messages
+ return null;
+ }
+ });
+ } catch (CadiException | APIException e) {
+ trans.error().log(e);
+ } finally {
+ tt.done();
+ }
+ }
+ });
+
+ gwAPI.routeAll(HttpMethods.DELETE,"/proxy/:path*",API.VOID,new LocateCode(facade,"Proxy DELETE", true) {
+ @Override
+ public void handle(final AuthzTrans trans, final HttpServletRequest req, final HttpServletResponse resp) throws Exception {
+ TimeTaken tt = trans.start("Forward to AAF Service", Env.REMOTE);
+ try {
+ gwAPI.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
+ @Override
+ public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
+ Future<Void> ft = client.transfer(req,resp,pathParam(req, ":path"),HttpStatus.OK_200);
+ ft.get(10000); // Covers return codes and err messages
+ return null;
+ }
+ });
+ } catch (CadiException | APIException e) {
+ trans.error().log(e);
+ } finally {
+ tt.done();
+ }
+ }
+ });
+ }
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java
index 8fb719fe..4a2afa58 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java
@@ -37,79 +37,79 @@ import org.onap.aaf.auth.rserv.RServlet;
public interface LocateFacade {
///////////////////// STANDARD ELEMENTS //////////////////
- /**
- * @param trans
- * @param response
- * @param result
- */
- void error(AuthzTrans trans, HttpServletResponse response, Result<?> result);
+ /**
+ * @param trans
+ * @param response
+ * @param result
+ */
+ void error(AuthzTrans trans, HttpServletResponse response, Result<?> result);
- /**
- *
- * @param trans
- * @param response
- * @param status
- */
- void error(AuthzTrans trans, HttpServletResponse response, int status, String msg, String ... detail);
+ /**
+ *
+ * @param trans
+ * @param response
+ * @param status
+ */
+ void error(AuthzTrans trans, HttpServletResponse response, int status, String msg, String ... detail);
- /**
- *
- * @param trans
- * @param resp
- * @param rservlet
- * @return
- */
- public Result<Void> getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet<AuthzTrans> rservlet);
+ /**
+ *
+ * @param trans
+ * @param resp
+ * @param rservlet
+ * @return
+ */
+ public Result<Void> getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet<AuthzTrans> rservlet);
- /**
- *
- * @param trans
- * @param resp
- * @param typeCode
- * @param optional
- * @return
- */
- public abstract Result<Void> getAPIExample(AuthzTrans trans, HttpServletResponse resp, String typeCode, boolean optional);
+ /**
+ *
+ * @param trans
+ * @param resp
+ * @param typeCode
+ * @param optional
+ * @return
+ */
+ public abstract Result<Void> getAPIExample(AuthzTrans trans, HttpServletResponse resp, String typeCode, boolean optional);
- /**
- *
- * @param trans
- * @param resp
- * @param service
- * @param version
- * @param other
- * @param string
- * @return
- */
- public abstract Result<Void> getEndpoints(AuthzTrans trans, HttpServletResponse resp, String key,
- String service, String version, String other);
+ /**
+ *
+ * @param trans
+ * @param resp
+ * @param service
+ * @param version
+ * @param other
+ * @param string
+ * @return
+ */
+ public abstract Result<Void> getEndpoints(AuthzTrans trans, HttpServletResponse resp, String key,
+ String service, String version, String other);
- /**
- *
- * @param trans
- * @param req
- * @param resp
- * @return
- */
- public abstract Result<Void> putMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp);
+ /**
+ *
+ * @param trans
+ * @param req
+ * @param resp
+ * @return
+ */
+ public abstract Result<Void> putMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp);
- /**
- *
- * @param trans
- * @param req
- * @param resp
- * @return
- */
- public abstract Result<Void> removeMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp);
+ /**
+ *
+ * @param trans
+ * @param req
+ * @param resp
+ * @return
+ */
+ public abstract Result<Void> removeMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp);
- /**
- *
- * @param trans
- * @param req
- * @param resp
- * @return
- */
- public Result<Void> getConfig(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String id, String type);
+ /**
+ *
+ * @param trans
+ * @param req
+ * @param resp
+ * @return
+ */
+ public Result<Void> getConfig(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String id, String type);
} \ No newline at end of file
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java
index 84fc20a5..0bb9fbdb 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java
@@ -36,14 +36,14 @@ import locate_local.v1_0.Error;;
public class LocateFacadeFactory {
- public static LocateFacade_1_1 v1_1(AuthzEnv env, AAF_Locate locate, AuthzTrans trans, Data.TYPE type) throws APIException {
- return new LocateFacade_1_1(
- env,
- new LocateServiceImpl<
- InRequest,
- Out,
- Error>(trans,locate,new Mapper_1_1()),
- type);
- }
+ public static LocateFacade_1_1 v1_1(AuthzEnv env, AAF_Locate locate, AuthzTrans trans, Data.TYPE type) throws APIException {
+ return new LocateFacade_1_1(
+ env,
+ new LocateServiceImpl<
+ InRequest,
+ Out,
+ Error>(trans,locate,new Mapper_1_1()),
+ type);
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java
index f655657b..f41fcd91 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java
@@ -73,7 +73,7 @@ import locate_local.v1_0.Api;
* 1) Interact with the Service Implementation (which might be supported by various kinds of Backend Storage)
* 2) Validate incoming data (if applicable)
* 3) Convert the Service response into the right Format, and mark the Content Type
- * a) In the future, we may support multiple Response Formats, aka JSON or XML, based on User Request.
+ * a) In the future, we may support multiple Response Formats, aka JSON or XML, based on User Request.
* 4) Log Service info, warnings and exceptions as necessary
* 5) When asked by the API layer, this will create and write Error content to the OutputStream
*
@@ -84,336 +84,336 @@ import locate_local.v1_0.Api;
*
*/
public abstract class LocateFacadeImpl<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIGURATION,ERROR> extends FacadeImpl implements LocateFacade
- {
- private LocateService<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIGURATION,ERROR> service;
+ {
+ private LocateService<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIGURATION,ERROR> service;
- private final RosettaDF<ERROR> errDF;
- private final RosettaDF<Api> apiDF;
- private final RosettaDF<ENDPOINTS> epDF;
- private final RosettaDF<MGMT_ENDPOINTS> mepDF;
- private final RosettaDF<CONFIGURATION> confDF;
+ private final RosettaDF<ERROR> errDF;
+ private final RosettaDF<Api> apiDF;
+ private final RosettaDF<ENDPOINTS> epDF;
+ private final RosettaDF<MGMT_ENDPOINTS> mepDF;
+ private final RosettaDF<CONFIGURATION> confDF;
- private static long cacheClear = 0L, emptyCheck=0L;
- private final static Map<String,String> epsCache = new HashMap<>(); // protected manually, in getEndpoints
+ private static long cacheClear = 0L, emptyCheck=0L;
+ private final static Map<String,String> epsCache = new HashMap<>(); // protected manually, in getEndpoints
- public LocateFacadeImpl(AuthzEnv env, LocateService<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIGURATION,ERROR> service, Data.TYPE dataType) throws APIException {
- this.service = service;
- (errDF = env.newDataFactory(mapper().getClass(API.ERROR))).in(dataType).out(dataType);
- (apiDF = env.newDataFactory(Api.class)).in(dataType).out(dataType);
- (epDF = env.newDataFactory(mapper().getClass(API.ENDPOINTS))).in(dataType).out(dataType);
- (mepDF = env.newDataFactory(mapper().getClass(API.MGMT_ENDPOINTS))).in(dataType).out(dataType);
- (confDF = env.newDataFactory(mapper().getClass(API.CONFIG))).in(dataType).out(dataType);
- }
-
- public Mapper<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIGURATION,ERROR> mapper() {
- return service.mapper();
- }
-
- /* (non-Javadoc)
- * @see com.att.authz.facade.AuthzFacade#error(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, int)
- *
- * Note: Conforms to AT&T TSS RESTful Error Structure
- */
- @Override
- public void error(AuthzTrans trans, HttpServletResponse response, Result<?> result) {
- String msg = result.details==null?"":result.details.trim();
- String[] detail;
- if(result.variables==null) {
- detail = new String[1];
- } else {
- int l = result.variables.length;
- detail=new String[l+1];
- System.arraycopy(result.variables, 0, detail, 1, l);
- }
- error(trans, response, result.status,msg,detail);
- }
-
- @Override
- public void error(AuthzTrans trans, HttpServletResponse response, int status, String msg, String ... _detail) {
- String[] detail = _detail;
- if(detail.length==0) {
- detail=new String[1];
- }
- boolean hidemsg = false;
- String msgId;
- switch(status) {
- case 202:
- case ERR_ActionNotCompleted:
- msgId = "SVC1202";
- detail[0] = "Accepted, Action not complete";
- response.setStatus(/*httpstatus=*/202);
- break;
+ public LocateFacadeImpl(AuthzEnv env, LocateService<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIGURATION,ERROR> service, Data.TYPE dataType) throws APIException {
+ this.service = service;
+ (errDF = env.newDataFactory(mapper().getClass(API.ERROR))).in(dataType).out(dataType);
+ (apiDF = env.newDataFactory(Api.class)).in(dataType).out(dataType);
+ (epDF = env.newDataFactory(mapper().getClass(API.ENDPOINTS))).in(dataType).out(dataType);
+ (mepDF = env.newDataFactory(mapper().getClass(API.MGMT_ENDPOINTS))).in(dataType).out(dataType);
+ (confDF = env.newDataFactory(mapper().getClass(API.CONFIG))).in(dataType).out(dataType);
+ }
+
+ public Mapper<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIGURATION,ERROR> mapper() {
+ return service.mapper();
+ }
+
+ /* (non-Javadoc)
+ * @see com.att.authz.facade.AuthzFacade#error(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, int)
+ *
+ * Note: Conforms to AT&T TSS RESTful Error Structure
+ */
+ @Override
+ public void error(AuthzTrans trans, HttpServletResponse response, Result<?> result) {
+ String msg = result.details==null?"":result.details.trim();
+ String[] detail;
+ if(result.variables==null) {
+ detail = new String[1];
+ } else {
+ int l = result.variables.length;
+ detail=new String[l+1];
+ System.arraycopy(result.variables, 0, detail, 1, l);
+ }
+ error(trans, response, result.status,msg,detail);
+ }
+
+ @Override
+ public void error(AuthzTrans trans, HttpServletResponse response, int status, String msg, String ... _detail) {
+ String[] detail = _detail;
+ if(detail.length==0) {
+ detail=new String[1];
+ }
+ boolean hidemsg = false;
+ String msgId;
+ switch(status) {
+ case 202:
+ case ERR_ActionNotCompleted:
+ msgId = "SVC1202";
+ detail[0] = "Accepted, Action not complete";
+ response.setStatus(/*httpstatus=*/202);
+ break;
- case 403:
- case ERR_Policy:
- case ERR_Security:
- case ERR_Denied:
- msgId = "SVC1403";
- detail[0] = "Forbidden";
- response.setStatus(/*httpstatus=*/403);
- break;
-
- case 404:
- case ERR_NotFound:
- msgId = "SVC1404";
- detail[0] = "Not Found";
- response.setStatus(/*httpstatus=*/404);
- break;
+ case 403:
+ case ERR_Policy:
+ case ERR_Security:
+ case ERR_Denied:
+ msgId = "SVC1403";
+ detail[0] = "Forbidden";
+ response.setStatus(/*httpstatus=*/403);
+ break;
+
+ case 404:
+ case ERR_NotFound:
+ msgId = "SVC1404";
+ detail[0] = "Not Found";
+ response.setStatus(/*httpstatus=*/404);
+ break;
- case 406:
- case ERR_BadData:
- msgId="SVC1406";
- detail[0] = "Not Acceptable";
- response.setStatus(/*httpstatus=*/406);
- break;
-
- case 409:
- case ERR_ConflictAlreadyExists:
- msgId = "SVC1409";
- detail[0] = "Conflict Already Exists";
- response.setStatus(/*httpstatus=*/409);
- break;
-
- case 501:
- case ERR_NotImplemented:
- msgId = "SVC1501";
- detail[0] = "Not Implemented";
- response.setStatus(/*httpstatus=*/501);
- break;
-
- default:
- msgId = "SVC1500";
- detail[0] = "General Service Error";
- response.setStatus(/*httpstatus=*/500);
- hidemsg = true;
- break;
- }
+ case 406:
+ case ERR_BadData:
+ msgId="SVC1406";
+ detail[0] = "Not Acceptable";
+ response.setStatus(/*httpstatus=*/406);
+ break;
+
+ case 409:
+ case ERR_ConflictAlreadyExists:
+ msgId = "SVC1409";
+ detail[0] = "Conflict Already Exists";
+ response.setStatus(/*httpstatus=*/409);
+ break;
+
+ case 501:
+ case ERR_NotImplemented:
+ msgId = "SVC1501";
+ detail[0] = "Not Implemented";
+ response.setStatus(/*httpstatus=*/501);
+ break;
+
+ default:
+ msgId = "SVC1500";
+ detail[0] = "General Service Error";
+ response.setStatus(/*httpstatus=*/500);
+ hidemsg = true;
+ break;
+ }
- try {
- StringBuilder holder = new StringBuilder();
- ERROR em = mapper().errorFromMessage(holder,msgId,msg,detail);
- trans.checkpoint(
- "ErrResp [" +
- msgId +
- "] " +
- holder.toString(),
- Env.ALWAYS);
- if(hidemsg) {
- holder.setLength(0);
- em = mapper().errorFromMessage(holder, msgId, "Server had an issue processing this request");
- }
- errDF.newData(trans).load(em).to(response.getOutputStream());
-
- } catch (Exception e) {
- trans.error().log(e,"unable to send response for",msg);
- }
- }
-
- /* (non-Javadoc)
- * @see com.att.authz.facade.AuthzFacade#getAPI(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse)
- */
- public final static String API_REPORT = "apiReport";
- @Override
- public Result<Void> getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet<AuthzTrans> rservlet) {
- TimeTaken tt = trans.start(API_REPORT, Env.SUB);
- try {
- Api api = new Api();
- Api.Route ar;
- Method[] meths = LocateServiceImpl.class.getDeclaredMethods();
- for(RouteReport rr : rservlet.routeReport()) {
- api.getRoute().add(ar = new Api.Route());
- ar.setMeth(rr.meth.name());
- ar.setPath(rr.path);
- ar.setDesc(rr.desc);
- ar.getContentType().addAll(rr.contextTypes);
- for(Method m : meths) {
- ApiDoc ad;
- if((ad = m.getAnnotation(ApiDoc.class))!=null &&
- rr.meth.equals(ad.method()) &&
- rr.path.equals(ad.path())) {
- for(String param : ad.params()) {
- ar.getParam().add(param);
- }
- for(String text : ad.text()) {
- ar.getComments().add(text);
- }
- ar.setExpected(ad.expectedCode());
- for(int ec : ad.errorCodes()) {
- ar.getExplicitErr().add(ec);
- }
- }
- }
- }
- apiDF.newData(trans).load(api).to(resp.getOutputStream());
- setContentType(resp,apiDF.getOutType());
- return Result.ok();
+ try {
+ StringBuilder holder = new StringBuilder();
+ ERROR em = mapper().errorFromMessage(holder,msgId,msg,detail);
+ trans.checkpoint(
+ "ErrResp [" +
+ msgId +
+ "] " +
+ holder.toString(),
+ Env.ALWAYS);
+ if(hidemsg) {
+ holder.setLength(0);
+ em = mapper().errorFromMessage(holder, msgId, "Server had an issue processing this request");
+ }
+ errDF.newData(trans).load(em).to(response.getOutputStream());
+
+ } catch (Exception e) {
+ trans.error().log(e,"unable to send response for",msg);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.att.authz.facade.AuthzFacade#getAPI(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse)
+ */
+ public final static String API_REPORT = "apiReport";
+ @Override
+ public Result<Void> getAPI(AuthzTrans trans, HttpServletResponse resp, RServlet<AuthzTrans> rservlet) {
+ TimeTaken tt = trans.start(API_REPORT, Env.SUB);
+ try {
+ Api api = new Api();
+ Api.Route ar;
+ Method[] meths = LocateServiceImpl.class.getDeclaredMethods();
+ for(RouteReport rr : rservlet.routeReport()) {
+ api.getRoute().add(ar = new Api.Route());
+ ar.setMeth(rr.meth.name());
+ ar.setPath(rr.path);
+ ar.setDesc(rr.desc);
+ ar.getContentType().addAll(rr.contextTypes);
+ for(Method m : meths) {
+ ApiDoc ad;
+ if((ad = m.getAnnotation(ApiDoc.class))!=null &&
+ rr.meth.equals(ad.method()) &&
+ rr.path.equals(ad.path())) {
+ for(String param : ad.params()) {
+ ar.getParam().add(param);
+ }
+ for(String text : ad.text()) {
+ ar.getComments().add(text);
+ }
+ ar.setExpected(ad.expectedCode());
+ for(int ec : ad.errorCodes()) {
+ ar.getExplicitErr().add(ec);
+ }
+ }
+ }
+ }
+ apiDF.newData(trans).load(api).to(resp.getOutputStream());
+ setContentType(resp,apiDF.getOutType());
+ return Result.ok();
- } catch (Exception e) {
- trans.error().log(e,IN,API_REPORT);
- return Result.err(e);
- } finally {
- tt.done();
- }
- }
-
- public final static String API_EXAMPLE = "apiExample";
- /* (non-Javadoc)
- * @see com.att.authz.facade.AuthzFacade#getAPIExample(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String)
- */
- @Override
- public Result<Void> getAPIExample(AuthzTrans trans, HttpServletResponse resp, String nameOrContentType, boolean optional) {
- TimeTaken tt = trans.start(API_EXAMPLE, Env.SUB);
- try {
- String content =Examples.print(apiDF.getEnv(), nameOrContentType, optional);
- resp.getOutputStream().print(content);
- setContentType(resp,content.contains("<?xml")?TYPE.XML:TYPE.JSON);
- return Result.ok();
- } catch (Exception e) {
- trans.error().log(e,IN,API_EXAMPLE);
- return Result.err(Result.ERR_NotImplemented,e.getMessage());
- } finally {
- tt.done();
- }
- }
+ } catch (Exception e) {
+ trans.error().log(e,IN,API_REPORT);
+ return Result.err(e);
+ } finally {
+ tt.done();
+ }
+ }
+
+ public final static String API_EXAMPLE = "apiExample";
+ /* (non-Javadoc)
+ * @see com.att.authz.facade.AuthzFacade#getAPIExample(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String)
+ */
+ @Override
+ public Result<Void> getAPIExample(AuthzTrans trans, HttpServletResponse resp, String nameOrContentType, boolean optional) {
+ TimeTaken tt = trans.start(API_EXAMPLE, Env.SUB);
+ try {
+ String content =Examples.print(apiDF.getEnv(), nameOrContentType, optional);
+ resp.getOutputStream().print(content);
+ setContentType(resp,content.contains("<?xml")?TYPE.XML:TYPE.JSON);
+ return Result.ok();
+ } catch (Exception e) {
+ trans.error().log(e,IN,API_EXAMPLE);
+ return Result.err(Result.ERR_NotImplemented,e.getMessage());
+ } finally {
+ tt.done();
+ }
+ }
- public final static String GET_ENDPOINTS = "getEndpoints";
- private final static Object LOCK = new Object();
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.facade.GwFacade#getEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String)
- */
- @Override
- public Result<Void> getEndpoints(AuthzTrans trans, HttpServletResponse resp, String key, String service, String version, String other) {
- TimeTaken tt = trans.start(GET_ENDPOINTS, Env.SUB);
- try {
- String output=null;
- long temp=System.currentTimeMillis();
- synchronized(LOCK) {
- if(cacheClear<temp) {
- epsCache.clear();
- cacheClear = temp+1000*60*2; // 2 mins standard cache clear
- } else {
- output = epsCache.get(key);
- if("{}".equals(output) && emptyCheck<temp) {
- output = null;
- emptyCheck = temp+5000; // 5 second check
- }
- }
- }
- if(output==null) {
- Result<ENDPOINTS> reps = this.service.getEndPoints(trans,service,version,other);
- if(reps.notOK()) {
- return Result.err(reps);
- } else {
- output = epDF.newData(trans).load(reps.value).asString();
- synchronized(LOCK) {
- epsCache.put(key, output);
- }
- }
- }
- resp.getOutputStream().println(output);
- setContentType(resp,epDF.getOutType());
- return Result.ok();
- } catch (Exception e) {
- trans.error().log(e,IN,API_EXAMPLE);
- return Result.err(Result.ERR_NotImplemented,e.getMessage());
- } finally {
- tt.done();
- }
- }
+ public final static String GET_ENDPOINTS = "getEndpoints";
+ private final static Object LOCK = new Object();
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.facade.GwFacade#getEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public Result<Void> getEndpoints(AuthzTrans trans, HttpServletResponse resp, String key, String service, String version, String other) {
+ TimeTaken tt = trans.start(GET_ENDPOINTS, Env.SUB);
+ try {
+ String output=null;
+ long temp=System.currentTimeMillis();
+ synchronized(LOCK) {
+ if(cacheClear<temp) {
+ epsCache.clear();
+ cacheClear = temp+1000*60*2; // 2 mins standard cache clear
+ } else {
+ output = epsCache.get(key);
+ if("{}".equals(output) && emptyCheck<temp) {
+ output = null;
+ emptyCheck = temp+5000; // 5 second check
+ }
+ }
+ }
+ if(output==null) {
+ Result<ENDPOINTS> reps = this.service.getEndPoints(trans,service,version,other);
+ if(reps.notOK()) {
+ return Result.err(reps);
+ } else {
+ output = epDF.newData(trans).load(reps.value).asString();
+ synchronized(LOCK) {
+ epsCache.put(key, output);
+ }
+ }
+ }
+ resp.getOutputStream().println(output);
+ setContentType(resp,epDF.getOutType());
+ return Result.ok();
+ } catch (Exception e) {
+ trans.error().log(e,IN,API_EXAMPLE);
+ return Result.err(Result.ERR_NotImplemented,e.getMessage());
+ } finally {
+ tt.done();
+ }
+ }
- private static final String PUT_MGMT_ENDPOINTS = "Put Mgmt Endpoints";
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.facade.GwFacade#putMgmtEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
- */
- @Override
- public Result<Void> putMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) {
- TimeTaken tt = trans.start(PUT_MGMT_ENDPOINTS, Env.SUB|Env.ALWAYS);
- try {
- MGMT_ENDPOINTS rreq;
- try {
- RosettaData<MGMT_ENDPOINTS> data = mepDF.newData().load(req.getInputStream());
- rreq = data.asObject();
- } catch(APIException e) {
- trans.error().log("Invalid Input",IN,PUT_MGMT_ENDPOINTS);
- return Result.err(Status.ERR_BadData,"Invalid Input");
+ private static final String PUT_MGMT_ENDPOINTS = "Put Mgmt Endpoints";
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.facade.GwFacade#putMgmtEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ public Result<Void> putMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) {
+ TimeTaken tt = trans.start(PUT_MGMT_ENDPOINTS, Env.SUB|Env.ALWAYS);
+ try {
+ MGMT_ENDPOINTS rreq;
+ try {
+ RosettaData<MGMT_ENDPOINTS> data = mepDF.newData().load(req.getInputStream());
+ rreq = data.asObject();
+ } catch(APIException e) {
+ trans.error().log("Invalid Input",IN,PUT_MGMT_ENDPOINTS);
+ return Result.err(Status.ERR_BadData,"Invalid Input");
- }
- Result<Void> rp = service.putMgmtEndPoints(trans, rreq);
- switch(rp.status) {
- case OK:
- synchronized(LOCK) {
- cacheClear = 0L;
- }
- setContentType(resp,mepDF.getOutType());
- return Result.ok();
- default:
- return rp;
- }
- } catch (Exception e) {
- trans.error().log(e,IN,PUT_MGMT_ENDPOINTS);
- return Result.err(e);
- } finally {
- tt.done();
- }
- }
+ }
+ Result<Void> rp = service.putMgmtEndPoints(trans, rreq);
+ switch(rp.status) {
+ case OK:
+ synchronized(LOCK) {
+ cacheClear = 0L;
+ }
+ setContentType(resp,mepDF.getOutType());
+ return Result.ok();
+ default:
+ return rp;
+ }
+ } catch (Exception e) {
+ trans.error().log(e,IN,PUT_MGMT_ENDPOINTS);
+ return Result.err(e);
+ } finally {
+ tt.done();
+ }
+ }
- private static final String DELETE_MGMT_ENDPOINTS = "Delete Mgmt Endpoints";
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.facade.GwFacade#removeMgmtEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
- */
- @Override
- public Result<Void> removeMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) {
- TimeTaken tt = trans.start(DELETE_MGMT_ENDPOINTS, Env.SUB|Env.ALWAYS);
- try {
- MGMT_ENDPOINTS rreq;
- try {
- RosettaData<MGMT_ENDPOINTS> data = mepDF.newData().load(req.getInputStream());
- rreq = data.asObject();
- } catch(APIException e) {
- trans.error().log("Invalid Input",IN,DELETE_MGMT_ENDPOINTS);
- return Result.err(Status.ERR_BadData,"Invalid Input");
+ private static final String DELETE_MGMT_ENDPOINTS = "Delete Mgmt Endpoints";
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.facade.GwFacade#removeMgmtEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ public Result<Void> removeMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) {
+ TimeTaken tt = trans.start(DELETE_MGMT_ENDPOINTS, Env.SUB|Env.ALWAYS);
+ try {
+ MGMT_ENDPOINTS rreq;
+ try {
+ RosettaData<MGMT_ENDPOINTS> data = mepDF.newData().load(req.getInputStream());
+ rreq = data.asObject();
+ } catch(APIException e) {
+ trans.error().log("Invalid Input",IN,DELETE_MGMT_ENDPOINTS);
+ return Result.err(Status.ERR_BadData,"Invalid Input");
- }
- Result<Void> rp = service.removeMgmtEndPoints(trans, rreq);
- switch(rp.status) {
- case OK:
- synchronized(LOCK) {
- cacheClear = 0L;
- }
- setContentType(resp,mepDF.getOutType());
- return Result.ok();
- default:
- return rp;
- }
- } catch (Exception e) {
- trans.error().log(e,IN,DELETE_MGMT_ENDPOINTS);
- return Result.err(e);
- } finally {
- tt.done();
- }
- }
+ }
+ Result<Void> rp = service.removeMgmtEndPoints(trans, rreq);
+ switch(rp.status) {
+ case OK:
+ synchronized(LOCK) {
+ cacheClear = 0L;
+ }
+ setContentType(resp,mepDF.getOutType());
+ return Result.ok();
+ default:
+ return rp;
+ }
+ } catch (Exception e) {
+ trans.error().log(e,IN,DELETE_MGMT_ENDPOINTS);
+ return Result.err(e);
+ } finally {
+ tt.done();
+ }
+ }
- private static final String GET_CONFIG = "Get Configuration";
- @Override
- public Result<Void> getConfig(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, final String id, final String type) {
- TimeTaken tt = trans.start(GET_CONFIG, Env.SUB|Env.ALWAYS);
- try {
- Result<CONFIGURATION> rp = service.getConfig(trans, id, type);
- switch(rp.status) {
- case OK:
- setContentType(resp,mepDF.getOutType());
- confDF.newData(trans).load(rp.value).to(resp.getOutputStream());
- return Result.ok();
- default:
- return Result.err(rp);
- }
- } catch (Exception e) {
- trans.error().log(e,IN,GET_CONFIG);
- return Result.err(e);
- } finally {
- tt.done();
- }
- }
-
+ private static final String GET_CONFIG = "Get Configuration";
+ @Override
+ public Result<Void> getConfig(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, final String id, final String type) {
+ TimeTaken tt = trans.start(GET_CONFIG, Env.SUB|Env.ALWAYS);
+ try {
+ Result<CONFIGURATION> rp = service.getConfig(trans, id, type);
+ switch(rp.status) {
+ case OK:
+ setContentType(resp,mepDF.getOutType());
+ confDF.newData(trans).load(rp.value).to(resp.getOutputStream());
+ return Result.ok();
+ default:
+ return Result.err(rp);
+ }
+ } catch (Exception e) {
+ trans.error().log(e,IN,GET_CONFIG);
+ return Result.err(e);
+ } finally {
+ tt.done();
+ }
+ }
+
} \ No newline at end of file
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java
index 87d98361..8f45058f 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java
@@ -36,7 +36,7 @@ import locate_local.v1_0.Error;
public class LocateFacade_1_1 extends LocateFacadeImpl<InRequest,Out,Endpoints,MgmtEndpoints,Configuration,Error>
{
- public LocateFacade_1_1(AuthzEnv env, LocateService<InRequest,Out,Endpoints,MgmtEndpoints,Configuration,Error> service, Data.TYPE type) throws APIException {
- super(env, service, type);
- }
+ public LocateFacade_1_1(AuthzEnv env, LocateService<InRequest,Out,Endpoints,MgmtEndpoints,Configuration,Error> service, Data.TYPE type) throws APIException {
+ super(env, service, type);
+ }
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java
index 7e012f2d..e2cd4bce 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java
@@ -30,12 +30,12 @@ import locate.v1_0.MgmtEndpoint;
public interface Mapper<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIG,ERROR>
{
- public enum API{IN_REQ,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIG,ERROR,VOID};
- public Class<?> getClass(API api);
- public<A> A newInstance(API api);
+ public enum API{IN_REQ,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIG,ERROR,VOID};
+ public Class<?> getClass(API api);
+ public<A> A newInstance(API api);
- public ERROR errorFromMessage(StringBuilder holder, String msgID, String text, String... detail);
- public Result<ENDPOINTS> endpoints(Result<List<Data>> resultDB, String version, String other);
- public Data locateData(MgmtEndpoint me);
+ public ERROR errorFromMessage(StringBuilder holder, String msgID, String text, String... detail);
+ public Result<ENDPOINTS> endpoints(Result<List<Data>> resultDB, String version, String other);
+ public Data locateData(MgmtEndpoint me);
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java
index 2edb54f9..d2eeb632 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java
@@ -38,116 +38,116 @@ import locate_local.v1_0.InRequest;
import locate_local.v1_0.Out;
public class Mapper_1_1 implements Mapper<InRequest,Out,Endpoints,MgmtEndpoints,Configuration,Error> {
-
- @Override
- public Class<?> getClass(API api) {
- switch(api) {
- case IN_REQ: return InRequest.class;
- case OUT: return Out.class;
- case ERROR: return Error.class;
- case VOID: return Void.class;
- case ENDPOINTS: return Endpoints.class;
- case MGMT_ENDPOINTS: return MgmtEndpoints.class;
- case CONFIG: return Configuration.class;
- }
- return null;
- }
+
+ @Override
+ public Class<?> getClass(API api) {
+ switch(api) {
+ case IN_REQ: return InRequest.class;
+ case OUT: return Out.class;
+ case ERROR: return Error.class;
+ case VOID: return Void.class;
+ case ENDPOINTS: return Endpoints.class;
+ case MGMT_ENDPOINTS: return MgmtEndpoints.class;
+ case CONFIG: return Configuration.class;
+ }
+ return null;
+ }
- @SuppressWarnings("unchecked")
- @Override
- public <A> A newInstance(API api) {
- switch(api) {
- case IN_REQ: return (A) new InRequest();
- case OUT: return (A) new Out();
- case ERROR: return (A)new Error();
- case ENDPOINTS: return (A) new Endpoints();
- case MGMT_ENDPOINTS: return (A) new MgmtEndpoints();
- case CONFIG: return (A) new Configuration();
- case VOID: return null;
- }
- return null;
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public <A> A newInstance(API api) {
+ switch(api) {
+ case IN_REQ: return (A) new InRequest();
+ case OUT: return (A) new Out();
+ case ERROR: return (A)new Error();
+ case ENDPOINTS: return (A) new Endpoints();
+ case MGMT_ENDPOINTS: return (A) new MgmtEndpoints();
+ case CONFIG: return (A) new Configuration();
+ case VOID: return null;
+ }
+ return null;
+ }
- ////////////// Mapping Functions /////////////
- @Override
- public locate_local.v1_0.Error errorFromMessage(StringBuilder holder, String msgID, String text,String... var) {
- Error err = new Error();
- err.setMessageId(msgID);
- // AT&T Restful Error Format requires numbers "%" placements
- err.setText(Vars.convert(holder, text, var));
- for(String s : var) {
- err.getVariables().add(s);
- }
- return err;
- }
+ ////////////// Mapping Functions /////////////
+ @Override
+ public locate_local.v1_0.Error errorFromMessage(StringBuilder holder, String msgID, String text,String... var) {
+ Error err = new Error();
+ err.setMessageId(msgID);
+ // AT&T Restful Error Format requires numbers "%" placements
+ err.setText(Vars.convert(holder, text, var));
+ for(String s : var) {
+ err.getVariables().add(s);
+ }
+ return err;
+ }
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.mapper.Mapper#endpoints(org.onap.aaf.auth.layer.test.Result, java.lang.String, java.lang.String)
- */
- @Override
- public Result<Endpoints> endpoints(Result<List<Data>> resultDB, String version, String other) {
- if(resultDB.notOK()) {
- return Result.err(resultDB);
- }
- int major=-1, minor=-1, patch=-1, pkg=-1;
- if(version!=null) {
- try {
- String[] v = Split.split('.',version);
- if(v.length>0) {major = Integer.parseInt(v[0]);}
- if(v.length>1) {minor = Integer.parseInt(v[1]);}
- if(v.length>2) {patch = Integer.parseInt(v[2]);}
- if(v.length>3) {pkg = Integer.parseInt(v[3]);}
- } catch (NumberFormatException e) {
- return Result.err(Result.ERR_BadData,"Invalid Version String " + version);
- }
- }
- Endpoints eps = new Endpoints();
- List<Endpoint> leps = eps.getEndpoint();
- for(Data d : resultDB.value) {
- if((major<0 || major==d.major) &&
- (minor<0 || minor<=d.minor) &&
- (patch<0 || patch==d.patch) &&
- (pkg<0 || pkg ==d.pkg)) {
- Endpoint ep = new Endpoint();
- ep.setName(d.name);
- ep.setHostname(d.hostname);
- ep.setPort(d.port);
- ep.setMajor(d.major);
- ep.setMinor(d.minor);
- ep.setPatch(d.patch);
- ep.setPkg(d.pkg);
- ep.setLatitude(d.latitude);
- ep.setLongitude(d.longitude);
- ep.setProtocol(d.protocol);
- for(String s : d.subprotocol(false)) {
- ep.getSubprotocol().add(s);
- }
- leps.add(ep);
- }
- }
- return Result.ok(eps);
- }
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.mapper.Mapper#endpoints(org.onap.aaf.auth.layer.test.Result, java.lang.String, java.lang.String)
+ */
+ @Override
+ public Result<Endpoints> endpoints(Result<List<Data>> resultDB, String version, String other) {
+ if(resultDB.notOK()) {
+ return Result.err(resultDB);
+ }
+ int major=-1, minor=-1, patch=-1, pkg=-1;
+ if(version!=null) {
+ try {
+ String[] v = Split.split('.',version);
+ if(v.length>0) {major = Integer.parseInt(v[0]);}
+ if(v.length>1) {minor = Integer.parseInt(v[1]);}
+ if(v.length>2) {patch = Integer.parseInt(v[2]);}
+ if(v.length>3) {pkg = Integer.parseInt(v[3]);}
+ } catch (NumberFormatException e) {
+ return Result.err(Result.ERR_BadData,"Invalid Version String " + version);
+ }
+ }
+ Endpoints eps = new Endpoints();
+ List<Endpoint> leps = eps.getEndpoint();
+ for(Data d : resultDB.value) {
+ if((major<0 || major==d.major) &&
+ (minor<0 || minor<=d.minor) &&
+ (patch<0 || patch==d.patch) &&
+ (pkg<0 || pkg ==d.pkg)) {
+ Endpoint ep = new Endpoint();
+ ep.setName(d.name);
+ ep.setHostname(d.hostname);
+ ep.setPort(d.port);
+ ep.setMajor(d.major);
+ ep.setMinor(d.minor);
+ ep.setPatch(d.patch);
+ ep.setPkg(d.pkg);
+ ep.setLatitude(d.latitude);
+ ep.setLongitude(d.longitude);
+ ep.setProtocol(d.protocol);
+ for(String s : d.subprotocol(false)) {
+ ep.getSubprotocol().add(s);
+ }
+ leps.add(ep);
+ }
+ }
+ return Result.ok(eps);
+ }
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.mapper.Mapper#locateData(locate.v1_0.MgmtEndpoint)
- */
- @Override
- public Data locateData(MgmtEndpoint me) {
- Data data = new Data();
- data.name = me.getName();
- data.port = me.getPort();
- data.hostname = me.getHostname();
- data.major = me.getMajor();
- data.minor = me.getMinor();
- data.patch = me.getPatch();
- data.pkg = me.getPkg();
- data.latitude = me.getLatitude();
- data.longitude = me.getLongitude();
- data.protocol = me.getProtocol();
- for(String s : me.getSubprotocol()) {
- data.subprotocol(true).add(s);
- }
- return data;
- }
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.mapper.Mapper#locateData(locate.v1_0.MgmtEndpoint)
+ */
+ @Override
+ public Data locateData(MgmtEndpoint me) {
+ Data data = new Data();
+ data.name = me.getName();
+ data.port = me.getPort();
+ data.hostname = me.getHostname();
+ data.major = me.getMajor();
+ data.minor = me.getMinor();
+ data.patch = me.getPatch();
+ data.pkg = me.getPkg();
+ data.latitude = me.getLatitude();
+ data.longitude = me.getLongitude();
+ data.protocol = me.getProtocol();
+ for(String s : me.getSubprotocol()) {
+ data.subprotocol(true).add(s);
+ }
+ return data;
+ }
} \ No newline at end of file
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java
index ac2e3c46..47f3b984 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java
@@ -26,9 +26,9 @@ import org.onap.aaf.auth.layer.Result;
import org.onap.aaf.auth.locate.mapper.Mapper;
public interface LocateService<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIG,ERROR> {
- public Mapper<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIG,ERROR> mapper();
- public Result<ENDPOINTS> getEndPoints(AuthzTrans trans, String service, String version, String other);
- public Result<Void> putMgmtEndPoints(AuthzTrans trans, MGMT_ENDPOINTS meps);
- public Result<Void> removeMgmtEndPoints(AuthzTrans trans, MGMT_ENDPOINTS meps);
- public Result<CONFIG> getConfig(AuthzTrans trans, String id, String type);
+ public Mapper<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIG,ERROR> mapper();
+ public Result<ENDPOINTS> getEndPoints(AuthzTrans trans, String service, String version, String other);
+ public Result<Void> putMgmtEndPoints(AuthzTrans trans, MGMT_ENDPOINTS meps);
+ public Result<Void> removeMgmtEndPoints(AuthzTrans trans, MGMT_ENDPOINTS meps);
+ public Result<CONFIG> getConfig(AuthzTrans trans, String id, String type);
}
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java
index b2cdfab6..d0aae466 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java
@@ -42,111 +42,111 @@ import locate.v1_1.Configuration;
import locate.v1_1.Configuration.Props;
public class LocateServiceImpl<IN,OUT,ERROR>
- implements LocateService<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> {
- private Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper;
- protected LocateDAO locateDAO;
- private ConfigDAO configDAO;
- private boolean permToRegister;
-
- public LocateServiceImpl(AuthzTrans trans, AAF_Locate locate, Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper) throws APIException {
- this.mapper = mapper;
- this.locateDAO = locate.locateDAO;
- this.configDAO = locate.configDAO;
- permToRegister = false; //TODO Setup a Configuration for this
- }
-
- public Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper() {return mapper;}
+ implements LocateService<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> {
+ private Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper;
+ protected LocateDAO locateDAO;
+ private ConfigDAO configDAO;
+ private boolean permToRegister;
+
+ public LocateServiceImpl(AuthzTrans trans, AAF_Locate locate, Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper) throws APIException {
+ this.mapper = mapper;
+ this.locateDAO = locate.locateDAO;
+ this.configDAO = locate.configDAO;
+ permToRegister = false; //TODO Setup a Configuration for this
+ }
+
+ public Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper() {return mapper;}
- @Override
- public Result<Endpoints> getEndPoints(AuthzTrans trans, String service, String version, String other) {
- return mapper.endpoints(locateDAO.readByName(trans, service), version, other);
- }
+ @Override
+ public Result<Endpoints> getEndPoints(AuthzTrans trans, String service, String version, String other) {
+ return mapper.endpoints(locateDAO.readByName(trans, service), version, other);
+ }
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.service.GwService#putMgmtEndPoints(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.Object)
- */
- @Override
- public Result<Void> putMgmtEndPoints(AuthzTrans trans, MgmtEndpoints meps) {
- LocateValidator v = new LocateValidator().mgmt_endpoints(meps, false);
- if(v.err()) {
- return Result.err(Result.ERR_BadData,v.errs());
- }
- int count = 0;
- for(MgmtEndpoint me : meps.getMgmtEndpoint()) {
- if(permToRegister) {
- int dot = me.getName().lastIndexOf('.'); // Note: Validator checks for NS for getName()
- AAFPermission p = new AAFPermission(me.getName().substring(0,dot),"locator",me.getName(),"write");
- if(trans.fish(p)) {
- LocateDAO.Data data = mapper.locateData(me);
- locateDAO.update(trans, data, true);
- ++count;
- } else {
- return Result.err(Result.ERR_Denied,"May not register service (needs " + p.getKey() + ')');
- }
- } else { //TODO if(MechID is part of Namespace) {
- LocateDAO.Data data = mapper.locateData(me);
- locateDAO.update(trans, data, true);
- ++count;
- }
- }
- if(count>0) {
- return Result.ok();
- } else {
- return Result.err(Result.ERR_NotFound, "No endpoints found");
- }
- }
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.service.GwService#putMgmtEndPoints(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.Object)
+ */
+ @Override
+ public Result<Void> putMgmtEndPoints(AuthzTrans trans, MgmtEndpoints meps) {
+ LocateValidator v = new LocateValidator().mgmt_endpoints(meps, false);
+ if(v.err()) {
+ return Result.err(Result.ERR_BadData,v.errs());
+ }
+ int count = 0;
+ for(MgmtEndpoint me : meps.getMgmtEndpoint()) {
+ if(permToRegister) {
+ int dot = me.getName().lastIndexOf('.'); // Note: Validator checks for NS for getName()
+ AAFPermission p = new AAFPermission(me.getName().substring(0,dot),"locator",me.getName(),"write");
+ if(trans.fish(p)) {
+ LocateDAO.Data data = mapper.locateData(me);
+ locateDAO.update(trans, data, true);
+ ++count;
+ } else {
+ return Result.err(Result.ERR_Denied,"May not register service (needs " + p.getKey() + ')');
+ }
+ } else { //TODO if(MechID is part of Namespace) {
+ LocateDAO.Data data = mapper.locateData(me);
+ locateDAO.update(trans, data, true);
+ ++count;
+ }
+ }
+ if(count>0) {
+ return Result.ok();
+ } else {
+ return Result.err(Result.ERR_NotFound, "No endpoints found");
+ }
+ }
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.service.GwService#removeMgmtEndPoints(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.Object)
- */
- @Override
- public Result<Void> removeMgmtEndPoints(AuthzTrans trans, MgmtEndpoints meps) {
- LocateValidator v = new LocateValidator().mgmt_endpoint_key(meps);
- if(v.err()) {
- return Result.err(Result.ERR_BadData,v.errs());
- }
- int count = 0;
- for(MgmtEndpoint me : meps.getMgmtEndpoint()) {
- int dot = me.getName().lastIndexOf('.'); // Note: Validator checks for NS for getName()
- AAFPermission p = new AAFPermission(me.getName().substring(0,dot),"locator",me.getHostname(),"write");
- if(trans.fish(p)) {
- LocateDAO.Data data = mapper.locateData(me);
- data.port_key = UUID.randomUUID();
- locateDAO.delete(trans, data, false);
- ++count;
- } else {
- return Result.err(Result.ERR_Denied,"May not register service (needs " + p.getKey() + ')');
- }
- }
- if(count>0) {
- return Result.ok();
- } else {
- return Result.err(Result.ERR_NotFound, "No endpoints found");
- }
- }
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.service.GwService#removeMgmtEndPoints(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.Object)
+ */
+ @Override
+ public Result<Void> removeMgmtEndPoints(AuthzTrans trans, MgmtEndpoints meps) {
+ LocateValidator v = new LocateValidator().mgmt_endpoint_key(meps);
+ if(v.err()) {
+ return Result.err(Result.ERR_BadData,v.errs());
+ }
+ int count = 0;
+ for(MgmtEndpoint me : meps.getMgmtEndpoint()) {
+ int dot = me.getName().lastIndexOf('.'); // Note: Validator checks for NS for getName()
+ AAFPermission p = new AAFPermission(me.getName().substring(0,dot),"locator",me.getHostname(),"write");
+ if(trans.fish(p)) {
+ LocateDAO.Data data = mapper.locateData(me);
+ data.port_key = UUID.randomUUID();
+ locateDAO.delete(trans, data, false);
+ ++count;
+ } else {
+ return Result.err(Result.ERR_Denied,"May not register service (needs " + p.getKey() + ')');
+ }
+ }
+ if(count>0) {
+ return Result.ok();
+ } else {
+ return Result.err(Result.ERR_NotFound, "No endpoints found");
+ }
+ }
- ///// ADDED v1_1
- /* (non-Javadoc)
- * @see org.onap.aaf.auth.locate.service.LocateService#getConfig(org.onap.aaf.auth.env.AuthzTrans, java.lang.String, java.lang.String)
- */
- @Override
- public Result<Configuration> getConfig(AuthzTrans trans, String id, String type) {
- Result<List<Data>> dr = configDAO.readName(trans, type);
- Configuration c = new Configuration();
- c.setName(type);
- Props p;
-
- if(dr.isOKhasData()) {
- for(ConfigDAO.Data data : dr.value) {
- p = new Props();
- p.setTag(data.tag);
- p.setValue(data.value);
- c.getProps().add(p);
- }
- }
- return Result.ok(c);
- //return Result.err(Result.ERR_NotImplemented,"not done yet");
- }
+ ///// ADDED v1_1
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.locate.service.LocateService#getConfig(org.onap.aaf.auth.env.AuthzTrans, java.lang.String, java.lang.String)
+ */
+ @Override
+ public Result<Configuration> getConfig(AuthzTrans trans, String id, String type) {
+ Result<List<Data>> dr = configDAO.readName(trans, type);
+ Configuration c = new Configuration();
+ c.setName(type);
+ Props p;
+
+ if(dr.isOKhasData()) {
+ for(ConfigDAO.Data data : dr.value) {
+ p = new Props();
+ p.setTag(data.tag);
+ p.setValue(data.value);
+ c.getProps().add(p);
+ }
+ }
+ return Result.ok(c);
+ //return Result.err(Result.ERR_NotImplemented,"not done yet");
+ }
//////////////// APIs ///////////////////
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/validation/LocateValidator.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/validation/LocateValidator.java
index 89157826..6dd3d92a 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/validation/LocateValidator.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/validation/LocateValidator.java
@@ -39,103 +39,103 @@ import locate.v1_0.MgmtEndpoints;
*
*/
public class LocateValidator extends Validator {
- private LocateValidator endpoint_key(Endpoint e) {
- if(e==null) {
- msg("Endpoint Data is null.");
- } else {
- nullOrBlank("Endpoint Name", e.getName());
- if(e.getName()!=null) {
- int idx = e.getName().indexOf('.');
- if(idx<=0) {
- msg("Endpoint Name must prefixed by Namespace");
- }
- }
- nullOrBlank("Endpoint Hostname", e.getHostname());
- intRange("Endpoint Port",e.getPort(),0,1000000);
- }
- return this;
- }
+ private LocateValidator endpoint_key(Endpoint e) {
+ if(e==null) {
+ msg("Endpoint Data is null.");
+ } else {
+ nullOrBlank("Endpoint Name", e.getName());
+ if(e.getName()!=null) {
+ int idx = e.getName().indexOf('.');
+ if(idx<=0) {
+ msg("Endpoint Name must prefixed by Namespace");
+ }
+ }
+ nullOrBlank("Endpoint Hostname", e.getHostname());
+ intRange("Endpoint Port",e.getPort(),0,1000000);
+ }
+ return this;
+ }
- public LocateValidator endpoint(Endpoint e) {
- endpoint_key(e);
- if(e!=null) {
- intRange("Endpoint Major Version",e.getMajor(),0,2000);
- intRange("Endpoint Minor Version",e.getMinor(),0,2000);
- intRange("Endpoint Patch Version",e.getPatch(),0,2000);
- intRange("Endpoint Pkg Version",e.getPkg(),0,2000);
- floatRange("Endpoint Latitude",e.getLatitude(),-90f,90f);
- floatRange("Endpoint Longitude",e.getLongitude(),-180f,180f);
- nullOrBlank("Endpoint Protocol", e.getProtocol());
- for(String s : e.getSubprotocol()) {
- nullOrBlank("Endpoint Subprotocol", s);
- }
- }
- return this;
- }
-
- public LocateValidator endpoints(Endpoints e, boolean emptyNotOK) {
- if(e==null) {
- msg("Endpoints Data is null.");
- } else {
- if(emptyNotOK && e.getEndpoint().size()==0) {
- msg("Endpoints contains no endpoints");
- } else {
- for(Endpoint ep : e.getEndpoint()) {
- endpoint(ep);
- }
- }
- }
- return this;
- }
+ public LocateValidator endpoint(Endpoint e) {
+ endpoint_key(e);
+ if(e!=null) {
+ intRange("Endpoint Major Version",e.getMajor(),0,2000);
+ intRange("Endpoint Minor Version",e.getMinor(),0,2000);
+ intRange("Endpoint Patch Version",e.getPatch(),0,2000);
+ intRange("Endpoint Pkg Version",e.getPkg(),0,2000);
+ floatRange("Endpoint Latitude",e.getLatitude(),-90f,90f);
+ floatRange("Endpoint Longitude",e.getLongitude(),-180f,180f);
+ nullOrBlank("Endpoint Protocol", e.getProtocol());
+ for(String s : e.getSubprotocol()) {
+ nullOrBlank("Endpoint Subprotocol", s);
+ }
+ }
+ return this;
+ }
+
+ public LocateValidator endpoints(Endpoints e, boolean emptyNotOK) {
+ if(e==null) {
+ msg("Endpoints Data is null.");
+ } else {
+ if(emptyNotOK && e.getEndpoint().size()==0) {
+ msg("Endpoints contains no endpoints");
+ } else {
+ for(Endpoint ep : e.getEndpoint()) {
+ endpoint(ep);
+ }
+ }
+ }
+ return this;
+ }
- public LocateValidator mgmt_endpoint_key(MgmtEndpoints meps) {
- if(meps==null) {
- msg("MgmtEndpoints Data is null.");
- } else {
- for(MgmtEndpoint ep : meps.getMgmtEndpoint()) {
- endpoint_key(ep);
- }
- }
- return this;
- }
+ public LocateValidator mgmt_endpoint_key(MgmtEndpoints meps) {
+ if(meps==null) {
+ msg("MgmtEndpoints Data is null.");
+ } else {
+ for(MgmtEndpoint ep : meps.getMgmtEndpoint()) {
+ endpoint_key(ep);
+ }
+ }
+ return this;
+ }
- public LocateValidator mgmt_endpoints(MgmtEndpoints me, boolean emptyOK) {
- if(me==null) {
- msg("MgmtEndpoints Data is null.");
- } else {
- if(!emptyOK && me.getMgmtEndpoint().size()==0) {
- msg("MgmtEndpoints contains no data");
- } else {
- for(MgmtEndpoint ep : me.getMgmtEndpoint()) {
- mgmt_endpoint(ep);
- }
- }
- }
- return this;
- }
+ public LocateValidator mgmt_endpoints(MgmtEndpoints me, boolean emptyOK) {
+ if(me==null) {
+ msg("MgmtEndpoints Data is null.");
+ } else {
+ if(!emptyOK && me.getMgmtEndpoint().size()==0) {
+ msg("MgmtEndpoints contains no data");
+ } else {
+ for(MgmtEndpoint ep : me.getMgmtEndpoint()) {
+ mgmt_endpoint(ep);
+ }
+ }
+ }
+ return this;
+ }
- private LocateValidator mgmt_endpoint(MgmtEndpoint ep) {
- endpoint(ep);
- for(SpecialPorts sp : ep.getSpecialPorts()) {
- specialPorts(sp);
- }
- return this;
- }
+ private LocateValidator mgmt_endpoint(MgmtEndpoint ep) {
+ endpoint(ep);
+ for(SpecialPorts sp : ep.getSpecialPorts()) {
+ specialPorts(sp);
+ }
+ return this;
+ }
- private LocateValidator specialPorts(SpecialPorts sp) {
- if(sp==null) {
- msg("Special Ports is null.");
- } else {
- nullOrBlank("Special Port Name",sp.getName());
- nullOrBlank("Special Port Protocol",sp.getProtocol());
- intRange("Special Port",sp.getPort(),0,1000000);
-
- for(String s : sp.getProtocolVersions()) {
- nullOrBlank("Special Port Protocol Version", s);
- }
- }
- return this;
- }
+ private LocateValidator specialPorts(SpecialPorts sp) {
+ if(sp==null) {
+ msg("Special Ports is null.");
+ } else {
+ nullOrBlank("Special Port Name",sp.getName());
+ nullOrBlank("Special Port Protocol",sp.getProtocol());
+ intRange("Special Port",sp.getPort(),0,1000000);
+
+ for(String s : sp.getProtocolVersions()) {
+ nullOrBlank("Special Port Protocol Version", s);
+ }
+ }
+ return this;
+ }
}
diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java
index eea60eb0..cdae121a 100644
--- a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java
+++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java
@@ -42,74 +42,74 @@ import org.onap.aaf.misc.env.LogTarget;
public class JU_BasicAuthCodeTest {
- @Mock
- AAFAuthn authn;
+ @Mock
+ AAFAuthn authn;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- AuthzTrans trans;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ AuthzTrans trans;
- @Mock
- HttpServletRequest req;
+ @Mock
+ HttpServletRequest req;
- @Mock
- HttpServletResponse resp;
+ @Mock
+ HttpServletResponse resp;
- @Mock
- LogTarget error;
+ @Mock
+ LogTarget error;
- @Mock
- LocateFacade facade;
+ @Mock
+ LocateFacade facade;
- @Mock
- BasicPrincipal basicPrincipal;
- @Mock
- X509Principal x509Principal;
+ @Mock
+ BasicPrincipal basicPrincipal;
+ @Mock
+ X509Principal x509Principal;
- @Before
- public void setUp() throws Exception {
- initMocks(this);
- }
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ }
- @Test
- public void testWithNullUserPrincipal() throws Exception {
- BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
- LocateCode locateCode = basicAuthCode.clone(facade, false);
+ @Test
+ public void testWithNullUserPrincipal() throws Exception {
+ BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
+ LocateCode locateCode = basicAuthCode.clone(facade, false);
- assertEquals(locateCode.desc(), basicAuthCode.desc());
+ assertEquals(locateCode.desc(), basicAuthCode.desc());
- when(trans.getUserPrincipal()).thenReturn(null);
- when(trans.error()).thenReturn(error);
+ when(trans.getUserPrincipal()).thenReturn(null);
+ when(trans.error()).thenReturn(error);
- basicAuthCode.handle(trans, req, resp);
- }
+ basicAuthCode.handle(trans, req, resp);
+ }
- @Test
- public void testWithBasicUserPrincipal() throws Exception {
- BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
- LocateCode locateCode = basicAuthCode.clone(facade, false);
+ @Test
+ public void testWithBasicUserPrincipal() throws Exception {
+ BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
+ LocateCode locateCode = basicAuthCode.clone(facade, false);
- assertEquals(locateCode.desc(), basicAuthCode.desc());
+ assertEquals(locateCode.desc(), basicAuthCode.desc());
- when(trans.getUserPrincipal()).thenReturn(basicPrincipal);
+ when(trans.getUserPrincipal()).thenReturn(basicPrincipal);
- basicAuthCode.handle(trans, req, resp);
+ basicAuthCode.handle(trans, req, resp);
- verify(resp).setStatus(HttpStatus.OK_200);
- }
+ verify(resp).setStatus(HttpStatus.OK_200);
+ }
- @Test
- public void testWithX509UserPrincipal() throws Exception {
- BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
- LocateCode locateCode = basicAuthCode.clone(facade, false);
+ @Test
+ public void testWithX509UserPrincipal() throws Exception {
+ BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
+ LocateCode locateCode = basicAuthCode.clone(facade, false);
- assertEquals(locateCode.desc(), basicAuthCode.desc());
+ assertEquals(locateCode.desc(), basicAuthCode.desc());
- when(trans.getUserPrincipal()).thenReturn(x509Principal);
- when(req.getHeader("Authorization")).thenReturn("Basic 76//76");
+ when(trans.getUserPrincipal()).thenReturn(x509Principal);
+ when(req.getHeader("Authorization")).thenReturn("Basic 76//76");
- basicAuthCode.handle(trans, req, resp);
+ basicAuthCode.handle(trans, req, resp);
- verify(resp).setStatus(HttpStatus.FORBIDDEN_403);
- }
+ verify(resp).setStatus(HttpStatus.FORBIDDEN_403);
+ }
}
diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java
index 26bea940..5422117c 100644
--- a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java
+++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java
@@ -35,31 +35,31 @@ import locate_local.v1_0.Out;
public class JU_Mapper_1_0Test {
- @Before
- public void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
- }
+ }
- @Test
- public void testGetClasses() {
- Mapper_1_1 mapper = new Mapper_1_1();
- assertEquals(InRequest.class, mapper.getClass(API.IN_REQ));
- assertEquals(Out.class, mapper.getClass(API.OUT));
- assertEquals(Error.class, mapper.getClass(API.ERROR));
- assertEquals(Void.class, mapper.getClass(API.VOID));
- assertEquals(Endpoints.class, mapper.getClass(API.ENDPOINTS));
- assertEquals(MgmtEndpoints.class, mapper.getClass(API.MGMT_ENDPOINTS));
- }
+ @Test
+ public void testGetClasses() {
+ Mapper_1_1 mapper = new Mapper_1_1();
+ assertEquals(InRequest.class, mapper.getClass(API.IN_REQ));
+ assertEquals(Out.class, mapper.getClass(API.OUT));
+ assertEquals(Error.class, mapper.getClass(API.ERROR));
+ assertEquals(Void.class, mapper.getClass(API.VOID));
+ assertEquals(Endpoints.class, mapper.getClass(API.ENDPOINTS));
+ assertEquals(MgmtEndpoints.class, mapper.getClass(API.MGMT_ENDPOINTS));
+ }
- @Test
- public void testNewInstance() {
- Mapper_1_1 mapper = new Mapper_1_1();
- assertTrue(mapper.newInstance(API.IN_REQ) instanceof InRequest);
- assertTrue(mapper.newInstance(API.OUT) instanceof Out);
- assertTrue(mapper.newInstance(API.ERROR) instanceof Error);
- assertTrue(mapper.newInstance(API.ENDPOINTS) instanceof Endpoints);
- assertTrue(mapper.newInstance(API.MGMT_ENDPOINTS) instanceof MgmtEndpoints);
- assertEquals(null, mapper.newInstance(API.VOID));
- }
+ @Test
+ public void testNewInstance() {
+ Mapper_1_1 mapper = new Mapper_1_1();
+ assertTrue(mapper.newInstance(API.IN_REQ) instanceof InRequest);
+ assertTrue(mapper.newInstance(API.OUT) instanceof Out);
+ assertTrue(mapper.newInstance(API.ERROR) instanceof Error);
+ assertTrue(mapper.newInstance(API.ENDPOINTS) instanceof Endpoints);
+ assertTrue(mapper.newInstance(API.MGMT_ENDPOINTS) instanceof MgmtEndpoints);
+ assertEquals(null, mapper.newInstance(API.VOID));
+ }
}
diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java
index c66de60b..e3a74720 100644
--- a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java
+++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java
@@ -44,71 +44,71 @@ import locate.v1_0.MgmtEndpoints;
public class JU_LocateServiceImplTest {
- // Extend, because I don't want a "setter" in the original. Compromised with a protected...
- private final class LocateServiceImplExtension extends LocateServiceImpl {
- private LocateServiceImplExtension(AuthzTrans trans, AAF_Locate locate, Mapper mapper) throws APIException {
- super(trans, locate, mapper);
- }
- public void set(LocateDAO ld) {
- locateDAO=ld;
- }
- }
-
- @Mock
- private AuthzTrans trans;
- @Mock
- private AAF_Locate aaf_locate;
- @Mock
- private LocateDAO locateDAO;
- @Mock
- private Mapper mapper;
- @Mock
- private Result<List<Data>> result;
- @Mock
- private Result endPointResult;
- @Mock
- private MgmtEndpoints meps;
- @Mock
- private MgmtEndpoint mgmtEndPoint;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void test() throws APIException {
- LocateServiceImplExtension locateServiceImpl = new LocateServiceImplExtension(trans, aaf_locate, mapper);
- locateServiceImpl.set(locateDAO);
-
- assertEquals(mapper, locateServiceImpl.mapper());
-
- when(locateDAO.readByName(trans, "http")).thenReturn(result);
- when(mapper.endpoints(result, "1.0", "other")).thenReturn(endPointResult);
-
- Result output = locateServiceImpl.getEndPoints(trans, "http", "1.0", "other");
-
- assertEquals(endPointResult, output);
-
- List<MgmtEndpoint> mgmtEndPoints = new ArrayList<>();
- mgmtEndPoints.add(mgmtEndPoint);
-
- when(mgmtEndPoint.getName()).thenReturn("http.Endpoint1");
- when(mgmtEndPoint.getHostname()).thenReturn("HOST1");
- when(mgmtEndPoint.getPort()).thenReturn(9090);
- when(mgmtEndPoint.getProtocol()).thenReturn("HTTP");
-
- when(meps.getMgmtEndpoint()).thenReturn(mgmtEndPoints);
- output = locateServiceImpl.putMgmtEndPoints(trans, meps);
-
- assertEquals(output.toString(), Result.ok().toString());
-
- when(trans.fish(any())).thenReturn(true);
- Data data = new LocateDAO.Data();
- when(mapper.locateData(mgmtEndPoint)).thenReturn(data);
- output = locateServiceImpl.removeMgmtEndPoints(trans, meps);
-
- assertEquals(output.toString(), Result.ok().toString());
- }
+ // Extend, because I don't want a "setter" in the original. Compromised with a protected...
+ private final class LocateServiceImplExtension extends LocateServiceImpl {
+ private LocateServiceImplExtension(AuthzTrans trans, AAF_Locate locate, Mapper mapper) throws APIException {
+ super(trans, locate, mapper);
+ }
+ public void set(LocateDAO ld) {
+ locateDAO=ld;
+ }
+ }
+
+ @Mock
+ private AuthzTrans trans;
+ @Mock
+ private AAF_Locate aaf_locate;
+ @Mock
+ private LocateDAO locateDAO;
+ @Mock
+ private Mapper mapper;
+ @Mock
+ private Result<List<Data>> result;
+ @Mock
+ private Result endPointResult;
+ @Mock
+ private MgmtEndpoints meps;
+ @Mock
+ private MgmtEndpoint mgmtEndPoint;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void test() throws APIException {
+ LocateServiceImplExtension locateServiceImpl = new LocateServiceImplExtension(trans, aaf_locate, mapper);
+ locateServiceImpl.set(locateDAO);
+
+ assertEquals(mapper, locateServiceImpl.mapper());
+
+ when(locateDAO.readByName(trans, "http")).thenReturn(result);
+ when(mapper.endpoints(result, "1.0", "other")).thenReturn(endPointResult);
+
+ Result output = locateServiceImpl.getEndPoints(trans, "http", "1.0", "other");
+
+ assertEquals(endPointResult, output);
+
+ List<MgmtEndpoint> mgmtEndPoints = new ArrayList<>();
+ mgmtEndPoints.add(mgmtEndPoint);
+
+ when(mgmtEndPoint.getName()).thenReturn("http.Endpoint1");
+ when(mgmtEndPoint.getHostname()).thenReturn("HOST1");
+ when(mgmtEndPoint.getPort()).thenReturn(9090);
+ when(mgmtEndPoint.getProtocol()).thenReturn("HTTP");
+
+ when(meps.getMgmtEndpoint()).thenReturn(mgmtEndPoints);
+ output = locateServiceImpl.putMgmtEndPoints(trans, meps);
+
+ assertEquals(output.toString(), Result.ok().toString());
+
+ when(trans.fish(any())).thenReturn(true);
+ Data data = new LocateDAO.Data();
+ when(mapper.locateData(mgmtEndPoint)).thenReturn(data);
+ output = locateServiceImpl.removeMgmtEndPoints(trans, meps);
+
+ assertEquals(output.toString(), Result.ok().toString());
+ }
}