From af2d592ebbb96d5f5f55f7322f9ecdfdccfce64e Mon Sep 17 00:00:00 2001 From: Instrumental Date: Wed, 29 Aug 2018 12:47:32 -0500 Subject: Change CadiFilter Default SSetter Issue-ID: AAF-460 Change-Id: I1f7d52104eb36c35cca3264b4995342936e69ef6 Signed-off-by: Instrumental --- .../org/onap/aaf/cadi/config/SecurityInfoC.java | 58 +++++++++++++++------- .../org/onap/aaf/cadi/config/SecurityInfoInit.java | 28 +++++++++++ .../org/onap/aaf/cadi/filter/CadiHTTPManip.java | 2 +- 3 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoInit.java (limited to 'cadi/core/src/main') diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java index a5fb4a0c..8e5faf4c 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java @@ -21,6 +21,7 @@ package org.onap.aaf.cadi.config; +import java.net.HttpURLConnection; import java.util.HashMap; import java.util.Map; @@ -33,32 +34,37 @@ public class SecurityInfoC extends SecurityInfo { public static final String DEF_ID = "ID not Set"; private static Map,SecurityInfoC> sicMap = new HashMap<>(); public SecuritySetter defSS; + public SecurityInfoC(Access access) throws CadiException { super(access); - defSS = new SecuritySetter() { - @Override - public String getID() { - return DEF_ID; - } - - @Override - public void setSecurity(CLIENT client) throws CadiException { - throw new CadiException("No Client Credentials set."); - } - - @Override - public int setLastResponse(int respCode) { - return 0; - } - }; + defSS = new DEFSS(); } + @SuppressWarnings("unchecked") public static synchronized SecurityInfoC instance(Access access, Class cls) throws CadiException { - @SuppressWarnings("unchecked") + SecurityInfoInit sii; + if(cls.isAssignableFrom(HttpURLConnection.class)) { + try { + @SuppressWarnings("rawtypes") + Class initCls = (Class)Class.forName("org.onap.aaf.cadi.http.HSecurityInfoInit"); + sii = initCls.newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + throw new CadiException("CADI using HttpURLConnection requires cadi-client jar",e); + } + } else { + sii = new SecurityInfoInit() { + @Override + public SecuritySetter bestDefault(SecurityInfoC si) throws CadiException { + return new DEFSS(); + } + }; + } + SecurityInfoC sic = (SecurityInfoC) sicMap.get(cls); if(sic==null) { - sic = new SecurityInfoC(access); + sic = new SecurityInfoC(access); + sic.set(sii.bestDefault(sic)); sicMap.put(cls, sic); } return sic; @@ -69,4 +75,20 @@ public class SecurityInfoC extends SecurityInfo { return this; } + private static class DEFSS implements SecuritySetter { + @Override + public String getID() { + return DEF_ID; + } + + @Override + public void setSecurity(C client) throws CadiException { + throw new CadiException("No Client Credentials set."); + } + + @Override + public int setLastResponse(int respCode) { + return 0; + } + }; } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoInit.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoInit.java new file mode 100644 index 00000000..d77a7196 --- /dev/null +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoInit.java @@ -0,0 +1,28 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.cadi.config; + +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.SecuritySetter; + +public interface SecurityInfoInit { + public SecuritySetter bestDefault(SecurityInfoC si) throws CadiException; +} diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java b/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java index 0cc52203..9d1653fa 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.CadiWrap; import org.onap.aaf.cadi.Connector; @@ -36,7 +37,6 @@ import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.Lur; import org.onap.aaf.cadi.Taf; import org.onap.aaf.cadi.TrustChecker; -import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.config.SecurityInfoC; import org.onap.aaf.cadi.lur.EpiLur; -- cgit 1.2.3-korg