Agent correctly sort Cert Chain/Truststore
[aaf/authz.git] / auth / auth-core / src / main / java / org / onap / aaf / auth / server / AbsService.java
index 497860a..5fbb951 100644 (file)
@@ -34,6 +34,7 @@ import org.onap.aaf.cadi.Access;
 import org.onap.aaf.cadi.Access.Level;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.LocatorException;
+import org.onap.aaf.cadi.aaf.Defaults;
 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
 import org.onap.aaf.cadi.client.Rcli;
 import org.onap.aaf.cadi.client.Retryable;
@@ -53,37 +54,32 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
 
     public final String app_name;
     public final String app_version;
-    public final String app_interface_version;
     public final String ROOT_NS;
-
+    
     public AbsService(final Access access, final ENV env) throws CadiException {
-            Define.set(access);
-            ROOT_NS = Define.ROOT_NS();
+        Define.set(access);
+        ROOT_NS = Define.ROOT_NS();
         this.access = access;
         this.env = env;
 
-        String component = access.getProperty(Config.AAF_COMPONENT, null);
-        final String[] locator_deploy;
-        
-        if(component == null) {
-            locator_deploy = null;
+        String str = access.getProperty(Config.AAF_LOCATOR_ENTRIES, null);
+        String[] scomp = Split.splitTrim(',', str);
+        if(scomp.length==0) {
+               throw new CadiException(Config.AAF_LOCATOR_ENTRIES + " must be defined.");
         } else {
-            locator_deploy = Split.splitTrim(':', component);
+               str = ROOT_NS + '.' + scomp[0];
         }
-            
-        if(component == null || locator_deploy==null || locator_deploy.length<2) {
-            throw new CadiException("AAF Component must include the " + Config.AAF_COMPONENT + " property, <fully qualified service name>:<full deployed version (i.e. 2.1.3.13)");
-        }
-        final String[] version = Split.splitTrim('.', locator_deploy[1]);
-        if(version==null || version.length<2) {
-            throw new CadiException("AAF Component Version must have at least Major.Minor version");
+        app_name = str;
+        
+        str = access.getProperty(Config.AAF_LOCATOR_VERSION, null);
+        if(str==null) {
+               str = Defaults.AAF_VERSION;
+               env.setProperty(Config.AAF_LOCATOR_VERSION, str);
         }
-            app_name = Define.varReplace(locator_deploy[0]);
-            app_version = locator_deploy[1];
-            app_interface_version = version[0]+'.'+version[1];
-            
+        app_version = access.getProperty(Config.AAF_DEPLOYED_VERSION, str);
+        
         // Print Cipher Suites Available
-        if(access.willLog(Level.DEBUG)) {
+        if (access.willLog(Level.DEBUG)) {
             SSLContext context;
             try {
                 context = SSLContext.getDefault();
@@ -94,16 +90,24 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
             StringBuilder sb = new StringBuilder("Available Cipher Suites: ");
             boolean first = true;
             int count=0;
-            for( String cs : sf.getSupportedCipherSuites()) {
-                if(first)first = false;
+            for ( String cs : sf.getSupportedCipherSuites()) {
+                if (first)first = false;
                 else sb.append(',');
                 sb.append(cs);
-                if(++count%4==0){sb.append('\n');}
+                if (++count%4==0){sb.append('\n');}
             }
             access.log(Level.DEBUG,sb);
         }
     }
+    
+    public void setProtocol(String proto) {
+       env.setProperty(Config.AAF_LOCATOR_PROTOCOL, proto);
+    }
 
+    public void setSubprotocol(String subproto) {
+       env.setProperty(Config.AAF_LOCATOR_SUBPROTOCOL, subproto);
+    }
+    
     protected abstract Filter[] _filters(Object ... additionalTafLurs) throws CadiException,  LocatorException;
     
     /**
@@ -117,12 +121,12 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
         return _filters();
     }
 
-    public abstract Registrant<ENV>[] registrants(final int port) throws CadiException, LocatorException;
+    public abstract Registrant<ENV>[] registrants(final int actualPort) throws CadiException, LocatorException;
 
     // Lazy Instantiation
     public synchronized AAFConHttp aafCon() throws CadiException, LocatorException {
-            if(aafCon==null) {
-                if(access.getProperty(Config.AAF_URL,null)!=null) {
+            if (aafCon==null) {
+                if (access.getProperty(Config.AAF_URL,null)!=null) {
                     aafCon = _newAAFConHttp();
                 } else {
                     throw new CadiException("AAFCon cannot be constructed without " + Config.AAF_URL);
@@ -137,7 +141,7 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
      * @throws LocatorException 
      */
         protected synchronized AAFConHttp _newAAFConHttp() throws CadiException, LocatorException {
-            if(aafCon==null) {
+            if (aafCon==null) {
                 aafCon = new AAFConHttp(access);
             }
             return aafCon;
@@ -150,11 +154,11 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
     }
     
     public Rcli<?> client() throws CadiException {
-        return aafCon.client(Config.AAF_DEFAULT_VERSION);
+        return aafCon.client();
     }
 
     public Rcli<?> clientAsUser(TaggedPrincipal p) throws CadiException {
-        return aafCon.client(Config.AAF_DEFAULT_VERSION).forUser(
+        return aafCon.client().forUser(
                 new HTransferSS(p,app_name, aafCon.securityInfo()));
     }
 
@@ -165,23 +169,22 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
     protected static final String loadFromArgOrSystem(final Properties props, final String tag, final String args[], final String def) {
         String tagEQ = tag + '=';
         String value;
-        for(String arg : args) {
-            if(arg.startsWith(tagEQ)) {
+        for (String arg : args) {
+            if (arg.startsWith(tagEQ)) {
                 props.put(tag, value=arg.substring(tagEQ.length()));
                 return value;
             }
         }
         // check System.properties
         value = System.getProperty(tag);
-        if(value!=null) { 
+        if (value!=null) { 
             props.put(tag, value);
             return value;
         }
         
-        if(def!=null) {
+        if (def!=null) {
             props.put(tag,def);
         }
         return def;
     }
-
 }