Update scripts per HEAT validation
[aaf/authz.git] / auth / auth-deforg / src / main / java / org / onap / aaf / org / DefaultOrg.java
index 63e8390..ac2105f 100644 (file)
@@ -56,9 +56,12 @@ public class DefaultOrg implements Organization {
        final String realm;
        
        private final String NAME,mailHost,mailFrom;
+       private final Set<String> supportedRealms;
 
        public DefaultOrg(Env env, String realm) throws OrganizationException {
                this.realm = realm;
+               supportedRealms=new HashSet<String>();
+               supportedRealms.add(realm);
                domain=FQI.reverseDomain(realm);
                atDomain = '@'+domain;
                String s;
@@ -84,7 +87,7 @@ public class DefaultOrg implements Organization {
                        if(temp==null) {
                                temp = env.getProperty(AAF_DATA_DIR);
                                if(temp!=null) {
-                                       env.warn().log(defFile, "is not defined. Using default: ",temp+"/identities.dat");
+                                       env.warn().log(defFile, " is not defined. Using default: ",temp+"/identities.dat");
                                        File dir = new File(temp);
                                        fIdentities=new File(dir,"identities.dat");
                                        if(!fIdentities.exists()) {
@@ -108,7 +111,11 @@ public class DefaultOrg implements Organization {
                        if(fIdentities!=null && fIdentities.exists()) {
                                identities = new Identities(fIdentities);
                        } else {
-                               throw new OrganizationException(fIdentities.getCanonicalPath() + " does not exist.");
+                               if(fIdentities==null) {
+                                       throw new OrganizationException("No Identities");
+                               } else {
+                                       throw new OrganizationException(fIdentities.getCanonicalPath() + " does not exist.");
+                               }
                        }
                } catch (IOException e) {
                        throw new OrganizationException(e);
@@ -391,20 +398,22 @@ public class DefaultOrg implements Organization {
                }
                
                List<String> cc = new ArrayList<String>();
-               if(ccList!=null && !ccList.isEmpty()) {
-                       for(String em : ccList) {
-                               if(em.indexOf('@')<0) {
-                                       cc.add(new DefaultOrgIdentity(trans, em, this).email());
-                               } else {
-                                       cc.add(em);
+               if(ccList!=null) {
+                       if(!ccList.isEmpty()) {
+                       
+                               for(String em : ccList) {
+                                       if(em.indexOf('@')<0) {
+                                               cc.add(new DefaultOrgIdentity(trans, em, this).email());
+                                       } else {
+                                               cc.add(em);
+                                       }
                                }
                        }
-               }
-               
-       
-               // for now, I want all emails so we can see what goes out. Remove later
-               if (!ccList.contains(mailFrom)) {
-                       ccList.add(mailFrom);
+                       
+                       // for now, I want all emails so we can see what goes out. Remove later
+                       if (!ccList.contains(mailFrom)) {
+                               ccList.add(mailFrom);
+                       }
                }
 
                try {
@@ -602,7 +611,7 @@ public class DefaultOrg implements Organization {
                                                        Identity mechid = getIdentity(trans, vars[0]);
                                                        if(mechid!=null) {
                                                                Identity sponsor = mechid.responsibleTo();
-                                                               if(sponsor!=null && requestor.equals(sponsor.fullID())) {
+                                                               if(sponsor!=null && requestor.fullID().equals(sponsor.fullID())) {
                                                                        return null;
                                                                } else {
                                                                        return trans.user() + " is not the Sponsor of MechID " + vars[0];
@@ -662,5 +671,31 @@ public class DefaultOrg implements Organization {
         return addressArray;
        }
 
-                       
+       private String extractRealm(final String r) {
+               int at;
+               if((at=r.indexOf('@'))>=0) {
+                       return FQI.reverseDomain(r.substring(at+1));
+               }
+               return r;
+       }
+       @Override
+       public boolean supportsRealm(final String r) {
+               if(r.endsWith(realm)) {
+                       return true;
+               } else {
+                       String erealm = extractRealm(r);
+                       for(String sr : supportedRealms) {
+                               if(erealm.startsWith(sr)) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+
+       @Override
+       public synchronized void addSupportedRealm(final String r) {
+               supportedRealms.add(extractRealm(r));
        }
+                       
+}