X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Foauth%2FAbsOTafLur.java;h=26a8a69d6985d19f01d5ccc6735f9f4b4cb1cbe5;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=fb8445181e7a4c7f1fe942aa472344a5f2ba90f8;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/AbsOTafLur.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/AbsOTafLur.java index fb844518..26a8a69d 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/AbsOTafLur.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/AbsOTafLur.java @@ -34,101 +34,101 @@ import org.onap.aaf.misc.env.util.Pool; import org.onap.aaf.misc.env.util.Pool.Creator; public abstract class AbsOTafLur { - protected static final String ERROR_GETTING_TOKEN_CLIENT = "Error getting TokenClient"; - protected static final String REQUIRED_FOR_OAUTH2 = " is required for OAuth Access"; + protected static final String ERROR_GETTING_TOKEN_CLIENT = "Error getting TokenClient"; + protected static final String REQUIRED_FOR_OAUTH2 = " is required for OAuth Access"; - protected final TokenMgr tkMgr; - protected final PropAccess access; - protected final String client_id; - protected static Pool tokenClientPool; - - protected AbsOTafLur(final PropAccess access, final String token_url, final String introspect_url) throws CadiException { - this.access = access; - String ci; - if((ci = access.getProperty(Config.AAF_APPID,null))==null) { - if((ci = access.getProperty(Config.CADI_ALIAS,null))==null) { - throw new CadiException(Config.AAF_APPID + REQUIRED_FOR_OAUTH2); - } - } - client_id = ci; + protected final TokenMgr tkMgr; + protected final PropAccess access; + protected final String client_id; + protected static Pool tokenClientPool; + + protected AbsOTafLur(final PropAccess access, final String token_url, final String introspect_url) throws CadiException { + this.access = access; + String ci; + if((ci = access.getProperty(Config.AAF_APPID,null))==null) { + if((ci = access.getProperty(Config.CADI_ALIAS,null))==null) { + throw new CadiException(Config.AAF_APPID + REQUIRED_FOR_OAUTH2); + } + } + client_id = ci; - synchronized(access) { - if(tokenClientPool==null) { - tokenClientPool = new Pool(new TCCreator(access)); - } - try { - tkMgr = TokenMgr.getInstance(access, token_url, introspect_url); - } catch (APIException e) { - throw new CadiException("Unable to create TokenManager",e); - } - } - } + synchronized(access) { + if(tokenClientPool==null) { + tokenClientPool = new Pool(new TCCreator(access)); + } + try { + tkMgr = TokenMgr.getInstance(access, token_url, introspect_url); + } catch (APIException e) { + throw new CadiException("Unable to create TokenManager",e); + } + } + } - private class TCCreator implements Creator { - private TokenClientFactory tcf; - private final int timeout; - private final String url,enc_secret; - - public TCCreator(PropAccess access) throws CadiException { - try { - tcf = TokenClientFactory.instance(access); - } catch (APIException | GeneralSecurityException | IOException e1) { - throw new CadiException(e1); - } - - if((url = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL,null))==null) { - throw new CadiException(Config.AAF_OAUTH2_TOKEN_URL + REQUIRED_FOR_OAUTH2); - } - - try { - timeout = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); - } catch (NumberFormatException e) { - throw new CadiException("Bad format for " + Config.AAF_CONN_TIMEOUT, e); - } - if((enc_secret= access.getProperty(Config.AAF_APPPASS,null))==null) { - throw new CadiException(Config.AAF_APPPASS + REQUIRED_FOR_OAUTH2); - } - } - - @Override - public TokenClient create() throws APIException { - try { - TokenClient tc = tcf.newClient(url, timeout); - tc.client_creds(client_id, access.decrypt(enc_secret, true)); - return tc; - } catch (CadiException | LocatorException | IOException e) { - throw new APIException(e); - } - } + private class TCCreator implements Creator { + private TokenClientFactory tcf; + private final int timeout; + private final String url,enc_secret; + + public TCCreator(PropAccess access) throws CadiException { + try { + tcf = TokenClientFactory.instance(access); + } catch (APIException | GeneralSecurityException | IOException e1) { + throw new CadiException(e1); + } + + if((url = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL,null))==null) { + throw new CadiException(Config.AAF_OAUTH2_TOKEN_URL + REQUIRED_FOR_OAUTH2); + } + + try { + timeout = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); + } catch (NumberFormatException e) { + throw new CadiException("Bad format for " + Config.AAF_CONN_TIMEOUT, e); + } + if((enc_secret= access.getProperty(Config.AAF_APPPASS,null))==null) { + throw new CadiException(Config.AAF_APPPASS + REQUIRED_FOR_OAUTH2); + } + } + + @Override + public TokenClient create() throws APIException { + try { + TokenClient tc = tcf.newClient(url, timeout); + tc.client_creds(client_id, access.decrypt(enc_secret, true)); + return tc; + } catch (CadiException | LocatorException | IOException e) { + throw new APIException(e); + } + } - @Override - public void destroy(TokenClient t) { - } + @Override + public void destroy(TokenClient t) { + } - @Override - public boolean isValid(TokenClient t) { - return t!=null && t.client_id()!=null; - } + @Override + public boolean isValid(TokenClient t) { + return t!=null && t.client_id()!=null; + } - @Override - public void reuse(TokenClient t) { - } - }; + @Override + public void reuse(TokenClient t) { + } + }; - /* (non-Javadoc) - * @see org.onap.aaf.cadi.Lur#destroy() - */ - public void destroy() { - tkMgr.close(); - } - - /* (non-Javadoc) - * @see org.onap.aaf.cadi.Lur#clear(java.security.Principal, java.lang.StringBuilder) - */ - public void clear(Principal p, StringBuilder report) { - tkMgr.clear(p, report); - } - + /* (non-Javadoc) + * @see org.onap.aaf.cadi.Lur#destroy() + */ + public void destroy() { + tkMgr.close(); + } + + /* (non-Javadoc) + * @see org.onap.aaf.cadi.Lur#clear(java.security.Principal, java.lang.StringBuilder) + */ + public void clear(Principal p, StringBuilder report) { + tkMgr.clear(p, report); + } + - + }