diff options
author | 2018-08-29 12:47:32 -0500 | |
---|---|---|
committer | 2018-08-29 14:08:16 -0500 | |
commit | af2d592ebbb96d5f5f55f7322f9ecdfdccfce64e (patch) | |
tree | b99bb5ddd7821fd3f0cf202d214eea8208bb4b1e /cadi/core/src/main/java/org/onap | |
parent | 45ca42c48030171a5dcf180bb35fb767ae5c2b78 (diff) |
Change CadiFilter Default SSetter
Issue-ID: AAF-460
Change-Id: I1f7d52104eb36c35cca3264b4995342936e69ef6
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'cadi/core/src/main/java/org/onap')
3 files changed, 69 insertions, 19 deletions
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<CLIENT> extends SecurityInfo { public static final String DEF_ID = "ID not Set"; private static Map<Class<?>,SecurityInfoC<?>> sicMap = new HashMap<>(); public SecuritySetter<CLIENT> defSS; + public SecurityInfoC(Access access) throws CadiException { super(access); - defSS = new SecuritySetter<CLIENT>() { - @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<CLIENT>(); } + @SuppressWarnings("unchecked") public static synchronized <CLIENT> SecurityInfoC<CLIENT> instance(Access access, Class<CLIENT> cls) throws CadiException { - @SuppressWarnings("unchecked") + SecurityInfoInit<CLIENT> sii; + if(cls.isAssignableFrom(HttpURLConnection.class)) { + try { + @SuppressWarnings("rawtypes") + Class<SecurityInfoInit> initCls = (Class<SecurityInfoInit>)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<CLIENT>() { + @Override + public SecuritySetter<CLIENT> bestDefault(SecurityInfoC<CLIENT> si) throws CadiException { + return new DEFSS<CLIENT>(); + } + }; + } + SecurityInfoC<CLIENT> sic = (SecurityInfoC<CLIENT>) sicMap.get(cls); if(sic==null) { - sic = new SecurityInfoC<CLIENT>(access); + sic = new SecurityInfoC<CLIENT>(access); + sic.set(sii.bestDefault(sic)); sicMap.put(cls, sic); } return sic; @@ -69,4 +75,20 @@ public class SecurityInfoC<CLIENT> extends SecurityInfo { return this; } + private static class DEFSS<C> implements SecuritySetter<C> { + @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<CLIENT> { + public SecuritySetter<CLIENT> bestDefault(SecurityInfoC<CLIENT> 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; |