sun.security.krb5.internal.Krb5 Java Examples

The following examples show how to use sun.security.krb5.internal.Krb5. 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: KrbAsReqBuilder.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
boolean handleError(KrbException ke) throws RealmException {
    if (enabled) {
        if (ke.returnCode() == Krb5.KRB_ERR_WRONG_REALM) {
            Realm referredRealm = ke.getError().getClientRealm();
            if (req.getMessage().reqBody.kdcOptions.get(KDCOptions.CANONICALIZE) &&
                    referredRealm != null && referredRealm.toString().length() > 0 &&
                    count < Config.MAX_REFERRALS) {
                refCname = new PrincipalName(refCname.getNameType(),
                        refCname.getNameStrings(), referredRealm);
                refreshComm = true;
                count++;
                return true;
            }
        }
        if (count < Config.MAX_REFERRALS &&
                refCname.getNameType() != PrincipalName.KRB_NT_ENTERPRISE) {
            // Server may raise an error if CANONICALIZE is true.
            // Try CANONICALIZE false.
            enabled = false;
            return true;
        }
    }
    return false;
}
 
Example #2
Source File: Config.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate KDC using DNS
 *
 * @param realm the realm for which the master KDC is desired
 * @return the KDC
 */
private String getKDCFromDNS(String realm) throws KrbException {
    // use DNS to locate KDC
    String kdcs = "";
    String[] srvs = null;
    // locate DNS SRV record using UDP
    if (DEBUG) {
        System.out.println("getKDCFromDNS using UDP");
    }
    srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
    if (srvs == null) {
        // locate DNS SRV record using TCP
        if (DEBUG) {
            System.out.println("getKDCFromDNS using TCP");
        }
        srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
    }
    if (srvs == null) {
        // no DNS SRV records
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate KDC for realm " + realm);
    }
    if (srvs.length == 0) {
        return null;
    }
    for (int i = 0; i < srvs.length; i++) {
        kdcs += srvs[i].trim() + " ";
    }
    kdcs = kdcs.trim();
    if (kdcs.equals("")) {
        return null;
    }
    return kdcs;
}
 
Example #3
Source File: Config.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #4
Source File: Realm.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected static String parseRealm(String name) throws RealmException {
    String result = parseRealmAtSeparator(name);
    if (result == null)
        result = name;
    if (result == null || result.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(result))
        throw new RealmException(Krb5.REALM_ILLCHAR);
    return result;
}
 
Example #5
Source File: Realm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a realm from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicate if this data field is optional
 * @return an instance of Realm.
 *
 */
public static Realm parse(DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException, RealmException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
        return null;
    }
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    } else {
        DerValue subDer = der.getData().getDerValue();
        return new Realm(subDer);
    }
}
 
Example #6
Source File: Realm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a realm from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicate if this data field is optional
 * @return an instance of Realm.
 *
 */
public static Realm parse(DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException, RealmException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
        return null;
    }
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    } else {
        DerValue subDer = der.getData().getDerValue();
        return new Realm(subDer);
    }
}
 
Example #7
Source File: ReplayCacheTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
        throws Exception {

    new OneKDC(null);

    if (args[0].equals("dfl")) {
        // Store file in scratch directory
        args[0] = "dfl:" + System.getProperty("user.dir") + File.separator;
        System.setProperty("sun.security.krb5.rcache", args[0]);
    }

    Context c, s;
    c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
    s = Context.fromUserKtab(OneKDC.SERVER, OneKDC.KTAB, true);

    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);

    byte[] first = c.take(new byte[0]);
    c.take(s.take(first));

    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    try {
        s.take(first);  // Replay the last apreq sent
        throw new Exception("This method should fail");
    } catch (GSSException gsse) {
        gsse.printStackTrace();
        KrbException ke = (KrbException)gsse.getCause();
        if (ke.returnCode() != Krb5.KRB_AP_ERR_REPEAT) {
            throw gsse;
        }
    }
}
 
