X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Foauth%2FTokenPerm.java;h=daac8f43efc2a2db09ab2661f0b4dd42380d9f8e;hb=refs%2Fchanges%2F75%2F65275%2F1;hp=bb33bc7622417e0b12ed5010c232e8878c91af02;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenPerm.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenPerm.java index bb33bc76..daac8f43 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenPerm.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenPerm.java @@ -42,133 +42,133 @@ import aaf.v2_0.Perms; import aafoauth.v2_0.Introspect; public class TokenPerm extends Persisting{ - private static final List NULL_PERMS = new ArrayList<>(); - private Introspect introspect; - private List perms; - private String scopes; - public TokenPerm(Persist p, RosettaDF permsDF, Introspect ti, byte[] hash, Path path) throws APIException { - super(p,ti,ti.getExp(),hash,path); // ti.getExp() is seconds after Jan 1, 1970 ) - this.introspect = ti; - if(ti.getContent()==null || ti.getContent().length()==0) { - perms = NULL_PERMS; - } else { - LoadPermissions lp; - try { - lp = new LoadPermissions(new StringReader(ti.getContent())); - perms = lp.perms; - } catch (ParseException e) { - throw new APIException("Error parsing Content",e); - } - } - scopes = ti.getScope(); - } - - public List perms() { - return perms; - } - - public String getClientId() { - return introspect.getClientId(); - } - - public String getUsername() { - return introspect.getUsername(); - } - - public String getToken() { - return introspect.getAccessToken(); - } - - public synchronized String getScopes() { - return scopes; - } + private static final List NULL_PERMS = new ArrayList<>(); + private Introspect introspect; + private List perms; + private String scopes; + public TokenPerm(Persist p, RosettaDF permsDF, Introspect ti, byte[] hash, Path path) throws APIException { + super(p,ti,ti.getExp(),hash,path); // ti.getExp() is seconds after Jan 1, 1970 ) + this.introspect = ti; + if(ti.getContent()==null || ti.getContent().length()==0) { + perms = NULL_PERMS; + } else { + LoadPermissions lp; + try { + lp = new LoadPermissions(new StringReader(ti.getContent())); + perms = lp.perms; + } catch (ParseException e) { + throw new APIException("Error parsing Content",e); + } + } + scopes = ti.getScope(); + } + + public List perms() { + return perms; + } + + public String getClientId() { + return introspect.getClientId(); + } + + public String getUsername() { + return introspect.getUsername(); + } + + public String getToken() { + return introspect.getAccessToken(); + } + + public synchronized String getScopes() { + return scopes; + } - public Introspect getIntrospect() { - return introspect; - } - - // Direct Parse Perms into List - public static class LoadPermissions { - public List perms; + public Introspect getIntrospect() { + return introspect; + } + + // Direct Parse Perms into List + public static class LoadPermissions { + public List perms; - public LoadPermissions(Reader r) throws ParseException { - PermInfo pi = new PermInfo(); - InJson ij = new InJson(); - Parsed pd = ij.newParsed(); - boolean inPerms = false, inPerm = false; - while((pd = ij.parse(r,pd.reuse())).valid()) { - switch(pd.event) { - case Parse.START_DOC: - perms = new ArrayList<>(); - break; - case Parse.START_ARRAY: - inPerms = "perm".equals(pd.name); - break; - case '{': - if(inPerms) { - inPerm=true; - pi.clear(); - } - break; - case ',': - if(inPerm) { - pi.eval(pd); - } - break; - case '}': - if(inPerms) { - if(inPerm) { - pi.eval(pd); - AAFPermission perm = pi.create(); - if(perm!=null) { - perms.add(perm); - } - } - inPerm=false; - } - break; - case Parse.END_ARRAY: - if(inPerms) { - inPerms=false; - } - break; - case Parse.END_DOC: - break; - } - } - } - } - - // Gathering object for parsing objects, then creating AAF Permission - private static class PermInfo { - public String ns,type,instance,action; - public void clear() { - ns=type=instance=action=null; - } - public void eval(Parsed pd) { - if(pd.hasName()) { - switch(pd.name) { - case "ns": - ns=pd.sb.toString(); - break; - case "type": - type=pd.sb.toString(); - break; - case "instance": - instance=pd.sb.toString(); - break; - case "action": - action=pd.sb.toString(); - break; - } - } - } - public AAFPermission create() { - if(type!=null && instance!=null && action !=null) { - return new AAFPermission(ns,type, instance, action); - } else { - return null; - } - } - } + public LoadPermissions(Reader r) throws ParseException { + PermInfo pi = new PermInfo(); + InJson ij = new InJson(); + Parsed pd = ij.newParsed(); + boolean inPerms = false, inPerm = false; + while((pd = ij.parse(r,pd.reuse())).valid()) { + switch(pd.event) { + case Parse.START_DOC: + perms = new ArrayList<>(); + break; + case Parse.START_ARRAY: + inPerms = "perm".equals(pd.name); + break; + case '{': + if(inPerms) { + inPerm=true; + pi.clear(); + } + break; + case ',': + if(inPerm) { + pi.eval(pd); + } + break; + case '}': + if(inPerms) { + if(inPerm) { + pi.eval(pd); + AAFPermission perm = pi.create(); + if(perm!=null) { + perms.add(perm); + } + } + inPerm=false; + } + break; + case Parse.END_ARRAY: + if(inPerms) { + inPerms=false; + } + break; + case Parse.END_DOC: + break; + } + } + } + } + + // Gathering object for parsing objects, then creating AAF Permission + private static class PermInfo { + public String ns,type,instance,action; + public void clear() { + ns=type=instance=action=null; + } + public void eval(Parsed pd) { + if(pd.hasName()) { + switch(pd.name) { + case "ns": + ns=pd.sb.toString(); + break; + case "type": + type=pd.sb.toString(); + break; + case "instance": + instance=pd.sb.toString(); + break; + case "action": + action=pd.sb.toString(); + break; + } + } + } + public AAFPermission create() { + if(type!=null && instance!=null && action !=null) { + return new AAFPermission(ns,type, instance, action); + } else { + return null; + } + } + } } \ No newline at end of file