X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Forg%2FOrganizationFactory.java;h=3b97d6f3869f4922a0eacacf4708064194942918;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=ffc7916937a41119f38c597914d3620710e1be78;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/org/OrganizationFactory.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/org/OrganizationFactory.java index ffc79169..3b97d6f3 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/org/OrganizationFactory.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/org/OrganizationFactory.java @@ -46,96 +46,96 @@ import org.onap.aaf.misc.env.impl.BasicEnv; * */ public class OrganizationFactory { - private static final String ORGANIZATION_DOT = "Organization."; - private static Organization defaultOrg = null; - private static Map orgs = new ConcurrentHashMap<>(); - public static Organization init(BasicEnv env) throws OrganizationException { - int idx = ORGANIZATION_DOT.length(); - Organization org,firstOrg = null; - - for(Entry es : env.getProperties().entrySet()) { - String key = es.getKey().toString(); - if(key.startsWith(ORGANIZATION_DOT)) { - org = obtain(env,key.substring(idx)); - if(firstOrg==null) { - firstOrg = org; - } - } - } - if(defaultOrg == null) { - defaultOrg = firstOrg; - } - return defaultOrg; - } - public static Organization obtain(Env env,final String theNS) throws OrganizationException { - String orgNS; - if(theNS.indexOf('@')>=0) { - orgNS=FQI.reverseDomain(theNS); - } else { - orgNS=theNS; - } - Organization org = orgs.get(orgNS); - if(org == null) { - env.debug().printf("Attempting to instantiate Organization %s\n",orgNS); + private static final String ORGANIZATION_DOT = "Organization."; + private static Organization defaultOrg = null; + private static Map orgs = new ConcurrentHashMap<>(); + public static Organization init(BasicEnv env) throws OrganizationException { + int idx = ORGANIZATION_DOT.length(); + Organization org,firstOrg = null; + + for(Entry es : env.getProperties().entrySet()) { + String key = es.getKey().toString(); + if(key.startsWith(ORGANIZATION_DOT)) { + org = obtain(env,key.substring(idx)); + if(firstOrg==null) { + firstOrg = org; + } + } + } + if(defaultOrg == null) { + defaultOrg = firstOrg; + } + return defaultOrg; + } + public static Organization obtain(Env env,final String theNS) throws OrganizationException { + String orgNS; + if(theNS.indexOf('@')>=0) { + orgNS=FQI.reverseDomain(theNS); + } else { + orgNS=theNS; + } + Organization org = orgs.get(orgNS); + if(org == null) { + env.debug().printf("Attempting to instantiate Organization %s\n",orgNS); - String orgClass = env.getProperty(ORGANIZATION_DOT+orgNS); - if(orgClass == null) { - env.warn().log("There is no Organization." + orgNS + " property"); - } else { - try { - Class orgCls = Class.forName(orgClass); - for(Organization o : orgs.values()) { - if(o.getClass().isAssignableFrom(orgCls)) { - org = o; - } - } - } catch (ClassNotFoundException e1) { - env.error().log(e1, orgClass + " is not on the Classpath."); - throw new OrganizationException(e1); - } - if(org==null) { - try { - @SuppressWarnings("unchecked") - Class cls = (Class) Class.forName(orgClass); - Constructor cnst = cls.getConstructor(Env.class,String.class); - org = cnst.newInstance(env,orgNS); - String other_realms = env.getProperty(orgNS+".also_supports"); - if(other_realms!=null) { - for(String r : Split.splitTrim(',', other_realms)) { - org.addSupportedRealm(r); - } - } - } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | - InstantiationException | IllegalAccessException | IllegalArgumentException | - InvocationTargetException e) { - env.error().log(e, "Error on Organization Construction"); - throw new OrganizationException(e); - } - } - orgs.put(orgNS, org); - boolean isDefault; - if((isDefault="true".equalsIgnoreCase(env.getProperty(orgNS+".default")))) { - defaultOrg = org; - } - env.init().printf("Instantiated %s with %s%s\n",orgNS,orgClass,(isDefault?" as default":"")); - } - if(org==null) { - if(defaultOrg!=null) { - org=defaultOrg; - orgs.put(orgNS, org); - } - } - } - - return org; - } + String orgClass = env.getProperty(ORGANIZATION_DOT+orgNS); + if(orgClass == null) { + env.warn().log("There is no Organization." + orgNS + " property"); + } else { + try { + Class orgCls = Class.forName(orgClass); + for(Organization o : orgs.values()) { + if(o.getClass().isAssignableFrom(orgCls)) { + org = o; + } + } + } catch (ClassNotFoundException e1) { + env.error().log(e1, orgClass + " is not on the Classpath."); + throw new OrganizationException(e1); + } + if(org==null) { + try { + @SuppressWarnings("unchecked") + Class cls = (Class) Class.forName(orgClass); + Constructor cnst = cls.getConstructor(Env.class,String.class); + org = cnst.newInstance(env,orgNS); + String other_realms = env.getProperty(orgNS+".also_supports"); + if(other_realms!=null) { + for(String r : Split.splitTrim(',', other_realms)) { + org.addSupportedRealm(r); + } + } + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | + InstantiationException | IllegalAccessException | IllegalArgumentException | + InvocationTargetException e) { + env.error().log(e, "Error on Organization Construction"); + throw new OrganizationException(e); + } + } + orgs.put(orgNS, org); + boolean isDefault; + if((isDefault="true".equalsIgnoreCase(env.getProperty(orgNS+".default")))) { + defaultOrg = org; + } + env.init().printf("Instantiated %s with %s%s\n",orgNS,orgClass,(isDefault?" as default":"")); + } + if(org==null) { + if(defaultOrg!=null) { + org=defaultOrg; + orgs.put(orgNS, org); + } + } + } + + return org; + } - public static Organization get(AuthzTrans trans) throws OrganizationException { - String domain = FQI.reverseDomain(trans.user()); - Organization org = orgs.get(domain); - if(org==null) { - org = defaultOrg; // can be null, btw, unless set. - } - return org; - } + public static Organization get(AuthzTrans trans) throws OrganizationException { + String domain = FQI.reverseDomain(trans.user()); + Organization org = orgs.get(domain); + if(org==null) { + org = defaultOrg; // can be null, btw, unless set. + } + return org; + } }