Example #8
Source File: ReplayCacheTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
        throws Exception {

    new OneKDC(null);

    if (args[0].equals("dfl")) {
        // Store file in scratch directory
        args[0] = "dfl:" + System.getProperty("user.dir") + File.separator;
        System.setProperty("sun.security.krb5.rcache", args[0]);
    }

    Context c, s;
    c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
    s = Context.fromUserKtab(OneKDC.SERVER, OneKDC.KTAB, true);

    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);

    byte[] first = c.take(new byte[0]);
    c.take(s.take(first));

    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    try {
        s.take(first);  // Replay the last apreq sent
        throw new Exception("This method should fail");
    } catch (GSSException gsse) {
        gsse.printStackTrace();
        KrbException ke = (KrbException)gsse.getCause();
        if (ke.returnCode() != Krb5.KRB_AP_ERR_REPEAT) {
            throw gsse;
        }
    }
}
 
Example #9
Source File: Config.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate KDC using DNS
 *
 * @param realm the realm for which the master KDC is desired
 * @return the KDC
 */
private String getKDCFromDNS(String realm) throws KrbException {
    // use DNS to locate KDC
    String kdcs = "";
    String[] srvs = null;
    // locate DNS SRV record using UDP
    if (DEBUG) {
        System.out.println("getKDCFromDNS using UDP");
    }
    srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
    if (srvs == null) {
        // locate DNS SRV record using TCP
        if (DEBUG) {
            System.out.println("getKDCFromDNS using TCP");
        }
        srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
    }
    if (srvs == null) {
        // no DNS SRV records
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate KDC for realm " + realm);
    }
    if (srvs.length == 0) {
        return null;
    }
    for (int i = 0; i < srvs.length; i++) {
        kdcs += srvs[i].trim() + " ";
    }
    kdcs = kdcs.trim();
    if (kdcs.equals("")) {
        return null;
    }
    return kdcs;
}
 
Example #10
Source File: Realm.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a realm from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicate if this data field is optional
 * @return an instance of Realm.
 *
 */
public static Realm parse(DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException, RealmException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
        return null;
    }
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    } else {
        DerValue subDer = der.getData().getDerValue();
        return new Realm(subDer);
    }
}
 
Example #11
Source File: DflCache.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    try {
        checkAndStore0(currTime, time);
    } catch (IOException ioe) {
        KrbApErrException ke = new KrbApErrException(Krb5.KRB_ERR_GENERIC);
        ke.initCause(ioe);
        throw ke;
    }
}
 
Example #12
Source File: Config.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate KDC using DNS
 *
 * @param realm the realm for which the master KDC is desired
 * @return the KDC
 */
private String getKDCFromDNS(String realm) throws KrbException {
    // use DNS to locate KDC
    String kdcs = "";
    String[] srvs = null;
    // locate DNS SRV record using UDP
    if (DEBUG) {
        System.out.println("getKDCFromDNS using UDP");
    }
    srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
    if (srvs == null) {
        // locate DNS SRV record using TCP
        if (DEBUG) {
            System.out.println("getKDCFromDNS using TCP");
        }
        srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
    }
    if (srvs == null) {
        // no DNS SRV records
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate KDC for realm " + realm);
    }
    if (srvs.length == 0) {
        return null;
    }
    for (int i = 0; i < srvs.length; i++) {
        kdcs += srvs[i].trim() + " ";
    }
    kdcs = kdcs.trim();
    if (kdcs.equals("")) {
        return null;
    }
    return kdcs;
}
 
Example #13
Source File: Realm.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #14
Source File: Realm.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a realm from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicate if this data field is optional
 * @return an instance of Realm.
 *
 */
public static Realm parse(DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException, RealmException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
        return null;
    }
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    } else {
        DerValue subDer = der.getData().getDerValue();
        return new Realm(subDer);
    }
}
 
Example #15
Source File: ReplayCacheTest.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 {

    new OneKDC(null);

    if (args[0].equals("dfl")) {
        // Store file in scratch directory
        args[0] = "dfl:" + System.getProperty("user.dir") + File.separator;
        System.setProperty("sun.security.krb5.rcache", args[0]);
    }

    Context c, s;
    c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
    s = Context.fromUserKtab(OneKDC.SERVER, OneKDC.KTAB, true);

    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);

    byte[] first = c.take(new byte[0]);
    c.take(s.take(first));

    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    try {
        s.take(first);  // Replay the last apreq sent
        throw new Exception("This method should fail");
    } catch (GSSException gsse) {
        gsse.printStackTrace();
        KrbException ke = (KrbException)gsse.getCause();
        if (ke.returnCode() != Krb5.KRB_AP_ERR_REPEAT) {
            throw gsse;
        }
    }
}
 
