Java Code Examples for sun.security.krb5.Config#getInstance()

The following examples show how to use sun.security.krb5.Config#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CksumType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns default checksum type.
 */
public static CksumType getInstance() throws KdcErrException {
    // this method provided for Kerberos applications.
    int cksumType = Checksum.CKSUMTYPE_RSA_MD5; // default
    try {
        Config c = Config.getInstance();
        if ((cksumType = (Config.getType(c.get("libdefaults",
                "ap_req_checksum_type")))) == - 1) {
            if ((cksumType = Config.getType(c.get("libdefaults",
                    "checksum_type"))) == -1) {
                cksumType = Checksum.CKSUMTYPE_RSA_MD5; // default
            }
        }
    } catch (KrbException e) {
    }
    return getInstance(cksumType);
}
 
Example 2
Source File: CksumType.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns default checksum type.
 */
public static CksumType getInstance() throws KdcErrException {
    // this method provided for Kerberos applications.
    int cksumType = Checksum.CKSUMTYPE_RSA_MD5; // default
    try {
        Config c = Config.getInstance();
        if ((cksumType = (Config.getType(c.get("libdefaults",
                "ap_req_checksum_type")))) == - 1) {
            if ((cksumType = Config.getType(c.get("libdefaults",
                    "checksum_type"))) == -1) {
                cksumType = Checksum.CKSUMTYPE_RSA_MD5; // default
            }
        }
    } catch (KrbException e) {
    }
    return getInstance(cksumType);
}
 
Example 3
Source File: EType.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieves the default etypes from the configuration file, or
 * if that's not available, return the built-in list of default etypes.
 * This result is always non-empty. If no etypes are found,
 * an exception is thrown.
 */
public static int[] getDefaults(String configName)
        throws KrbException {
    Config config = null;
    try {
        config = Config.getInstance();
    } catch (KrbException exc) {
        if (DEBUG) {
            System.out.println("Exception while getting " +
                configName + exc.getMessage());
            System.out.println("Using default builtin etypes");
        }
        return getBuiltInDefaults();
    }
    return config.defaultEtype(configName);
}
 
Example 4
Source File: DNS.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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 + "]");
    };
}
 
Example 5
Source File: DNS.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 + "]");
    };
}
 
Example 6
Source File: EType.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Retrieves the default etypes from the configuration file, or
 * if that's not available, return the built-in list of default etypes.
 * This result is always non-empty. If no etypes are found,
 * an exception is thrown.
 */
public static int[] getDefaults(String configName)
        throws KrbException {
    Config config = null;
    try {
        config = Config.getInstance();
    } catch (KrbException exc) {
        if (DEBUG) {
            System.out.println("Exception while getting " +
                configName + exc.getMessage());
            System.out.println("Using default builtin etypes");
        }
        return getBuiltInDefaults();
    }
    return config.defaultEtype(configName);
}
 
Example 7
Source File: EType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void initStatic() {
    boolean allowed = false;
    try {
        Config cfg = Config.getInstance();
        String temp = cfg.get("libdefaults", "allow_weak_crypto");
        if (temp != null && temp.equals("true")) allowed = true;
    } catch (Exception exc) {
        if (DEBUG) {
            System.out.println ("Exception in getting allow_weak_crypto, " +
                                "using default value " +
                                exc.getMessage());
        }
    }
    allowWeakCrypto = allowed;
}
 
Example 8
Source File: EType.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void initStatic() {
    boolean allowed = false;
    try {
        Config cfg = Config.getInstance();
        String temp = cfg.get("libdefaults", "allow_weak_crypto");
        if (temp != null && temp.equals("true")) allowed = true;
    } catch (Exception exc) {
        if (DEBUG) {
            System.out.println ("Exception in getting allow_weak_crypto, " +
                                "using default value " +
                                exc.getMessage());
        }
    }
    allowWeakCrypto = allowed;
}
 
