FileDocCategorySizeDatePackage
ConfigXMLParser.javaAPI DocGlassfish v2 API16744Fri May 04 22:35:36 BST 2007com.sun.enterprise.security.jmac.config

ConfigXMLParser

public class ConfigXMLParser extends Object implements ConfigParser
Parser for message-security-config in domain.xml or sun-acc.xml

Fields Summary
private static Logger
_logger
private Map
configMap
private Set
layersWithDefault
private static final String
SUNACC_XML_URL
Constructors Summary
ConfigXMLParser()


       
    
Methods Summary
public java.util.MapgetConfigMap()

        return configMap;
    
public java.util.SetgetLayersWithDefault()

        return layersWithDefault;
    
public voidinitialize(com.sun.enterprise.config.ConfigContext configCtx)

        boolean isAppClientContainer =
            (Switch.getSwitch().getContainerType() ==
            Switch.APPCLIENT_CONTAINER);
        if (configCtx == null) {
            if (isAppClientContainer) {
                try {
                    configCtx = ConfigFactory.createConfigContext
                        (System.getProperty(SUNACC_XML_URL),
                        true, false, false, ClientContainer.class,
                        new ClientBeansResolver());
                } catch(ConfigException cex) {
                    IOException iex = new IOException();
                    iex.initCause(cex);
                    throw iex;
                }
            } else { // container == Switch.EJBWEB_CONTAINER
                configCtx =
                    ApplicationServer.getServerContext().getConfigContext();
            }

            if (configCtx == null) {
                return;
            }
        }
        if (isAppClientContainer) {
            processClientConfigContext(configCtx, configMap);
        } else {
            processServerConfigContext(configCtx, configMap);
        }
    
private voidparseIDEntry(com.sun.enterprise.config.clientbeans.ProviderConfig pConfig, java.util.Map newConfig, java.lang.String intercept)


        String id = pConfig.getProviderId();
        String type = pConfig.getProviderType();
        String moduleClass = pConfig.getClassName();
        MessagePolicy requestPolicy = parsePolicy(pConfig.getRequestPolicy());
        MessagePolicy responsePolicy = parsePolicy(pConfig.getResponsePolicy());

        // get the module options

        Map options = new HashMap();
        String key;
        String value;

        for (int i = 0; i < pConfig.sizeElementProperty(); i++) {
            try {
                options.put(pConfig.getElementProperty(i).getName(),
                            PropertyExpander.expand
                            (pConfig.getElementProperty(i).getValue(),
                             false));
            } catch (sun.security.util.PropertyExpander.ExpandException ee) {
                // log warning and give the provider a chance to 
                // interpret value itself.
                if (_logger.isLoggable(Level.WARNING)) {
                    _logger.warning("jmac.unexpandedproperty");
                }
                options.put(pConfig.getElementProperty(i).getName(),
                            pConfig.getElementProperty(i).getValue());
            }
        }

        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ID Entry: " +
                        "\n    module class: " + moduleClass +
                        "\n    id: " + id +
                        "\n    type: " + type +
                        "\n    request policy: " + requestPolicy +
                        "\n    response policy: " + responsePolicy +
                        "\n    options: " + options);
        }

        // create ID entry

        GFServerConfigProvider.IDEntry idEntry =
                new GFServerConfigProvider.IDEntry(type, moduleClass,
                requestPolicy, responsePolicy, options);

        GFServerConfigProvider.InterceptEntry intEntry =
                (GFServerConfigProvider.InterceptEntry)newConfig.get(intercept);
        if (intEntry == null) {
            throw new IOException
                ("intercept entry for " + intercept +
                " must be specified before ID entries");
        }

        if (intEntry.idMap == null) {
            intEntry.idMap = new HashMap();
        }

        // map id to Intercept
        intEntry.idMap.put(id, idEntry);
    
