changed to unmaintained
[aaf/authz.git] / auth / auth-core / src / main / java / org / onap / aaf / auth / server / AbsService.java
index f249544..0e770e5 100644 (file)
@@ -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.
@@ -25,7 +25,7 @@ import java.security.NoSuchAlgorithmException;
 import java.util.Properties;
 
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.SSLServerSocketFactory;
 import javax.servlet.Filter;
 
 import org.onap.aaf.auth.common.Define;
@@ -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;
@@ -51,37 +52,32 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
     public final ENV env;
     private AAFConHttp aafCon;
 
-    public final String app_name;
-    public final String app_version;
-    public final String app_interface_version;
-    public final String ROOT_NS;
+    public final String appName;
+    public final String appVersion;
+    public final String rootNs;
 
     public AbsService(final Access access, final ENV env) throws CadiException {
-            Define.set(access);
-            ROOT_NS = Define.ROOT_NS();
+        Define.set(access);
+        rootNs = 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);
-        }
-            
-        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)");
+            str = rootNs + '.' + scomp[0];
         }
-        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");
+        appName = 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];
-            
+        appVersion = access.getProperty(Config.AAF_DEPLOYED_VERSION, str);
+
         // Print Cipher Suites Available
         if (access.willLog(Level.DEBUG)) {
             SSLContext context;
@@ -90,7 +86,7 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
             } catch (NoSuchAlgorithmException e) {
                 throw new CadiException("SSLContext issue",e);
             }
-            SSLSocketFactory sf = context.getSocketFactory();
+            SSLServerSocketFactory sf = context.getServerSocketFactory();
             StringBuilder sb = new StringBuilder("Available Cipher Suites: ");
             boolean first = true;
             int count=0;
@@ -104,11 +100,19 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
         }
     }
 
+    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;
-    
+
     /**
      * Overload this method to add new TAF or LURs
-     * 
+     *
      * @return
      * @throws CadiException
      * @throws LocatorException
@@ -117,7 +121,7 @@ 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 {
@@ -130,11 +134,11 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
             }
             return aafCon;
     }
-    
+
     /**
      * Allow to be over ridden for special cases
      * @return
-     * @throws LocatorException 
+     * @throws LocatorException
      */
         protected synchronized AAFConHttp _newAAFConHttp() throws CadiException, LocatorException {
             if (aafCon==null) {
@@ -143,25 +147,25 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
             return aafCon;
 
         }
-    
+
     // This is a method, so we can overload for AAFAPI
     public String aaf_url() {
             return access.getProperty(Config.AAF_URL, null);
     }
-    
+
     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(
-                new HTransferSS(p,app_name, aafCon.securityInfo()));
+        return aafCon.client().forUser(
+                new HTransferSS(p, appName, aafCon.securityInfo()));
     }
 
     public<RET> RET clientAsUser(TaggedPrincipal p,Retryable<RET> retryable) throws APIException, LocatorException, CadiException  {
-            return aafCon.hman().best(new HTransferSS(p,app_name, aafCon.securityInfo()), retryable);
+            return aafCon.hman().best(new HTransferSS(p, appName, aafCon.securityInfo()), retryable);
     }
-    
+
     protected static final String loadFromArgOrSystem(final Properties props, final String tag, final String args[], final String def) {
         String tagEQ = tag + '=';
         String value;
@@ -173,15 +177,14 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
         }
         // check System.properties
         value = System.getProperty(tag);
-        if (value!=null) { 
+        if (value!=null) {
             props.put(tag, value);
             return value;
         }
-        
+
         if (def!=null) {
             props.put(tag,def);
         }
         return def;
     }
-
 }