/**
 * The contents of this file are subject to the Regenstrief Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance with the License.
 * Please contact Regenstrief Institute if you would like to obtain a copy of the license.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) Regenstrief Institute.  All Rights Reserved.
 */
package org.carewebframework.vista.security.base;

import java.util.List;

import org.carewebframework.api.security.SecurityDomainRegistry;
import org.carewebframework.common.StrUtil;
import org.carewebframework.security.spring.Constants;
import org.carewebframework.vista.mbroker.BrokerSession;

import org.springframework.util.StringUtils;

/**
 * Security Domain Loader.
 */
public class SecurityDomainLoader {
    
    public SecurityDomainLoader(BrokerSession brokerSession) {
        List<String> results = brokerSession.callRPCList("RGNETBRP DIVGET", null);
        String preLoginMessage = StringUtils.collectionToDelimitedString(brokerSession.getPreLoginMessage(), "\n");
        
        for (String result : results) {
            String[] pcs = StrUtil.split(result, StrUtil.U, 4);
            
            if (!pcs[2].isEmpty()) {
                SecurityDomain securityDomain = new SecurityDomain(pcs[1], pcs[0]);
                securityDomain.setAttribute(Constants.PROP_LOGIN_INFO, preLoginMessage);
                SecurityDomainRegistry.registerSecurityDomain(securityDomain);
            }
        }
        
        brokerSession.disconnect();
    }
    
}

@@ -1251,16 +1251,53 @@
  %22%5Cn%22);%0A
+        String defaultDomain = null;%0A
         
@@ -1289,32 +1289,32 @@
  null;%0A        %0A
-
         for (Str
@@ -1434,26 +1434,91 @@
 if (
-!pcs%5B2%5D.isEmpty())
+defaultDomain == null) %7B%0A                defaultDomain = pcs%5B0%5D;%0A            %7D else
  %7B%0A 
@@ -1689,16 +1689,16 @@
 ssage);%0A
-
         
@@ -1768,16 +1768,171 @@
 omain);%0A
+                %0A                if (pcs%5B0%5D.equals(defaultDomain)) %7B%0A                    securityDomain.setAttribute(%22default%22, %22true%22);%0A                %7D%0A
         

Add support for default domain.