diff options
Diffstat (limited to 'cadi')
17 files changed, 531 insertions, 137 deletions
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/Defaults.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/Defaults.java index 0dc51106..c631cb9c 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/Defaults.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/Defaults.java @@ -24,12 +24,6 @@ public interface Defaults { public final static String AAF_VERSION = "2.1"; public final static String AAF_NS = "AAF_NS"; public final static String AAF_LOCATE_CONST="https://AAF_LOCATE_URL"; - public final static String AAF_ROOT = AAF_LOCATE_CONST + '/' + AAF_NS; - public final static String AAF_URL = AAF_ROOT + ".service:" + AAF_VERSION; - public final static String GUI_URL = AAF_ROOT + ".gui:" + AAF_VERSION; - public final static String CM_URL = AAF_ROOT + ".cm:" + AAF_VERSION; - public final static String FS_URL = AAF_ROOT + ".fs:" + AAF_VERSION; - public final static String HELLO_URL = AAF_ROOT + ".hello:" + AAF_VERSION; - public final static String OAUTH2_TOKEN_URL = AAF_ROOT + ".token:" + AAF_VERSION; - public final static String OAUTH2_INTROSPECT_URL = AAF_ROOT + ".introspect:" + AAF_VERSION; + public final static String AAF_ROOT = AAF_LOCATE_CONST + "/%CNS.%" + AAF_NS; + } diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java index bf7ed6d9..004c43c5 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java @@ -185,7 +185,7 @@ public class TestConnectivity { String tokenURL = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL); String locateURL=access.getProperty(Config.AAF_LOCATE_URL); if (tokenURL==null || (tokenURL.contains("/locate/") && locateURL!=null)) { - tokenURL=Defaults.OAUTH2_TOKEN_URL+"/token"; + tokenURL=Config.OAUTH2_TOKEN_URL_DEF; } try { diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java index 77489633..4fe05f71 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java @@ -22,6 +22,7 @@ package org.onap.aaf.cadi.aaf.v2_0; import java.net.URI; +import java.net.UnknownHostException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -35,12 +36,14 @@ import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.Lur; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.SecuritySetter; +import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.aaf.AAFPermission; import org.onap.aaf.cadi.aaf.marshal.CertsMarshal; import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.client.Rcli; import org.onap.aaf.cadi.client.Retryable; import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.config.RegistrationPropHolder; import org.onap.aaf.cadi.config.SecurityInfoC; import org.onap.aaf.cadi.lur.EpiLur; import org.onap.aaf.cadi.principal.BasicPrincipal; @@ -106,6 +109,13 @@ public abstract class AAFCon<CLIENT> implements Connector { throw new CadiException("A URL or " + tag + " property is required."); } } + try { + RegistrationPropHolder rph = new RegistrationPropHolder(access, 0); + str = rph.replacements(str, null,null); + } catch (UnknownHostException e) { + throw new CadiException(e); + } + access.printf(Level.INFO, "AAFCon has URL of %s",str); setInitURI(str); } try { diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java index 9b630a76..14878d38 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java @@ -23,6 +23,7 @@ package org.onap.aaf.cadi.aaf.v2_0; import java.net.URI; import java.net.URISyntaxException; +import java.net.UnknownHostException; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Iterator; @@ -32,10 +33,11 @@ import java.util.NoSuchElementException; import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.Access.Level; +import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.LocatorException; -import org.onap.aaf.cadi.aaf.Defaults; import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.config.RegistrationPropHolder; import org.onap.aaf.cadi.routing.GreatCircle; import org.onap.aaf.misc.env.Trans; import org.onap.aaf.misc.env.util.Split; @@ -64,17 +66,23 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI> public AbsAAFLocator(Access access, String name, final long refreshMin) throws LocatorException { - aaf_locator_host = access.getProperty(Config.AAF_LOCATE_URL, null); - if (aaf_locator_host==null) { - aaf_locator_uri = null; - } else { - try { - aaf_locator_uri = new URI(aaf_locator_host); - } catch (URISyntaxException e) { - throw new LocatorException(e); - } + RegistrationPropHolder rph; + try { + rph = new RegistrationPropHolder(access, 0); + } catch (UnknownHostException | CadiException e1) { + throw new LocatorException(e1); + } + try { + aaf_locator_host = rph.replacements("https://"+Config.AAF_LOCATE_URL_TAG,null,null); + aaf_locator_uri = new URI(aaf_locator_host); + access.printf(Level.INFO, "AbsAAFLocator AAF URI is %s",aaf_locator_uri); + } catch (URISyntaxException e) { + throw new LocatorException(e); } + name = rph.replacements(name, null,null); + access.printf(Level.INFO, "AbsAAFLocator name is %s",aaf_locator_uri); + epList = new LinkedList<>(); refreshWait = refreshMin; @@ -88,12 +96,6 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI> longitude = Double.parseDouble(lng); } - if (name.startsWith(Defaults.AAF_NS)) { - String root_ns = access.getProperty(Config.AAF_ROOT_NS, null); - if(root_ns!=null) { - name=name.replace(Defaults.AAF_NS, root_ns); - } - } if (name.startsWith("http")) { // simple URL this.name = name; diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java index aa4e5743..c7a74965 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java @@ -229,7 +229,7 @@ public class Agent { aafsso.setStdErrDefault(); // if CM_URL can be obtained, add to sso.props, if written - String cm_url = getProperty(access,env,false, Config.CM_URL,Config.CM_URL+": "); + String cm_url = getProperty(access,env,false, Config.CM_URL,Config.CM_URL_DEF); if (cm_url!=null) { aafsso.addProp(Config.CM_URL, cm_url); } @@ -781,7 +781,7 @@ public class Agent { } app.add(Config.AAF_APPID, fqi); - app.add(Config.AAF_URL, propAccess, Defaults.AAF_URL); + app.add(Config.AAF_URL, propAccess, Config.AAF_URL_DEF); String cts = propAccess.getProperty(Config.CADI_TRUSTSTORE); if (cts!=null) { diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java index 21b65f1a..c507a826 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java @@ -64,10 +64,10 @@ public class TokenClientFactory extends Persist<Token,TimedToken> { super(pa, new RosettaEnv(pa.getProperties()),Token.class,"outgoing"); if (access.getProperty(Config.AAF_OAUTH2_TOKEN_URL,null)==null) { - access.getProperties().put(Config.AAF_OAUTH2_TOKEN_URL, Defaults.OAUTH2_TOKEN_URL); // Default to AAF + access.getProperties().put(Config.AAF_OAUTH2_TOKEN_URL, Config.OAUTH2_TOKEN_URL_DEF); // Default to AAF } if (access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL,null)==null) { - access.getProperties().put(Config.AAF_OAUTH2_INTROSPECT_URL, Defaults.OAUTH2_INTROSPECT_URL); // Default to AAF); + access.getProperties().put(Config.AAF_OAUTH2_INTROSPECT_URL, Config.OAUTH2_INTROSPECT_URL_DEF); // Default to AAF); } symm = Symm.encrypt.obtain(); diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java index 66f1af0c..75cddfff 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java @@ -319,7 +319,7 @@ public class AAFSSO { if(aaf_root_ns==null) { locateRoot=Defaults.AAF_ROOT; } else { - locateRoot = Defaults.AAF_LOCATE_CONST + '/' + aaf_root_ns; + locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS.%" + aaf_root_ns; } if(access.getProperty(Config.AAF_URL)==null) { @@ -425,7 +425,6 @@ public class AAFSSO { diskprops.store(fos, "AAF Single Signon"); } finally { fos.close(); - setReadonly(sso); } } if (sso != null) { diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFAuthn.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFAuthn.java new file mode 100644 index 00000000..41b519b1 --- /dev/null +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFAuthn.java @@ -0,0 +1,204 @@ +/** + * ============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.aaf.v2_0; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.cadi.AbsUserCache; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.User; +import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.client.Future; +import org.onap.aaf.cadi.client.Rcli; +import org.onap.aaf.cadi.principal.BasicPrincipal; + +public class JU_AAFAuthn { + + @Mock + AAFCon con; + + @Mock + AbsUserCache<AAFPermission> cache; + + @Mock + PropAccess propaccess; + + @Before + public void setUp() { + initMocks(this); + } + + @Test + public void testGetRealm() { + AAFAuthn authnObj = new AAFAuthn(con); + String realm = authnObj.getRealm(); + assertNull(realm); + } + + @Test + public void testValidateFailure() { + AAFAuthnImplWithGetUserNull authnObj = new AAFAuthnImplWithGetUserNull(con, cache); + String realm=""; + try { + Mockito.doReturn("test").when(propaccess).decrypt("test", false); + realm = authnObj.validate("test", "test"); + assertNull(realm); + } catch (Exception e) { + // TODO Auto-generated catch block + assertNull( e.getLocalizedMessage()); + } + } + + @Test + public void testValidate() { + AAFAuthnImpl authnObj = new AAFAuthnImpl(con); + String realm=""; + try { + Mockito.doReturn("test").when(propaccess).decrypt("test", false); + Rcli rcliObj = Mockito.mock(Rcli.class); + Mockito.doReturn(rcliObj).when(con).client(); + Mockito.doReturn(rcliObj).when(rcliObj).forUser(null); + Future<String> futureObj = Mockito.mock(Future.class); + Mockito.doReturn(futureObj).when(rcliObj).read( "/authn/basicAuth","text/plain"); + realm = authnObj.validate("test", "test","test"); + assertTrue(realm.contains("User/Pass combo invalid")); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testValidateRevalidate() { + AAFAuthnImpl authnObj = new AAFAuthnImpl(con); + String realm=""; + try { + Mockito.doReturn("test").when(propaccess).decrypt("test", false); + Rcli rcliObj = Mockito.mock(Rcli.class); + Mockito.doReturn(rcliObj).when(con).client(); + Mockito.doReturn(rcliObj).when(rcliObj).forUser(null); + Future<String> futureObj = Mockito.mock(Future.class); + Mockito.doReturn(futureObj).when(rcliObj).read( "/authn/basicAuth","text/plain"); + Mockito.doReturn(true).when(futureObj).get( 0); + realm = authnObj.validate("test", "test","test"); + assertNull(realm); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testValidateValidUser() { + AAFAuthnImplWithGetUser authnObj = new AAFAuthnImplWithGetUser(con); + String realm=""; + try { + Mockito.doReturn("test").when(propaccess).decrypt("test", false); + realm = authnObj.validate("test", "test","test"); + assertTrue(realm.contains("User already denied")); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testValidateValidUserNull() { + AAFAuthnImplWithGetUserNull authnObj = new AAFAuthnImplWithGetUserNull(con); + String realm=""; + try { + Mockito.doReturn("test").when(propaccess).decrypt("test", false); + realm = authnObj.validate("test", "test","test"); + assertNull(realm); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + class AAFAuthnImpl extends AAFAuthn{ + AAFAuthnImpl(AAFCon con) { + super(con); + this.access = propaccess; + // TODO Auto-generated constructor stub + } + + AAFAuthnImpl(AAFCon con, AbsUserCache cache) { + super(con, cache); + this.access = propaccess; + // TODO Auto-generated constructor stub + } + + + } + + class AAFAuthnImplWithGetUser extends AAFAuthn{ + AAFAuthnImplWithGetUser(AAFCon con) { + super(con); + this.access = propaccess; + // TODO Auto-generated constructor stub + } + + AAFAuthnImplWithGetUser(AAFCon con, AbsUserCache cache) { + super(con, cache); + this.access = propaccess; + // TODO Auto-generated constructor stub + } + + @Override + protected User getUser(String user, byte[] cred) { + return new User<>("test",new byte[] {}); + } + } + + class AAFAuthnImplWithGetUserNull extends AAFAuthn{ + AAFAuthnImplWithGetUserNull(AAFCon con) { + super(con); + this.access = propaccess; + // TODO Auto-generated constructor stub + } + + AAFAuthnImplWithGetUserNull(AAFCon con, AbsUserCache cache) { + super(con, cache); + this.access = propaccess; + // TODO Auto-generated constructor stub + } + + @Override + protected User getUser(String user, byte[] cred) { + User user1 = null; + try { + user1 = new User(new BasicPrincipal("test","test")); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return user1; + } + } +} diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFSingleLocator.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFSingleLocator.java new file mode 100644 index 00000000..488c2857 --- /dev/null +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFSingleLocator.java @@ -0,0 +1,138 @@ +/** + * ============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.aaf.v2_0; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.cadi.AbsUserCache; +import org.onap.aaf.cadi.Locator; +import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.aaf.AAFPermission; + + +public class JU_AAFSingleLocator { + + @Mock + AAFCon con; + + @Mock + AbsUserCache<AAFPermission> cache; + + @Mock + PropAccess propaccess; + + + AAFSingleLocator authnObj; + + @Before + public void setUp() { + initMocks(this); + try { + authnObj = new AAFSingleLocator("http://www.google.com"); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testGetRealm() { + try { + URI retVal = authnObj.get(Mockito.mock( Locator.Item.class)); + assertEquals("www.google.com",retVal.getHost()); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testHasItem() { + boolean retVal = authnObj.hasItems(); + assertTrue(retVal); + } + + @Test + public void testInvalidate() { + try { + authnObj.invalidate(Mockito.mock( Locator.Item.class)); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testBest() { + try { + Locator.Item retVal = authnObj.best(); + assertTrue(retVal.toString().contains("org.onap.aaf.cadi.aaf.v2_0.AAFSingleLocator$SingleItem")); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Test + public void testFirst() { + try { + Locator.Item retVal = authnObj.first(); + assertTrue(retVal.toString().contains("org.onap.aaf.cadi.aaf.v2_0.AAFSingleLocator$SingleItem")); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Test + public void testNext() { + try { + Locator.Item retVal = authnObj.next(Mockito.mock( Locator.Item.class)); + assertNull(retVal); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testRefres() { + boolean retVal = authnObj.refresh(); + assertFalse(retVal); + } + + @Test + public void testdestroy() { + authnObj.destroy(); + } + + +} diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java index 599bb984..461ef43c 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java @@ -93,10 +93,20 @@ public class PropAccess implements Access { int eq; for (String arg : args) { if ((eq=arg.indexOf('='))>0) { - nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1)); + String key = arg.substring(0, eq); + if(Config.CADI_PROP_FILES.equals(key)) { + nprops.setProperty(key,arg.substring(eq+1)); + } } } init(nprops); + + // Re-overlay Args + for (String arg : args) { + if ((eq=arg.indexOf('='))>0) { + props.setProperty(arg.substring(0, eq),arg.substring(eq+1)); + } + } } protected void init(Properties p) { @@ -105,15 +115,16 @@ public class PropAccess implements Access { level=DEFAULT.maskOf(); props = new Properties(); - // First, load related System Properties + + // Find the "cadi_prop_files" + // First in VM Args for (Entry<Object,Object> es : System.getProperties().entrySet()) { String key = es.getKey().toString(); - for (String start : new String[] {"HOSTNAME","cadi_","aaf_","cm_"}) { - if (key.startsWith(start)) { - props.put(key, es.getValue()); - } - } + if(Config.CADI_PROP_FILES.equals(key)) { + props.put(key,es.getValue().toString()); + } } + // Second, overlay or fill in with Passed in Props if (p!=null) { props.putAll(p); @@ -122,6 +133,16 @@ public class PropAccess implements Access { // Third, load any Chained Property Files load(props.getProperty(Config.CADI_PROP_FILES)); + // Fourth, System.getProperties takes precedence over Files + for (Entry<Object,Object> es : System.getProperties().entrySet()) { + String key = es.getKey().toString(); + for (String start : new String[] {"HOSTNAME","cadi_","aaf_","cm_"}) { + if (key.startsWith(start)) { + props.put(key, es.getValue()); + } + } + } + String sLevel = props.getProperty(Config.CADI_LOGLEVEL); if (sLevel!=null) { level=Level.valueOf(sLevel).maskOf(); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java index fc972c8c..62623fb8 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java @@ -151,13 +151,13 @@ public class Config { public static final String AAF_DEFAULT_API_VERSION = "2.1"; public static final String AAF_API_VERSION = "aaf_api_version"; public static final String AAF_URL = "aaf_url"; //URL for AAF... Use to trigger AAF configuration - public static final String AAF_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.service:" + AAF_DEFAULT_API_VERSION; - public static final String GUI_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.gui:" + AAF_DEFAULT_API_VERSION; - public static final String CM_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.cm:" + AAF_DEFAULT_API_VERSION; - public static final String FS_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.fs:" + AAF_DEFAULT_API_VERSION; - public static final String HELLO_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.hello:" + AAF_DEFAULT_API_VERSION; - public static final String OAUTH2_TOKEN_URL = "https://AAF_LOCATE_URL/AAF_NS.token:" + AAF_DEFAULT_API_VERSION; - public static final String OAUTH2_INTROSPECT_URL = "https://AAF_LOCATE_URL/AAF_NS.introspect:" + AAF_DEFAULT_API_VERSION; + public static final String AAF_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.service:" + AAF_DEFAULT_API_VERSION; + public static final String GUI_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.gui:" + AAF_DEFAULT_API_VERSION; + public static final String CM_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.cm:" + AAF_DEFAULT_API_VERSION; + public static final String FS_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.fs:" + AAF_DEFAULT_API_VERSION; + public static final String HELLO_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.hello:" + AAF_DEFAULT_API_VERSION; + public static final String OAUTH2_TOKEN_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.token:" + AAF_DEFAULT_API_VERSION +"/token"; + public static final String OAUTH2_INTROSPECT_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.introspect:" + AAF_DEFAULT_API_VERSION +"/introspect";; public static final String AAF_LOCATOR_CLASS = "aaf_locator_class"; // AAF Locator Entries are ADDITIONAL entries, which also gives the Property ability @@ -258,6 +258,12 @@ public class Config { public static HttpTaf configHttpTaf(Connector con, SecurityInfoC<HttpURLConnection> si, TrustChecker tc, CredVal up, Lur lur, Object ... additionalTafLurs) throws CadiException, LocatorException { Access access = si.access; + RegistrationPropHolder rph; + try { + rph = new RegistrationPropHolder(access, 0); + } catch (UnknownHostException e2) { + throw new CadiException(e2); + } ///////////////////////////////////////////////////// // Setup AAFCon for any following ///////////////////////////////////////////////////// @@ -277,7 +283,7 @@ public class Config { boolean hasDirectAAF = hasDirect("DirectAAFLur",additionalTafLurs); // IMPORTANT! Don't attempt to load AAF Connector if there is no AAF URL - String aafURL = access.getProperty(AAF_URL,null); + String aafURL = logProp(rph, AAF_URL,null); if (!hasDirectAAF && aafcon==null && aafURL!=null) { aafcon = loadAAFConnector(si, aafURL); } @@ -352,8 +358,8 @@ public class Config { Class<HttpTaf> obasicCls = (Class<HttpTaf>)loadClass(access,CADI_OBASIC_HTTP_TAF_DEF); if (obasicCls!=null) { try { - String tokenurl = logProp(access,Config.AAF_OAUTH2_TOKEN_URL, null); - String introspecturl = logProp(access,Config.AAF_OAUTH2_INTROSPECT_URL, null); + String tokenurl = logProp(rph,Config.AAF_OAUTH2_TOKEN_URL, null); + String introspecturl = logProp(rph,Config.AAF_OAUTH2_INTROSPECT_URL, null); if (tokenurl==null || introspecturl==null) { access.log(Level.INIT,"Both tokenurl and introspecturl are required. Oauth Authorization is disabled."); } @@ -431,7 +437,7 @@ public class Config { // Configure OAuth TAF ///////////////////////////////////////////////////// if (!hasOAuthDirectTAF) { - String oauthTokenUrl = logProp(access,Config.AAF_OAUTH2_TOKEN_URL,null); + String oauthTokenUrl = logProp(rph,Config.AAF_OAUTH2_TOKEN_URL,null); Class<?> oadtClss; try { oadtClss = Class.forName(OAUTH_DIRECT_TAF); @@ -448,7 +454,7 @@ public class Config { additionalTafLurs = array; access.log(Level.INIT,"OAuth2 Direct is enabled"); } else if (oauthTokenUrl!=null) { - String oauthIntrospectUrl = logProp(access,Config.AAF_OAUTH2_INTROSPECT_URL,null); + String oauthIntrospectUrl = logProp(rph,Config.AAF_OAUTH2_INTROSPECT_URL,null); @SuppressWarnings("unchecked") Class<HttpTaf> oaTCls = (Class<HttpTaf>)loadClass(access,OAUTH_HTTP_TAF); if (oaTCls!=null) { @@ -549,7 +555,7 @@ public class Config { } access.log(Level.INIT, sb); - Locator<URI> locator = loadLocator(si, logProp(access, AAF_LOCATE_URL, null)); + Locator<URI> locator = loadLocator(si, logProp(rph, AAF_LOCATE_URL, null)); taf = new HttpEpiTaf(access,locator, tc, htarray); // ok to pass locator == null String level = logProp(access, CADI_LOGLEVEL, null); @@ -561,6 +567,18 @@ public class Config { return taf; } + public static String logProp(RegistrationPropHolder rph, String tag, String def) { + String rv = rph.access().getProperty(tag, def); + if (rv == null) { + rph.access().log(Level.INIT,tag,"is not explicitly set"); + } else { + rv = rph.replacements(rv, null, null); + rph.access().log(Level.INIT,tag,"is set to",rv); + } + return rv; + + } + public static String logProp(Access access,String tag, String def) { String rv = access.getProperty(tag, def); if (rv == null) { @@ -573,6 +591,13 @@ public class Config { public static Lur configLur(SecurityInfoC<HttpURLConnection> si, Connector con, Object ... additionalTafLurs) throws CadiException { Access access = si.access; + RegistrationPropHolder rph; + try { + rph = new RegistrationPropHolder(access, 0); + } catch (UnknownHostException e2) { + throw new CadiException(e2); + } + List<Priori<Lur>> lurs = new ArrayList<>(); ///////////////////////////////////////////////////// @@ -601,8 +626,8 @@ public class Config { ///////////////////////////////////////////////////// // Configure the OAuth Lur (if any) ///////////////////////////////////////////////////// - String tokenUrl = logProp(access,AAF_OAUTH2_TOKEN_URL, null); - String introspectUrl = logProp(access,AAF_OAUTH2_INTROSPECT_URL, null); + String tokenUrl = logProp(rph,AAF_OAUTH2_TOKEN_URL, null); + String introspectUrl = logProp(rph,AAF_OAUTH2_INTROSPECT_URL, null); if (tokenUrl!=null && introspectUrl !=null) { try { Class<?> olurCls = loadClass(access, CADI_OLUR_CLASS_DEF); @@ -631,7 +656,7 @@ public class Config { ///////////////////////////////////////////////////// // Configure the AAF Lur (if any) ///////////////////////////////////////////////////// - String aafURL = logProp(access,AAF_URL,null); // Trigger Property + String aafURL = logProp(rph,AAF_URL,null); // Trigger Property String aafEnv = access.getProperty(AAF_ENV,null); if (aafEnv == null && aafURL!=null && access instanceof PropAccess) { // set AAF_ENV from AAF_URL int ec = aafURL.indexOf("envContext="); @@ -822,41 +847,11 @@ public class Config { try { rph = new RegistrationPropHolder(access, 0); url = rph.replacements(_url, null, null); + access.printf(Level.INFO, "loadLocator URL is %s",url); } catch (UnknownHostException | CadiException e1) { throw new LocatorException(e1); } -// if(url.indexOf('%')>=0) { -// String str = access.getProperty(Config.AAF_LOCATOR_CONTAINER_ID, null); -// if(str==null) { -// url = url.replace("%CID",""); -// } else { -// url = url.replace("%CID",str+'.'); -// } -// str = access.getProperty(Config.AAF_LOCATOR_CONTAINER, null); -// if(str==null) { -// url = url.replace("%C",""); -// } else { -// url = url.replace("%C",str+'.'); -// } -// -// if (root_ns==null) { -// url = url.replace("%AAF_NS",""); -// } else { -// url = url.replace("%AAF_NS",root_ns); -// } -// } - String replacement; - int idxAAFLocateUrl; - if ((idxAAFLocateUrl=url.indexOf(AAF_LOCATE_URL_TAG))>0 && ((replacement=access.getProperty(AAF_LOCATE_URL, null))!=null)) { - StringBuilder sb = new StringBuilder(replacement); - if (!replacement.endsWith("/locate")) { - sb.append("/locate"); - } - sb.append(url,idxAAFLocateUrl+AAF_LOCATE_URL_TAG.length(),url.length()); - url = sb.toString(); - } - try { Class<?> lcls = loadClass(access,AAF_LOCATOR_CLASS_DEF); if (lcls==null) { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java index b6cd533c..68a018d6 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java @@ -41,6 +41,7 @@ public class RegistrationPropHolder { public final String default_name; public final String lentries; public final String lcontainer; + public final String default_container; public RegistrationPropHolder(final Access access, final int port) throws UnknownHostException, CadiException { this.access = access; @@ -50,15 +51,15 @@ public class RegistrationPropHolder { lentries=access.getProperty(Config.AAF_LOCATOR_ENTRIES,""); - str = access.getProperty(Config.AAF_LOCATOR_CONTAINER, ""); - if(!str.isEmpty()) { - lcontainer=',' + str; // "" makes a blank default Public Entry - str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT+'.'+str, null); + default_container = access.getProperty(Config.AAF_LOCATOR_CONTAINER, ""); + if(!default_container.isEmpty()) { + lcontainer=',' + default_container; // "" makes a blank default Public Entry + str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT+'.'+default_container, null); if(str==null) { str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT, null); } } else { - lcontainer=str; + lcontainer=default_container; str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT, null); } if(str!=null) { @@ -149,47 +150,42 @@ public class RegistrationPropHolder { } - public String replacements(String source, final String name, final String dot_le) { + public String replacements(String source, final String name, final String _dot_le) { if(source == null) { return ""; } else if(source.isEmpty()) { return source; } - String str; - // aaf_locate_url - if(source.indexOf(Config.AAF_LOCATE_URL_TAG)>=0) { - str = access.getProperty(Config.AAF_LOCATE_URL, null); - if(str!=null) { - if(!str.endsWith("/")) { - str+='/'; - } - if(!str.endsWith("/locate/")) { - str+="locate/"; - } - source = source.replace("https://AAF_LOCATE_URL/", str); - } + + String dot_le; + if(_dot_le==null) { + dot_le = default_container.isEmpty()?"":'.'+default_container; + } else { + dot_le = _dot_le; } - if(source.indexOf("%NS")>=0) { - str = getNS(dot_le); - if(str==null || str.isEmpty()) { - source = source.replace("%NS"+'.', str); - } - source = source.replace("%NS", str); - } + String aaf_locator_host = access.getProperty(Config.AAF_LOCATE_URL+dot_le,null); + if(aaf_locator_host==null) { + aaf_locator_host = access.getProperty(Config.AAF_LOCATE_URL,null); + } - // aaf_root_ns - if(source.indexOf("AAF_NS")>=0) { - str = access.getProperty(Config.AAF_ROOT_NS, null); - if(str!=null) { - String temp = source.replace("%AAF_NS", str); - if(temp == source) { // intended - source = source.replace("AAF_NS", str); // Backward Compatibility - } else { - source = temp; + String str; + if(aaf_locator_host!=null) { + if("https://AAF_LOCATE_URL".equals(source)) { + source = aaf_locator_host; + } else { + str = aaf_locator_host; + if(source.indexOf(Config.AAF_LOCATE_URL_TAG)>=0) { + if(!str.endsWith("/")) { + str+='/'; + } + if(!str.endsWith("/locate/")) { + str+="locate/"; + } + source = source.replace("https://AAF_LOCATE_URL/", str); } } - } + } int atC = source.indexOf("%C"); if(atC>=0) { @@ -200,18 +196,44 @@ public class RegistrationPropHolder { } source = source.replace("%CNS", str); - str = access.getProperty(Config.AAF_LOCATOR_CONTAINER+dot_le, ""); + str = access.getProperty(Config.AAF_LOCATOR_CONTAINER+dot_le,default_container); if(str.isEmpty()) { source = source.replace("%C"+'.', str); } source = source.replace("%C", str); } + if(source.indexOf("%NS")>=0) { + str = getNS(dot_le); + if(str==null || str.isEmpty()) { + source = source.replace("%NS"+'.', str); + } + source = source.replace("%NS", str); + } + + // aaf_root_ns + if(source.indexOf("AAF_NS")>=0) { + str = access.getProperty(Config.AAF_ROOT_NS, Config.AAF_ROOT_NS_DEF); + String temp = source.replace("%AAF_NS", str); + if(temp.equals(source)) { // intended + source = source.replace("AAF_NS", str); // Backward Compatibility + } else { + source = temp; + } + } + + if(source.indexOf('%')>=0) { - // These shouldn't be expected to have dot elements - source = source.replace("%N", name); - source = source.replace("%DF", default_fqdn); - source = source.replace("%PH", public_hostname); + // These shouldn't be expected to have dot elements + if(name!=null) { + source = source.replace("%N", name); + } + if(default_fqdn!=null) { + source = source.replace("%DF", default_fqdn); + } + if(public_hostname!=null) { + source = source.replace("%PH", public_hostname); + } } return source; } @@ -221,4 +243,8 @@ public class RegistrationPropHolder { public_port: port; } + + public Access access() { + return access; + } }
\ No newline at end of file diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java index 677f2139..fca99a31 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java @@ -134,7 +134,7 @@ public class X509Taf implements HttpTaf { // Note: If the Issuer is not in the TrustStore, it's not added to the Cert list String issuer = certarr[0].getIssuerDN().toString(); String subject = certarr[0].getSubjectDN().getName(); - access.printf(Level.DEBUG,"Client Certificate found\n Subject %s\n Issuer %s",subject,issuer); + access.printf(Level.DEBUG,"Client Certificate found\n Subject '%s'\n Issuer '%s'",subject,issuer); if (cadiIssuers.contains(issuer)) { // avoiding extra object creation, since this is validated EVERY transaction with a Cert int start = 0; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java index a834db51..a3958878 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java @@ -57,6 +57,10 @@ public class CSV { processAll = false; } + public String name() { + return csv.getName(); + } + public CSV processAll() { processAll = true; return this; @@ -85,7 +89,7 @@ public class CSV { List<String> row = new ArrayList<>(); boolean quotes=false; boolean escape=false; - char c; + char c = 0; for(int i=0;i<line.length();++i) { switch(c=line.charAt(i)) { case '"': @@ -124,7 +128,7 @@ public class CSV { sb.append(c); } } - if(sb.length()>0) { + if(sb.length()>0 || c==',') { row.add(sb.toString()); sb.setLength(0); } @@ -197,9 +201,10 @@ public class CSV { * Note: CSV files do not actually support Comments as a standard, but it is useful * @param comment */ - public void comment(String comment) { + public void comment(String comment, Object ... objs) { ps.print("# "); - ps.println(comment); + ps.printf(comment,objs); + ps.println(); } public void flush() { diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java index 46fd741d..18e26f55 100644 --- a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java +++ b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java @@ -130,8 +130,8 @@ public class JU_RegistrationPropHolder { target = "mycontns.org.osaaf.aaf.theName"; assertEquals(target,rph.replacements(fqdn, name, ".hello")); - pa.setProperty(Config.AAF_LOCATOR_CONTAINER+".hello","hello"); - target = "hello.mycontns.org.osaaf.aaf.theName"; + pa.setProperty(Config.AAF_LOCATOR_CONTAINER+".hello","helloC"); + target = "helloC.mycontns.org.osaaf.aaf.theName"; assertEquals(target,rph.replacements(fqdn, name, ".hello")); pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS,"c_ns"); diff --git a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java index cd9c2313..10bcdcc2 100644 --- a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java +++ b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java @@ -73,10 +73,10 @@ public class OAuthExample { // Obtain Endpoints for OAuth2 from Properties. Expected is "cadi.properties" file, pointed to by "cadi_prop_files" - String tokenServiceURL = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL,Defaults.OAUTH2_TOKEN_URL); // Default to AAF - String tokenIntrospectURL = access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL,Defaults.OAUTH2_INTROSPECT_URL); // Default to AAF); + String tokenServiceURL = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL,Config.OAUTH2_TOKEN_URL_DEF); // Default to AAF + String tokenIntrospectURL = access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL,Config.OAUTH2_INTROSPECT_URL_DEF); // Default to AAF); // Get Hello Service - final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL,Defaults.HELLO_URL); + final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL,Config.HELLO_URL_DEF); final int CALL_TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CALL_TIMEOUT,Config.AAF_CALL_TIMEOUT_DEF)); diff --git a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java index f4fe017f..0a653297 100644 --- a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java +++ b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java @@ -104,7 +104,7 @@ public class OnapClientExample { // Use this Token in your client calls with "Tokenized Client" (TzClient) // These should NOT be used cross thread. // Get Hello Service URL... roll your own in your own world. - final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL,Defaults.HELLO_URL); + final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL,Config.HELLO_URL_DEF); TzClient helloClient = tcf.newTzClient(endServicesURL); |