Merge "Sonar fixes related to exceptions"
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / aaf / v2_0 / AAFLurPerm.java
index 41f237d..a5ef6d1 100644 (file)
@@ -59,8 +59,10 @@ import aaf.v2_0.Perms;
  *
  */
 public class AAFLurPerm extends AbsAAFLur<AAFPermission> {
+       private static final String ORG_OSAAF_CADI_OAUTH_O_AUTH2_LUR = "org.osaaf.cadi.oauth.OAuth2Lur";
+
        /**
-        *  Need to be able to transmutate a Principal into either ATTUID or MechID, which are the only ones accepted at this
+        *  Need to be able to transmutate a Principal into either Person or AppID, which are the only ones accepted at this
         *  point by AAF.  There is no "domain", aka, no "@att.com" in "ab1234@att.com".  
         *  
         *  The only thing that matters here for AAF is that we don't waste calls with IDs that obviously aren't valid.
@@ -90,7 +92,7 @@ public class AAFLurPerm extends AbsAAFLur<AAFPermission> {
                                        Constructor<?> tmconst = tmcls.getConstructor(AAFCon.class,String.class);
                                        Object tokMangr = tmconst.newInstance(con,oauth2_url);
                                        @SuppressWarnings("unchecked")
-                                       Class<Lur> oa2cls = (Class<Lur>)Config.loadClass(access,"org.osaaf.cadi.oauth.OAuth2Lur");
+                                       Class<Lur> oa2cls = (Class<Lur>)Config.loadClass(access,ORG_OSAAF_CADI_OAUTH_O_AUTH2_LUR);
                                        Constructor<Lur> oa2const = oa2cls.getConstructor(tmcls);
                                        Lur oa2 = oa2const.newInstance(tokMangr);
                                        setPreemptiveLur(oa2);
@@ -105,12 +107,6 @@ public class AAFLurPerm extends AbsAAFLur<AAFPermission> {
 
        protected User<AAFPermission> loadUser(final Principal principal)  {
                final String name = principal.getName();
-//             // Note: The rules for AAF is that it only stores permissions for ATTUID and MechIDs, which don't 
-//             // have domains.  We are going to make the Transitive Class (see this.transmutative) to convert
-//             final Principal tp = principal; //transmutate.mutate(principal);
-//             if(tp==null) {
-//                     return null; // if not a valid Transmutated credential, don't bother calling...
-//             }
 //             TODO Create a dynamic way to declare domains supported.
                final long start = System.nanoTime();
                final boolean[] success = new boolean[]{false};
@@ -146,7 +142,7 @@ public class AAFLurPerm extends AbsAAFLur<AAFPermission> {
                                                Map<String, Permission> newMap = user.newMap();
                                                boolean willLog = aaf.access.willLog(Level.DEBUG);
                                                for(Perm perm : fp.value.getPerm()) {
-                                                       user.add(newMap,new AAFPermission(perm.getType(),perm.getInstance(),perm.getAction(),perm.getRoles()));
+                                                       user.add(newMap,new AAFPermission(perm.getNs(),perm.getType(),perm.getInstance(),perm.getAction(),perm.getRoles()));
                                                        if(willLog) {
                                                                aaf.access.log(Level.DEBUG, name,"has '",perm.getType(),'|',perm.getInstance(),'|',perm.getAction(),'\'');
                                                        }
@@ -195,7 +191,7 @@ public class AAFLurPerm extends AbsAAFLur<AAFPermission> {
                                Map<String,Permission> newMap = user.newMap(); 
                                boolean willLog = aaf.access.willLog(Level.DEBUG);
                                for(Perm perm : fp.value.getPerm()) {
-                                       user.add(newMap, new AAFPermission(perm.getType(),perm.getInstance(),perm.getAction(),perm.getRoles()));
+                                       user.add(newMap, new AAFPermission(perm.getNs(),perm.getType(),perm.getInstance(),perm.getAction(),perm.getRoles()));
                                        if(willLog) {
                                                aaf.access.log(Level.DEBUG, name,"has",perm.getType(),perm.getInstance(),perm.getAction());
                                        }
@@ -233,10 +229,13 @@ public class AAFLurPerm extends AbsAAFLur<AAFPermission> {
        @Override
        public Permission createPerm(String p) {
                String[] params = Split.split('|', p);
-               if(params.length==3) {
-                       return new AAFPermission(params[0],params[1],params[2]);
-               } else {
-                       return new LocalPermission(p);
+               switch(params.length) {
+                       case 3:
+                               return new AAFPermission(null,params[0],params[1],params[2]);
+                       case 4:
+                               return new AAFPermission(params[0],params[1],params[2],params[3]);
+                       default:
+                               return new LocalPermission(p);
                }
        }