Update for more Logging Info
[aaf/authz.git] / auth / auth-service / src / main / java / org / onap / aaf / auth / service / mapper / Mapper_2_0.java
index 55c3bc8..7a5d0c1 100644 (file)
@@ -58,6 +58,7 @@ import org.onap.aaf.auth.org.Organization.Expiration;
 import org.onap.aaf.auth.rserv.Pair;
 import org.onap.aaf.auth.service.MayChange;
 import org.onap.aaf.cadi.aaf.marshal.CertsMarshal;
+import org.onap.aaf.cadi.util.Split;
 import org.onap.aaf.cadi.util.Vars;
 import org.onap.aaf.misc.env.Env;
 import org.onap.aaf.misc.env.TimeTaken;
@@ -364,18 +365,32 @@ public class Mapper_2_0 implements Mapper<Nss, Perms, Pkey, Roles, Users, UserRo
     @Override
     public Result<PermDAO.Data> perm(AuthzTrans trans, Request req) {
         PermRequest from = (PermRequest)req;
-        Result<NsSplit> nss = q.deriveNsSplit(trans, from.getType());
+        String type = from.getType();
+        if(type==null) {
+               return Result.err(Result.ERR_BadData, "Invalid Perm Type");
+        }
         PermDAO.Data pd = new PermDAO.Data();
-        if (nss.isOK()) { 
-            pd.ns=nss.value.ns;
-            pd.type = nss.value.name;
-            pd.instance = from.getInstance();
-            pd.action = from.getAction();
-            pd.description = from.getDescription();
-            trans.checkpoint(pd.fullPerm(), Env.ALWAYS);
-            return Result.ok(pd);
-        } else {
-            return Result.err(nss);
+        if(type.contains("@")) {
+               String[] split = Split.splitTrim(':', type);
+               pd.ns = split[0];
+               pd.type=split.length>1?split[1]:"";
+               pd.instance = from.getInstance();
+               pd.action = from.getAction();
+               pd.description = from.getDescription();
+               return Result.ok(pd);
+        }  else {
+               Result<NsSplit> nss = q.deriveNsSplit(trans, from.getType());
+               if (nss.isOK()) { 
+                   pd.ns=nss.value.ns;
+                   pd.type = nss.value.name;
+                   pd.instance = from.getInstance();
+                   pd.action = from.getAction();
+                   pd.description = from.getDescription();
+                   trans.checkpoint(pd.fullPerm(), Env.ALWAYS);
+                   return Result.ok(pd);
+               } else {
+                   return Result.err(nss);
+               }
         }
     }
     
@@ -509,22 +524,27 @@ public class Mapper_2_0 implements Mapper<Nss, Perms, Pkey, Roles, Users, UserRo
         CredDAO.Data to = new CredDAO.Data();
         to.id=from.getId();
         to.ns = Question.domain2ns(to.id);
-        String passwd = from.getPassword();
-        if (requiresPass) {
-            String ok = trans.org().isValidPassword(trans, to.id,passwd);
-            if (ok.length()>0) {
-                return Result.err(Status.ERR_BadData,ok);
-            }
-        } else {
-            to.type=0;
-        }
-        if (passwd != null) {
-            to.cred = ByteBuffer.wrap(passwd.getBytes());
-            to.type = CredDAO.RAW; 
+        to.type = from.getType();
+        if(to.type!=null && to.type==CredDAO.FQI) {
+               to.cred = null;
         } else {
-            to.type = 0;
-        }
-        
+               String passwd = from.getPassword();
+               if (requiresPass) {
+                   String ok = trans.org().isValidPassword(trans, to.id,passwd);
+                   if (ok.length()>0) {
+                       return Result.err(Status.ERR_BadData,ok);
+                   }
+               } else {
+                   to.type=0;
+               }
+               if (passwd != null) {
+                   to.cred = ByteBuffer.wrap(passwd.getBytes());
+                   to.type = CredDAO.RAW; 
+               } else {
+                   to.type = CredDAO.FQI;
+               }
+        }
+               
         // Note: Ensure requested EndDate created will match Organization Password Rules
         //  P.S. Do not apply TempPassword rule here. Do that when you know you are doing a Create/Reset (see Service)
         to.expires = getExpires(trans.org(),Expiration.Password,base,from.getId());
@@ -541,6 +561,7 @@ public class Mapper_2_0 implements Mapper<Nss, Perms, Pkey, Roles, Users, UserRo
             user.setId(cred.id);
             user.setExpires(Chrono.timeStamp(cred.expires));
             user.setType(cred.type);
+            user.setTag(cred.tag);
             cu.add(user);
         }
         return Result.ok(to);
@@ -672,7 +693,7 @@ public class Mapper_2_0 implements Mapper<Nss, Perms, Pkey, Roles, Users, UserRo
         Error err = new Error();
         err.setMessageId(msgID);
         // AT&T Restful Error Format requires numbers "%" placements
-        err.setText(Vars.convert(holder, text, var));
+        err.setText(Vars.convert(holder, text, (Object[])var));
         for (String s : var) {
             err.getVariables().add(s);
         }