Example #16
Source File: Realm.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static String parseRealmAtSeparator(String name)
    throws RealmException {
    if (name == null) {
        throw new IllegalArgumentException
            ("null input name is not allowed");
    }
    String temp = new String(name);
    String result = null;
    int i = 0;
    while (i < temp.length()) {
        if (temp.charAt(i) == PrincipalName.NAME_REALM_SEPARATOR) {
            if (i == 0 || temp.charAt(i - 1) != '\\') {
                if (i + 1 < temp.length()) {
                    result = temp.substring(i + 1, temp.length());
                } else {
                    throw new IllegalArgumentException
                            ("empty realm part not allowed");
                }
                break;
            }
        }
        i++;
    }
    if (result != null) {
        if (result.length() == 0)
            throw new RealmException(Krb5.REALM_NULL);
        if (!isValidRealmString(result))
            throw new RealmException(Krb5.REALM_ILLCHAR);
    }
    return result;
}
 
Example #17
Source File: Realm.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #18
Source File: ReplayCacheTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
        throws Exception {

    new OneKDC(null);

    if (args[0].equals("dfl")) {
        // Store file in scratch directory
        args[0] = "dfl:" + System.getProperty("user.dir") + File.separator;
        System.setProperty("sun.security.krb5.rcache", args[0]);
    }

    Context c, s;
    c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
    s = Context.fromUserKtab(OneKDC.SERVER, OneKDC.KTAB, true);

    c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);

    byte[] first = c.take(new byte[0]);
    c.take(s.take(first));

    s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
    try {
        s.take(first);  // Replay the last apreq sent
        throw new Exception("This method should fail");
    } catch (GSSException gsse) {
        gsse.printStackTrace();
        KrbException ke = (KrbException)gsse.getCause();
        if (ke.returnCode() != Krb5.KRB_AP_ERR_REPEAT) {
            throw gsse;
        }
    }
}
 
Example #19
Source File: Realm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #20
Source File: Config.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #21
Source File: DflCache.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    try {
        checkAndStore0(currTime, time);
    } catch (IOException ioe) {
        KrbApErrException ke = new KrbApErrException(Krb5.KRB_ERR_GENERIC);
        ke.initCause(ioe);
        throw ke;
    }
}
 
Example #22
Source File: Realm.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a realm from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicate if this data field is optional
 * @return an instance of Realm.
 *
 */
public static Realm parse(DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException, RealmException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
        return null;
    }
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    } else {
        DerValue subDer = der.getData().getDerValue();
        return new Realm(subDer);
    }
}
 
Example #23
Source File: Realm.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #24
Source File: DflCache.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    try {
        checkAndStore0(currTime, time);
    } catch (IOException ioe) {
        KrbApErrException ke = new KrbApErrException(Krb5.KRB_ERR_GENERIC);
        ke.initCause(ioe);
        throw ke;
    }
}
 
Example #25
Source File: Config.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #26
Source File: DflCache.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void checkAndStore(KerberosTime currTime, AuthTimeWithHash time)
        throws KrbApErrException {
    try {
        checkAndStore0(currTime, time);
    } catch (IOException ioe) {
        KrbApErrException ke = new KrbApErrException(Krb5.KRB_ERR_GENERIC);
        ke.initCause(ioe);
        throw ke;
    }
}
 
Example #27
Source File: Realm.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #28
Source File: Config.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #29
Source File: Realm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Realm object.
 * @param encoding a Der-encoded data.
 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */
public Realm(DerValue encoding)
    throws Asn1Exception, RealmException, IOException {
    if (encoding == null) {
        throw new IllegalArgumentException("encoding can not be null");
    }
    realm = new KerberosString(encoding).toString();
    if (realm == null || realm.length() == 0)
        throw new RealmException(Krb5.REALM_NULL);
    if (!isValidRealmString(realm))
        throw new RealmException(Krb5.REALM_ILLCHAR);
}
 
Example #30
Source File: KdcComm.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public KdcComm(String realm) throws KrbException {
    if (realm == null) {
       realm = Config.getInstance().getDefaultRealm();
        if (realm == null) {
            throw new KrbException(Krb5.KRB_ERR_GENERIC,
                                   "Cannot find default realm");
        }
    }
    this.realm = realm;
}