Fix testing results for Authn
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / oauth / TokenClientFactory.java
index 3f6fa59..28bf659 100644 (file)
@@ -43,6 +43,7 @@ import org.onap.aaf.cadi.aaf.v2_0.AAFLocator;
 import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.config.SecurityInfoC;
 import org.onap.aaf.cadi.locator.PropertyLocator;
+import org.onap.aaf.cadi.locator.SingleEndpointLocator;
 import org.onap.aaf.cadi.oauth.TokenClient.AUTHN_METHOD;
 import org.onap.aaf.cadi.persist.Persist;
 import org.onap.aaf.cadi.principal.Kind;
@@ -53,13 +54,21 @@ import aafoauth.v2_0.Token;
 
 public class TokenClientFactory extends Persist<Token,TimedToken> {
        private static TokenClientFactory instance;
-       private Map<String,AAFConHttp> aafcons = new ConcurrentHashMap<String, AAFConHttp>();
+       private Map<String,AAFConHttp> aafcons = new ConcurrentHashMap<>();
        private SecurityInfoC<HttpURLConnection> hsi;
        // Package on purpose
-       final Symm symm;        
+       final Symm symm;
 
        private TokenClientFactory(Access pa) throws APIException, GeneralSecurityException, IOException, CadiException {
                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, "https://AAF_LOCATE_URL/AAF_NS.token:2.0"); // Default to AAF
+               }
+               if(access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL,null)==null) {
+                       access.getProperties().put(Config.AAF_OAUTH2_INTROSPECT_URL, "https://AAF_LOCATE_URL/AAF_NS.introspect:2.0"); // Default to AAF);
+               }
+
                symm = Symm.encrypt.obtain();
                hsi = SecurityInfoC.instance(access, HttpURLConnection.class);
        }
@@ -70,7 +79,7 @@ public class TokenClientFactory extends Persist<Token,TimedToken> {
                }
                return instance;
        }
-
+       
        /**
         * Pickup Timeout from Properties
         * 
@@ -95,18 +104,23 @@ public class TokenClientFactory extends Persist<Token,TimedToken> {
                        }
                }
                char okind;
-               if(Config.AAF_OAUTH2_TOKEN_URL.equals(tagOrURL) || 
-                       tagOrURL.equals(access.getProperty(Config.AAF_OAUTH2_TOKEN_URL, null))) {
+               if( Config.AAF_OAUTH2_TOKEN_URL.equals(tagOrURL) ||
+                       Config.AAF_OAUTH2_INTROSPECT_URL.equals(tagOrURL) ||
+                       tagOrURL.equals(access.getProperty(Config.AAF_OAUTH2_TOKEN_URL, null)) ||
+                       tagOrURL.equals(access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL, null))
+                       ) {
                                okind = Kind.AAF_OAUTH;
                        } else {
                                okind = Kind.OAUTH;
                        }
-               return new TokenClient(
+               TokenClient tci = new TokenClient(
                                okind,
                                this,
                                ach,
                                timeout,
                                AUTHN_METHOD.none);
+               tci.client_creds(access);
+               return tci;
        }
        
        public TzClient newTzClient(final String locatorURL) throws CadiException, LocatorException {
@@ -158,12 +172,12 @@ public class TokenClientFactory extends Persist<Token,TimedToken> {
                if(locatorURL==null) {
                        throw new LocatorException("Cannot have a null locatorURL in bestLocator");
                }
-               if(locatePattern.matcher(locatorURL).matches()) {
+               if(locatorURL.startsWith("https://AAF_LOCATE_URL/") || locatePattern.matcher(locatorURL).matches()) {
                        return new AAFLocator(hsi,new URI(locatorURL));
-               } else if(locatorURL.contains("//DME2RESOLVE/")) {
-                       throw new LocatorException("DME2Locator doesn't exist.  Use DME2 specific Clients");
-               } else {
+               } else if(locatorURL.indexOf(',')>0) { // multiple URLs is a Property Locator
                        return new PropertyLocator(locatorURL);
+               } else {
+                       return new SingleEndpointLocator(locatorURL);
                }
                // Note: Removed DME2Locator... If DME2 client is needed, use DME2Clients
        }