private voidparseIDEntry(com.sun.enterprise.config.serverbeans.ProviderConfig pConfig, java.util.Map newConfig, java.lang.String intercept)


        String id = pConfig.getProviderId();
        String type = pConfig.getProviderType();
        String moduleClass = pConfig.getClassName();
        MessagePolicy requestPolicy = parsePolicy(pConfig.getRequestPolicy());
        MessagePolicy responsePolicy = parsePolicy(pConfig.getResponsePolicy());

        // get the module options

        Map options = new HashMap();
        String key;
        String value;

        for (int i = 0; i < pConfig.sizeElementProperty(); i++) {
            try {
                options.put(pConfig.getElementProperty(i).getName(),
                            PropertyExpander.expand
                            (pConfig.getElementProperty(i).getValue(),
                             false));
            } catch (sun.security.util.PropertyExpander.ExpandException ee) {
                // log warning and give the provider a chance to 
                // interpret value itself.
                if (_logger.isLoggable(Level.WARNING)) {
                    _logger.warning("jmac.unexpandedproperty");
                }
                options.put(pConfig.getElementProperty(i).getName(),
                            pConfig.getElementProperty(i).getValue());
            }
        }

        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ID Entry: " +
                        "\n    module class: " + moduleClass +
                        "\n    id: " + id +
                        "\n    type: " + type +
                        "\n    request policy: " + requestPolicy +
                        "\n    response policy: " + responsePolicy +
                        "\n    options: " + options);
        }

        // create ID entry

        GFServerConfigProvider.IDEntry idEntry =
                new GFServerConfigProvider.IDEntry(type, moduleClass,
                requestPolicy, responsePolicy, options);

        GFServerConfigProvider.InterceptEntry intEntry =
                (GFServerConfigProvider.InterceptEntry)newConfig.get(intercept);
        if (intEntry == null) {
            throw new IOException
                ("intercept entry for " + intercept +
                " must be specified before ID entries");
        }

        if (intEntry.idMap == null) {
            intEntry.idMap = new HashMap();
        }

        // map id to Intercept
        intEntry.idMap.put(id, idEntry);
    
private java.lang.StringparseInterceptEntry(com.sun.enterprise.config.ConfigBean msgConfig, java.util.Map newConfig)


        String intercept = null;
        String defaultServerID = null;
        String defaultClientID = null;

        if (msgConfig instanceof com.sun.enterprise.config.serverbeans.MessageSecurityConfig) {
            com.sun.enterprise.config.serverbeans.MessageSecurityConfig serverMsgSecConfig = (com.sun.enterprise.config.serverbeans.MessageSecurityConfig)msgConfig;
            intercept = serverMsgSecConfig.getAuthLayer();
            defaultServerID = serverMsgSecConfig.getDefaultProvider();
            defaultClientID = serverMsgSecConfig.getDefaultClientProvider();
        } else if (msgConfig instanceof com.sun.enterprise.config.clientbeans.MessageSecurityConfig) {
            com.sun.enterprise.config.clientbeans.MessageSecurityConfig clientMsgSecConfig = (com.sun.enterprise.config.clientbeans.MessageSecurityConfig)msgConfig;
            intercept = clientMsgSecConfig.getAuthLayer();
            defaultServerID = clientMsgSecConfig.getDefaultProvider();
            defaultClientID = clientMsgSecConfig.getDefaultClientProvider();
        } 

        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Intercept Entry: " +
                        "\n    intercept: " + intercept +
                        "\n    defaultServerID: " + defaultServerID +
                        "\n    defaultClientID:  " + defaultClientID);
        }

        if (defaultServerID != null || defaultClientID != null) {
            layersWithDefault.add(intercept);
        }

        GFServerConfigProvider.InterceptEntry intEntry =
            (GFServerConfigProvider.InterceptEntry)newConfig.get(intercept);
        if (intEntry != null) {
            throw new IOException("found multiple MessageSecurityConfig " +
                                "entries with the same auth-layer");
        }

        // create new intercept entry
        intEntry = new GFServerConfigProvider.InterceptEntry(defaultClientID,
                defaultServerID, null);
        newConfig.put(intercept, intEntry);
        return intercept;
    