Example 9
Source File: Duplicates.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: ConfigWithQuotations.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // This config file is generated using Kerberos.app on a Mac
    System.setProperty("java.security.krb5.conf",
            System.getProperty("test.src", ".") +"/edu.mit.Kerberos");
    Config config = Config.getInstance();

    System.out.println(config);

    if (!config.getDefaultRealm().equals("MAC.LOCAL")) {
        throw new Exception("Realm error");
    }
    if (!config.getKDCList("MAC.LOCAL").equals("kdc.mac.local:88")) {
        throw new Exception("KDC error");
    }
}
 
Example 11
Source File: HBaseClient.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
private static synchronized void login(Args args, Configuration conf) throws Exception {
    if (args.has(Args.OPTION_DEBUG)) {
        System.setProperty("sun.security.krb5.debug", "true");
        System.setProperty("sun.security.spnego.debug", "true");
    }

    System.setProperty("java.security.auth.login.config", createJaasConfigFile(args));
    System.setProperty("java.security.krb5.conf", kerberosConfigFile(args));

    Config krbConfig = Config.getInstance();
    final String realm;
    if (args.has(Args.OPTION_REALM)) {
        realm = (String) args.valueOf(Args.OPTION_REALM);
        System.setProperty("java.security.krb5.realm", realm);
        System.setProperty("java.security.krb5.kdc", krbConfig.getKDCList(realm));
        Config.refresh();
    } else {
        realm = krbConfig.getDefaultRealm();
    }

    updateConf(conf, realm);

    if (args.has(Args.OPTION_KEY_TAB, Args.OPTION_KEY_TAB_SHORT)) {
        UserGroupInformation.setConfiguration(conf);
        UserGroupInformation.loginUserFromKeytab(principal(args), (String) args.valueOf(Args.OPTION_KEY_TAB, Args.OPTION_KEY_TAB_SHORT));
    } else {
        loginWithPassword(args, conf);
    }

    UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
    System.out.println(currentUser + "\n");
}
 
Example 12
Source File: ParseConfig.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") +"/krb5.conf");
    Config config = Config.getInstance();
    config.listTable();

    String sample = "kdc.example.com kdc2.example.com";
    for ( int i = 0; i < 4; i++ ) {
        String expected = config.getAll("realms", "EXAMPLE_" + i + ".COM", "kdc");
        if (!sample.equals(expected)) {
            throw new Exception("krb5.conf: unexpected kdc value \"" +
                    expected + "\"");
        }
    }
}
 
Example 13
Source File: Duplicates.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 14
Source File: EType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void initStatic() {
    boolean allowed = false;
    try {
        Config cfg = Config.getInstance();
        String temp = cfg.get("libdefaults", "allow_weak_crypto");
        if (temp != null && temp.equals("true")) allowed = true;
    } catch (Exception exc) {
        if (DEBUG) {
            System.out.println ("Exception in getting allow_weak_crypto, " +
                                "using default value " +
                                exc.getMessage());
        }
    }
    allowWeakCrypto = allowed;
}
 
Example 15
Source File: Duplicates.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 16
Source File: Semicolon.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    System.setProperty("java.security.krb5.conf",
            System.getProperty("test.src", ".") + "/comments.conf");
    Config config = Config.getInstance();
    config.get("section", "value");
}
 
Example 17
Source File: ConfPlusProp.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void refresh() throws Exception {
    Config.refresh();
    config = Config.getInstance();
}
 
Example 18
Source File: Semicolon.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    System.setProperty("java.security.krb5.conf",
            System.getProperty("test.src", ".") + "/comments.conf");
    Config config = Config.getInstance();
    config.get("section", "value");
}
 
Example 19
Source File: Semicolon.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    System.setProperty("java.security.krb5.conf",
            System.getProperty("test.src", ".") + "/comments.conf");
    Config config = Config.getInstance();
    config.get("section", "value");
}
 
Example 20
Source File: Semicolon.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    System.setProperty("java.security.krb5.conf",
            System.getProperty("test.src", ".") + "/comments.conf");
    Config config = Config.getInstance();
    config.get("section", "value");
}