X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Foauth%2FTokenMgr.java;h=89d5c1a09b5a68c49b9b13e64514b5c83637542c;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=147621fc525cfceff0f21c79c3154291b7d3e588;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenMgr.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenMgr.java index 147621fc..89d5c1a0 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenMgr.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenMgr.java @@ -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. @@ -51,16 +51,16 @@ public class TokenMgr extends Persist { public static RosettaDF introspectDF; private final TokenPermLoader tpLoader; - + private TokenMgr(PropAccess access, String tokenURL, String introspectURL) throws APIException, CadiException { super(access,new RosettaEnv(access.getProperties()),Introspect.class,"introspect"); synchronized(access) { - if(permsDF==null) { + if (permsDF==null) { permsDF = env.newDataFactory(Perms.class); introspectDF = env.newDataFactory(Introspect.class); } } - if("dbToken".equals(tokenURL) && "dbIntrospect".equals(introspectURL)) { + if ("dbToken".equals(tokenURL) && "dbIntrospect".equals(introspectURL)) { tpLoader = new TokenPermLoader() { // null Loader @Override public Result load(String accessToken, byte[] cred) @@ -72,7 +72,7 @@ public class TokenMgr extends Persist { RemoteTokenPermLoader rtpl = new RemoteTokenPermLoader(tokenURL, introspectURL); // default is remote String i = access.getProperty(Config.AAF_APPID,null); String p = access.getProperty(Config.AAF_APPPASS, null); - if(i==null || p==null) { + if (i==null || p==null) { throw new CadiException(Config.AAF_APPID + " and " + Config.AAF_APPPASS + " must be set to initialize TokenMgr"); } rtpl.introCL.client_creds(i,p); @@ -83,7 +83,7 @@ public class TokenMgr extends Persist { private TokenMgr(PropAccess access, TokenPermLoader tpl) throws APIException, CadiException { super(access,new RosettaEnv(access.getProperties()),Introspect.class,"incoming"); synchronized(access) { - if(permsDF==null) { + if (permsDF==null) { permsDF = env.newDataFactory(Perms.class); introspectDF = env.newDataFactory(Introspect.class); } @@ -94,12 +94,12 @@ public class TokenMgr extends Persist { public static synchronized TokenMgr getInstance(final PropAccess access, final String tokenURL, final String introspectURL) throws APIException, CadiException { String key; TokenMgr tm = tmmap.get(key=tokenURL+'/'+introspectURL); - if(tm==null) { + if (tm==null) { tmmap.put(key, tm=new TokenMgr(access,tokenURL,introspectURL)); } return tm; } - + public Result toPrincipal(final String accessToken, final byte[] hash) throws APIException, CadiException, LocatorException { Result tp = get(accessToken, hash, new Loader() { @Override @@ -111,20 +111,20 @@ public class TokenMgr extends Persist { } } }); - if(tp.isOK()) { + if (tp.isOK()) { return Result.ok(200, new OAuth2Principal(tp.value,hash)); } else { return Result.err(tp); } } - + public Result get(final String accessToken, final byte[] hash) throws APIException, CadiException, LocatorException { return get(accessToken,hash,new Loader() { @Override public Result load(String key) throws APIException, CadiException, LocatorException { return tpLoader.load(key,hash); } - + }); // return tpLoader.load(accessToken,hash); } @@ -132,7 +132,7 @@ public class TokenMgr extends Persist { public interface TokenPermLoader{ public Result load(final String accessToken, final byte[] cred) throws APIException, CadiException, LocatorException; } - + private class RemoteTokenPermLoader implements TokenPermLoader { private TokenClientFactory tcf; private TokenClient tokenCL, introCL; @@ -141,12 +141,12 @@ public class TokenMgr extends Persist { try { tcf = TokenClientFactory.instance(access); int timeout = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); - tokenCL = tcf.newClient(tokenURL, + tokenCL = tcf.newClient(tokenURL, timeout); - if(introspectURL.equals(tokenURL)) { + if (introspectURL.equals(tokenURL)) { introCL = tokenCL; } else { - introCL = tcf.newClient(introspectURL, + introCL = tcf.newClient(introspectURL, timeout); } @@ -154,12 +154,12 @@ public class TokenMgr extends Persist { throw new CadiException(e); } } - + public Result load(final String accessToken, final byte[] cred) throws APIException, CadiException, LocatorException { long start = System.currentTimeMillis(); try { Result ri = introCL.introspect(accessToken); - if(ri.isOK()) { + if (ri.isOK()) { return Result.ok(ri.code, new TokenPerm(TokenMgr.this,permsDF,ri.value,cred,getPath(accessToken))); } else { return Result.err(ri); @@ -172,7 +172,7 @@ public class TokenMgr extends Persist { public void clear(Principal p, StringBuilder report) { TokenPerm tp = tpmap.remove(p.getName()); - if(tp==null) { + if (tp==null) { report.append("Nothing to clear"); } else { report.append("Cleared ");