private javax.security.auth.message.MessagePolicyparsePolicy(com.sun.enterprise.config.ConfigBean policy)


        if (policy == null) {
            return null;
        }

        String authSource = null;
        String authRecipient = null;

        if (policy instanceof
                com.sun.enterprise.config.serverbeans.RequestPolicy) {
            com.sun.enterprise.config.serverbeans.RequestPolicy serverRequestPolicy = (com.sun.enterprise.config.serverbeans.RequestPolicy)policy;
            authSource = serverRequestPolicy.getAuthSource();
            authRecipient = serverRequestPolicy.getAuthRecipient();
        } else if (policy instanceof
               com.sun.enterprise.config.serverbeans.ResponsePolicy) {
            com.sun.enterprise.config.serverbeans.ResponsePolicy serverResponsePolicy = (com.sun.enterprise.config.serverbeans.ResponsePolicy)policy;
            authSource = serverResponsePolicy.getAuthSource();
            authRecipient = serverResponsePolicy.getAuthRecipient();
        } else if (policy instanceof
                com.sun.enterprise.config.clientbeans.RequestPolicy) {
            com.sun.enterprise.config.clientbeans.RequestPolicy clientRequestPolicy = (com.sun.enterprise.config.clientbeans.RequestPolicy)policy;
            authSource = clientRequestPolicy.getAuthSource();
            authRecipient = clientRequestPolicy.getAuthRecipient();
        } else if (policy instanceof
                com.sun.enterprise.config.clientbeans.ResponsePolicy) {
            com.sun.enterprise.config.clientbeans.ResponsePolicy clientResponsePolicy = (com.sun.enterprise.config.clientbeans.ResponsePolicy)policy;
            authSource = clientResponsePolicy.getAuthSource();
            authRecipient = clientResponsePolicy.getAuthRecipient();
        }

        return AuthMessagePolicy.getMessagePolicy(authSource, authRecipient);
    
private voidprocessClientConfigContext(com.sun.enterprise.config.ConfigContext configCtx, java.util.Map newConfig)


        // auth-layer
        String intercept = null;

        try {
            ClientContainer cc = (ClientContainer)configCtx.getRootConfigBean();
            com.sun.enterprise.config.clientbeans.MessageSecurityConfig[]
                msgConfigs = cc.getMessageSecurityConfig();

            for (int j = 0; msgConfigs != null && j < msgConfigs.length; j++) {

                // single message-security-config for each auth-layer
                //
                // auth-layer is synonymous with intercept

                intercept = parseInterceptEntry(msgConfigs[j], newConfig);
                com.sun.enterprise.config.clientbeans.ProviderConfig[]
                        pConfigs = msgConfigs[j].getProviderConfig();

                for (int k = 0; pConfigs != null && k < pConfigs.length; k++) {
                     parseIDEntry(pConfigs[k], newConfig, intercept);
                }
            }
        } catch (ConfigException ce) {
            IOException ioe = new IOException();
            ioe.initCause(ce);
            throw ioe;
        }
    
private voidprocessServerConfigContext(com.sun.enterprise.config.ConfigContext configCtx, java.util.Map newConfig)


        // auth-layer
        String intercept = null;

        try {
            Server configBean = ServerBeansFactory.getServerBean(configCtx);
            SecurityService secService =
                ServerBeansFactory.getSecurityServiceBean(configCtx);

            com.sun.enterprise.config.serverbeans.MessageSecurityConfig[]
                msgConfigs = secService.getMessageSecurityConfig();

            for (int j = 0; msgConfigs != null &&
                    j < msgConfigs.length; j++) {

                // single message-security-config for each auth-layer
                //
                // auth-layer is synonymous with intercept

                intercept = parseInterceptEntry(msgConfigs[j], newConfig);
                com.sun.enterprise.config.serverbeans.ProviderConfig[]
                        pConfigs = msgConfigs[j].getProviderConfig();

                for (int k = 0; pConfigs != null &&
                        k < pConfigs.length; k++) {
                    parseIDEntry(pConfigs[k], newConfig, intercept);
                }
            }
        } catch (ConfigException ce) {
            IOException ioe = new IOException();
            ioe.initCause(ce); throw ioe;
        }