Fix Agent and CM Issues
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / aaf / v2_0 / AAFAuthn.java
index edacdfd..c48e35f 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.
@@ -29,14 +29,14 @@ import org.onap.aaf.cadi.CadiException;
 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.config.Config;
 import org.onap.aaf.cadi.lur.ConfigPrincipal;
 
+import aaf.v2_0.CredRequest;
+
 public class AAFAuthn<CLIENT> extends AbsUserCache<AAFPermission> {
     private AAFCon<CLIENT> con;
     private String realm;
-    
+
     /**
      * Configure with Standard AAF properties, Stand alone
      * @param con
@@ -51,17 +51,17 @@ public class AAFAuthn<CLIENT> extends AbsUserCache<AAFPermission> {
     /**
      * Configure with Standard AAF properties, but share the Cache (with AAF Lur)
      * @param con
-     * @throws Exception 
+     * @throws Exception
      */
     // Package on purpose
     AAFAuthn(AAFCon<CLIENT> con, AbsUserCache<AAFPermission> cache) {
         super(cache);
         this.con = con;
     }
-    
+
     /**
      * Return Native Realm of AAF Instance.
-     * 
+     *
      * @return
      */
     public String getRealm() {
@@ -70,24 +70,24 @@ public class AAFAuthn<CLIENT> extends AbsUserCache<AAFPermission> {
 
     /**
      * Returns null if ok, or an Error String;
-     * 
+     *
      * Convenience function.  Passes "null" for State object
      */
     public String validate(String user, String password) throws IOException {
         return validate(user,password,null);
     }
-    
+
     /**
      * Returns null if ok, or an Error String;
-     * 
+     *
      * For State Object, you may put in HTTPServletRequest or AuthzTrans, if available.  Otherwise,
      * leave null
-     * 
+     *
      * @param user
      * @param password
      * @return
-     * @throws IOException 
-     * @throws CadiException 
+     * @throws IOException
+     * @throws CadiException
      * @throws Exception
      */
     public String validate(String user, String password, Object state) throws IOException {
@@ -95,8 +95,8 @@ public class AAFAuthn<CLIENT> extends AbsUserCache<AAFPermission> {
         byte[] bytes = password.getBytes();
         User<AAFPermission> usr = getUser(user,bytes);
 
-        if(usr != null && !usr.permExpired()) {
-            if(usr.principal==null) {
+        if (usr != null && !usr.permExpired()) {
+            if (usr.principal==null) {
                 return "User already denied";
             } else {
                 return null; // good
@@ -108,7 +108,7 @@ public class AAFAuthn<CLIENT> extends AbsUserCache<AAFPermission> {
         // Statement
         switch(cp.revalidate(state)) {
             case REVALIDATED:
-                if(usr!=null) {
+                if (usr!=null) {
                     usr.principal = cp;
                 } else {
                     addUser(new User<AAFPermission>(cp,con.timeout));
@@ -118,14 +118,14 @@ public class AAFAuthn<CLIENT> extends AbsUserCache<AAFPermission> {
                 return "AAF Inaccessible";
             case UNVALIDATED:
                 addUser(new User<AAFPermission>(user,bytes,con.timeout));
-                return "User/Pass combo invalid for " + user;
+                return "user/pass combo invalid for " + user;
             case DENIED:
                 return "AAF denies API for " + user;
-            default: 
+            default:
                 return "AAFAuthn doesn't handle Principal " + user;
         }
     }
-    
+
     private class AAFCachedPrincipal extends ConfigPrincipal implements CachedPrincipal {
         private long expires;
         private long timeToLive;
@@ -139,13 +139,17 @@ public class AAFAuthn<CLIENT> extends AbsUserCache<AAFPermission> {
         public Resp revalidate(Object state) {
             try {
                 Miss missed = missed(getName(),getCred());
-                if(missed==null || missed.mayContinue()) {
-                    Rcli<CLIENT> client = con.client(Config.AAF_DEFAULT_VERSION).forUser(con.basicAuth(getName(), new String(getCred())));
-                    Future<String> fp = client.read(
-                            "/authn/basicAuth",
-                            "text/plain"
-                            );
-                    if(fp.get(con.timeout)) {
+                if (missed==null || missed.mayContinue()) {
+                    CredRequest cr = new CredRequest();
+                    cr.setId(getName());
+                    cr.setPassword(new String(getCred()));
+                    Future<String> fp = con.client().readPost("/authn/validate", con.credReqDF, cr);
+                    //Rcli<CLIENT> client = con.client().forUser(con.basicAuth(getName(), new String(getCred())));
+                    //Future<String> fp = client.read(
+                    //        "/authn/basicAuth",
+                    //        "text/plain"
+                    //       );
+                     if (fp.get(con.timeout)) {
                         expires = System.currentTimeMillis() + timeToLive;
                         addUser(new User<AAFPermission>(this, expires));
                         return Resp.REVALIDATED;