X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fconfig%2FSecurityInfoC.java;h=7c5f50ed008eed5d0248b755b7da09051e85bc25;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=a5fb4a0c31c139c693cacdd2a7b6453532fc45ca;hpb=f85f0889b3b0e5e9694afab4dd01a4a97a155188;p=aaf%2Fauthz.git 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..7c5f50ed 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,6 +21,7 @@ package org.onap.aaf.cadi.config; +import java.net.HttpURLConnection; import java.util.HashMap; import java.util.Map; @@ -30,43 +31,64 @@ import org.onap.aaf.cadi.SecuritySetter; 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 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 DEFSS(); + } + + @SuppressWarnings("unchecked") + public static synchronized SecurityInfoC instance(Access access, Class cls) throws CadiException { + 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(); + } + }; + } - public SecurityInfoC(Access access) throws CadiException { - super(access); - defSS = new SecuritySetter() { - @Override - public String getID() { - return DEF_ID; - } + SecurityInfoC sic = (SecurityInfoC) sicMap.get(cls); + if (sic==null) { + sic = new SecurityInfoC(access); + sic.set(sii.bestDefault(sic)); + sicMap.put(cls, sic); + } + return sic; + } - @Override - public void setSecurity(CLIENT client) throws CadiException { - throw new CadiException("No Client Credentials set."); - } + public SecurityInfoC set(SecuritySetter defSS) { + this.defSS = defSS; + return this; + } - @Override - public int setLastResponse(int respCode) { - return 0; - } - }; - } - - public static synchronized SecurityInfoC instance(Access access, Class cls) throws CadiException { - @SuppressWarnings("unchecked") - SecurityInfoC sic = (SecurityInfoC) sicMap.get(cls); - if(sic==null) { - sic = new SecurityInfoC(access); - sicMap.put(cls, sic); - } - return sic; - } + private static class DEFSS implements SecuritySetter { + @Override + public String getID() { + return DEF_ID; + } - public SecurityInfoC set(SecuritySetter defSS) { - this.defSS = defSS; - return this; - } + @Override + public void setSecurity(C client) throws CadiException { + throw new CadiException("No Client Credentials set."); + } + @Override + public int setLastResponse(int respCode) { + return 0; + } + }; }