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;
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);
}
}
return instance;
}
-
+
/**
* Pickup Timeout from Properties
*
}
}
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 {
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
}