Search in sources :

Example 81 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project jdk8u_jdk by JetBrains.

the class DNS method main.

public static void main(String[] args) throws Exception {
    System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") + "/no-such-file.conf");
    Config config = Config.getInstance();
    try {
        String r = config.getDefaultRealm();
        throw new Exception("What? There is a default realm " + r + "?");
    } catch (KrbException ke) {
        ke.printStackTrace();
        if (ke.getCause() != null) {
            throw new Exception("There should be no cause. Won't try DNS");
        }
    }
    String kdcs = config.getKDCList("X");
    if (!kdcs.equals("a.com.:88 b.com.:99") && !kdcs.equals("a.com. b.com.:99")) {
        throw new Exception("Strange KDC: [" + kdcs + "]");
    }
    ;
}
Also used : Config(sun.security.krb5.Config) KrbException(sun.security.krb5.KrbException) KrbException(sun.security.krb5.KrbException)

Example 82 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project jdk8u_jdk by JetBrains.

the class SCDynamicConfigTest method main.

public static void main(String[] args) throws Exception {
    // Reconstruct a typical SCDynamicConfig.getKerberosConfig() output
    Hashtable<String, Object> conf = new Hashtable<>();
    Hashtable<String, Object> libdefaults = new Hashtable<>();
    libdefaults.put("default_realm", "REALM.COM");
    conf.put("libdefaults", libdefaults);
    Hashtable<String, Object> realms = new Hashtable<>();
    Hashtable<String, Object> thisRealm = new Hashtable<>();
    realms.put("REALM.COM", thisRealm);
    thisRealm.put("kpasswd", hosts());
    thisRealm.put("kadmin", hosts());
    thisRealm.put("kdc", hosts());
    conf.put("realms", realms);
    Hashtable<String, Object> domain_realm = new Hashtable<>();
    domain_realm.put(".realm.com", "REALM.COM");
    domain_realm.put("realm.com", "REALM.COM");
    conf.put("domain_realm", domain_realm);
    System.out.println("SCDynamicConfig:\n");
    System.out.println(conf);
    // Simulate SCDynamicConfig.getConfig() output
    Method m = SCDynamicStoreConfig.class.getDeclaredMethod("convertNativeConfig", Hashtable.class);
    m.setAccessible(true);
    conf = (Hashtable) m.invoke(null, conf);
    System.out.println("\nkrb5.conf:\n");
    System.out.println(conf);
    // Feed it into a Config object
    System.setProperty("java.security.krb5.conf", "not-a-file");
    Config cf = Config.getInstance();
    Field f = Config.class.getDeclaredField("stanzaTable");
    f.setAccessible(true);
    f.set(cf, conf);
    System.out.println("\nConfig:\n");
    System.out.println(cf);
    if (!cf.getDefaultRealm().equals("REALM.COM")) {
        throw new Exception();
    }
    if (!cf.getKDCList("REALM.COM").equals("127.0.0.1 127.0.0.2")) {
        throw new Exception();
    }
    if (!cf.get("domain_realm", ".realm.com").equals("REALM.COM")) {
        throw new Exception();
    }
}
Also used : Field(java.lang.reflect.Field) Hashtable(java.util.Hashtable) SCDynamicStoreConfig(sun.security.krb5.SCDynamicStoreConfig) Config(sun.security.krb5.Config) Method(java.lang.reflect.Method)

Example 83 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project jdk8u_jdk by JetBrains.

the class Duplicates method main.

public static void main(String[] args) throws Exception {
    System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") + "/k1.conf");
    Config config = Config.getInstance();
    config.listTable();
    String s;
    // Latter overwrites former for root section
    s = config.get("libdefaults", "default_realm");
    if (s != null) {
        throw new Exception();
    }
    // Latter overwrites former for strings
    s = config.get("libdefaults", "default_tkt_enctypes");
    if (!s.equals("aes256-cts")) {
        throw new Exception();
    }
    // Latter overwrites former for sub-section
    s = config.get("realms", "R1", "kdc");
    if (!s.equals("k2")) {
        throw new Exception(s);
    }
    // Duplicate keys in [realms] are merged
    s = config.getAll("realms", "R2", "kdc");
    if (!s.equals("k1 k2 k3 k4")) {
        throw new Exception(s);
    }
    // Duplicate keys in [capaths] are merged
    s = config.getAll("capaths", "R1", "R2");
    if (!s.equals("R3 R4 R5 R6")) {
        throw new Exception(s);
    }
    // We can be very deep now
    s = config.get("new", "x", "y", "z", "a", "b", "c");
    if (!s.equals("d")) {
        throw new Exception(s);
    }
}
Also used : Config(sun.security.krb5.Config)

Example 84 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class WebContainerStarter method postConstruct.

/**
 * Scans the domain.xml to see if it specifies any configuration
 * that can be handled only by the web container, and if so, starts
 * the web container
 */
public void postConstruct() {
    domainProvider.get();
    Config serverConfig = serverConfigProvider.get();
    boolean isStartNeeded = false;
    if (serverConfig != null) {
        if (isStartNeeded(serverConfig.getHttpService())) {
            isStartNeeded = true;
        }
        if (!isStartNeeded && isStartNeeded(serverConfig.getNetworkConfig())) {
            isStartNeeded = true;
        }
    }
    if (isStartNeeded) {
        startWebContainer();
    } else {
        ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
        bean.addListener(this);
        bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
        bean.addListener(this);
    }
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 85 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class DeleteResourceAdapterConfig 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) {
    final ActionReport report = context.getActionReport();
    if (raName == null) {
        report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.noRARName", "No RAR name defined for resource adapter config."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we already have this resource
    if (ConnectorsUtil.getResourceByName(domain.getResources(), ResourceAdapterConfig.class, raName) == null) {
        report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.notfound", "Resource-Adapter-Config for {0} does not exist.", raName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        // delete resource-adapter-config
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ResourceAdapterConfig resource = (ResourceAdapterConfig) ConnectorsUtil.getResourceByName(domain.getResources(), ResourceAdapterConfig.class, raName);
                if (resource != null && resource.getResourceAdapterName().equals(raName)) {
                    return param.getResources().remove(resource);
                }
                // not found
                return null;
            }
        }, domain.getResources()) == null) {
            report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.fail", "Unable to delete resource adapter config {0}", raName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.fail", "Unable to delete resource adapter config {0}", raName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    // report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.success",
    // "Resource adapter config {0} deleted", raName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)81 Config (com.sun.enterprise.config.serverbeans.Config)69 ActionReport (org.glassfish.api.ActionReport)60 PropertyVetoException (java.beans.PropertyVetoException)59 Property (org.jvnet.hk2.config.types.Property)50 CommandTarget (org.glassfish.config.support.CommandTarget)24 Target (org.glassfish.internal.api.Target)23 Properties (java.util.Properties)21 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)17 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Server (com.sun.enterprise.config.serverbeans.Server)14 List (java.util.List)14 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)14 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 IOException (java.io.IOException)10 Map (java.util.Map)10 Cluster (com.sun.enterprise.config.serverbeans.Cluster)9