Search in sources :

Example 16 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class DeleteProtocol method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    ActionReport report = context.getActionReport();
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    try {
        protocol = protocols.findProtocol(protocolName);
        if (protocol == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_NOT_EXISTS), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // check if the protocol to be deleted is being used by
        // any network listener
        List<NetworkListener> nwlsnrList = protocol.findNetworkListeners();
        for (NetworkListener nwlsnr : nwlsnrList) {
            if (protocol.getName().equals(nwlsnr.getProtocol())) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_BEING_USED), protocolName, nwlsnr.getName()));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            public Object run(Protocols param) {
                param.getProtocol().remove(protocol);
                return protocol;
            }
        }, protocols);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_FAIL), protocolName) + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 17 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class CreateProtocol method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    // check for duplicates
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    for (Protocol protocol : protocols.getProtocol()) {
        if (protocolName != null && protocolName.equalsIgnoreCase(protocol.getName())) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL_DUPLICATE), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // Add to the <network-config>
    try {
        create(protocols, protocolName, securityEnabled);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    } catch (Exception e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 18 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class WebModuleContextConfig method authenticatorConfig.

/**
 * Always sets up an Authenticator regardless of any security constraints.
 */
@Override
protected synchronized void authenticatorConfig() throws LifecycleException {
    LoginConfig loginConfig = context.getLoginConfig();
    if (loginConfig == null) {
        loginConfig = new LoginConfig("NONE", null, null, null);
        context.setLoginConfig(loginConfig);
    }
    // Has an authenticator been configured already?
    if (context instanceof Authenticator) {
        return;
    }
    if (context instanceof ContainerBase) {
        Pipeline pipeline = ((ContainerBase) context).getPipeline();
        if (pipeline != null) {
            GlassFishValve basic = pipeline.getBasic();
            if ((basic != null) && (basic instanceof Authenticator))
                return;
            GlassFishValve[] valves = pipeline.getValves();
            for (int i = 0; i < valves.length; i++) {
                if (valves[i] instanceof Authenticator)
                    return;
            }
        }
    } else {
        // Cannot install a Valve even if it would be needed
        return;
    }
    // Has a Realm been configured for us to authenticate against?
    /* START IASRI 4856062
        if (context.getRealm() == null) {
        */
    // BEGIN IASRI 4856062
    Realm rlm = context.getRealm();
    if (rlm == null) {
        // END IASRI 4856062
        String realmName = (context.getLoginConfig() != null) ? context.getLoginConfig().getRealmName() : null;
        if (realmName != null && !realmName.isEmpty()) {
            String msg = rb.getString(LogFacade.MISSING_REALM);
            throw new LifecycleException(MessageFormat.format(msg, realmName));
        }
        return;
    }
    // BEGIN IASRI 4856062
    // If a realm is available set its name in the Realm(Adapter)
    rlm.setRealmName(loginConfig.getRealmName(), loginConfig.getAuthMethod());
    // END IASRI 4856062
    /*
         * First check to see if there is a custom mapping for the login
         * method. If so, use it. Otherwise, check if there is a mapping in
         * org/apache/catalina/startup/Authenticators.properties.
         */
    GlassFishValve authenticator = null;
    if (customAuthenticators != null) {
        authenticator = (GlassFishValve) customAuthenticators.get(loginConfig.getAuthMethod());
    }
    if (authenticator == null) {
        // Identify the class name of the Valve we should configure
        String authenticatorName = null;
        // BEGIN RIMOD 4808402
        // If login-config is given but auth-method is null, use NONE
        // so that NonLoginAuthenticator is picked
        String authMethod = loginConfig.getAuthMethod();
        if (authMethod == null) {
            authMethod = "NONE";
        }
        authenticatorName = authenticators.getProperty(authMethod);
        if (authenticatorName == null) {
            String msg = rb.getString(LogFacade.AUTHENTICATOR_MISSING);
            throw new LifecycleException(MessageFormat.format(msg, loginConfig.getAuthMethod()));
        }
        // Instantiate and install an Authenticator of the requested class
        try {
            Class authenticatorClass = Class.forName(authenticatorName);
            authenticator = (GlassFishValve) authenticatorClass.newInstance();
        } catch (Exception e) {
            String msg = rb.getString(LogFacade.AUTHENTICATOR_INSTANTIATE_ERROR);
            throw new LifecycleException(MessageFormat.format(msg, authenticatorName), e);
        }
    }
    if (authenticator != null && context instanceof ContainerBase) {
        Pipeline pipeline = ((ContainerBase) context).getPipeline();
        if (pipeline != null) {
            ((ContainerBase) context).addValve(authenticator);
            if (logger.isLoggable(Level.FINEST)) {
                logger.log(Level.FINEST, LogFacade.AUTHENTICATOR_CONFIGURED, loginConfig.getAuthMethod());
            }
        }
    }
    if (authenticator instanceof DigestAuthenticator) {
        Config config = services.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
        SecurityService securityService = config.getSecurityService();
        String digestAlgorithm = null;
        if (securityService != null) {
            digestAlgorithm = securityService.getPropertyValue(DEFAULT_DIGEST_ALGORITHM);
        }
        if (digestAlgorithm != null) {
            ((DigestAuthenticator) authenticator).setAlgorithm(digestAlgorithm);
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) ContextConfig(org.apache.catalina.startup.ContextConfig) LoginConfig(org.apache.catalina.deploy.LoginConfig) Config(com.sun.enterprise.config.serverbeans.Config) String(java.lang.String) NamingException(javax.naming.NamingException) GlassFishValve(org.glassfish.web.valve.GlassFishValve) DigestAuthenticator(org.apache.catalina.authenticator.DigestAuthenticator) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) LoginConfig(org.apache.catalina.deploy.LoginConfig) DigestAuthenticator(org.apache.catalina.authenticator.DigestAuthenticator)

Example 19 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class IiopFolbGmsClient method getClusterInstanceInfo.

// For addMember.
private ClusterInstanceInfo getClusterInstanceInfo(String instanceName) {
    fineLog("getClusterInstanceInfo: instanceName {0}", instanceName);
    final Servers servers = services.getService(Servers.class);
    fineLog("getClusterInstanceInfo: servers {0}", servers);
    final Server server = servers.getServer(instanceName);
    fineLog("getClusterInstanceInfo: server {0}", server);
    final Config config = getConfigForServer(server);
    fineLog("getClusterInstanceInfo: servers {0}", servers);
    // assumeInstanceIsRunning is set to true since this is
    // coming from addMember, because shoal just told us that the instance is up.
    ClusterInstanceInfo result = getClusterInstanceInfo(server, config, true);
    fineLog("getClusterInstanceInfo: result {0}", result);
    return result;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Servers(com.sun.enterprise.config.serverbeans.Servers) ClusterInstanceInfo(com.sun.corba.ee.spi.folb.ClusterInstanceInfo)

Example 20 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class OSGIConsoleHandlers method getConsoleUrl.

@Handler(id = "getConsoleUrl", input = { @HandlerInput(name = "instanceName", type = String.class, required = true) }, output = { @HandlerOutput(name = "consoleUrl", type = String.class) })
public static void getConsoleUrl(HandlerContext handlerCtx) {
    String instanceName = (String) handlerCtx.getInputValue("instanceName");
    Domain domain = Globals.get(Domain.class);
    Server server = domain.getServerNamed(instanceName);
    String port = null;
    SystemProperty httpPort = server.getSystemProperty(http_port);
    if (httpPort != null) {
        port = httpPort.getValue();
    } else {
        // if port is not set as system property, get it from config
        Config cfg = server.getConfig();
        SystemProperty httpConfigPort = cfg.getSystemProperty(http_port);
        if (httpConfigPort != null) {
            port = httpConfigPort.getValue();
        }
    }
    if (port == null) {
        throw new RuntimeException("Not able to get HTTP_LISTENER_PORT " + "for instance : " + instanceName);
    }
    Node node = domain.getNodeNamed(server.getNodeRef());
    String host = node.getNodeHost();
    String consoleUrl = "http://" + host + ":" + port + consolePath;
    handlerCtx.setOutputValue("consoleUrl", consoleUrl);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Node(com.sun.enterprise.config.serverbeans.Node) Domain(com.sun.enterprise.config.serverbeans.Domain) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10