Java Code Examples for sun.security.krb5.Realm#AUTODEDUCEREALM

The following examples show how to use sun.security.krb5.Realm#AUTODEDUCEREALM . 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
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            // getNativeNameType() can modify NT_GSS_KRB5_PRINCIPAL to null
            if ((nameType == null
                        || nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}
 
Example 2
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            // getNativeNameType() can modify NT_GSS_KRB5_PRINCIPAL to null
            if ((nameType == null
                        || nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}
 
Example 3
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            // getNativeNameType() can modify NT_GSS_KRB5_PRINCIPAL to null
            if ((nameType == null
                        || nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}
 
Example 4
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            // getNativeNameType() can modify NT_GSS_KRB5_PRINCIPAL to null
            if ((nameType == null
                        || nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}
 
Example 5
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            // getNativeNameType() can modify NT_GSS_KRB5_PRINCIPAL to null
            if ((nameType == null
                        || nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}
 
Example 6
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            // getNativeNameType() can modify NT_GSS_KRB5_PRINCIPAL to null
            if ((nameType == null
                        || nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}
 
Example 7
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            if (nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL)
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}
 
Example 8
GSSNameElement(byte[] nameBytes, Oid nameType, GSSLibStub stub)
    throws GSSException {
    assert(stub != null);
    if (nameBytes == null) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    cStub = stub;
    byte[] name = nameBytes;

    if (nameType != null) {
        // Special handling the specified name type if
        // necessary
        nameType = getNativeNameType(nameType, stub);

        if (GSSName.NT_EXPORT_NAME.equals(nameType)) {
            // Need to add back the mech Oid portion (stripped
            // off by GSSNameImpl class prior to calling this
            // method) for "NT_EXPORT_NAME"
            byte[] mechBytes = null;
            DerOutputStream dout = new DerOutputStream();
            Oid mech = cStub.getMech();
            try {
                dout.putOID(new ObjectIdentifier(mech.toString()));
            } catch (IOException e) {
                throw new GSSExceptionImpl(GSSException.FAILURE, e);
            }
            mechBytes = dout.toByteArray();
            name = new byte[2 + 2 + mechBytes.length + 4 + nameBytes.length];
            int pos = 0;
            name[pos++] = 0x04;
            name[pos++] = 0x01;
            name[pos++] = (byte) (mechBytes.length>>>8);
            name[pos++] = (byte) mechBytes.length;
            System.arraycopy(mechBytes, 0, name, pos, mechBytes.length);
            pos += mechBytes.length;
            name[pos++] = (byte) (nameBytes.length>>>24);
            name[pos++] = (byte) (nameBytes.length>>>16);
            name[pos++] = (byte) (nameBytes.length>>>8);
            name[pos++] = (byte) nameBytes.length;
            System.arraycopy(nameBytes, 0, name, pos, nameBytes.length);
        }
    }
    pName = cStub.importName(name, nameType);
    setPrintables();

    SecurityManager sm = System.getSecurityManager();
    if (sm != null && !Realm.AUTODEDUCEREALM) {
        String krbName = getKrbName();
        int atPos = krbName.lastIndexOf('@');
        if (atPos != -1) {
            String atRealm = krbName.substring(atPos);
            // getNativeNameType() can modify NT_GSS_KRB5_PRINCIPAL to null
            if ((nameType == null
                        || nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL))
                    && new String(nameBytes).endsWith(atRealm)) {
                // Created from Kerberos name with realm, no need to check
            } else {
                try {
                    sm.checkPermission(new ServicePermission(atRealm, "-"));
                } catch (SecurityException se) {
                    // Do not chain the actual exception to hide info
                    throw new GSSException(GSSException.FAILURE);
                }
            }
        }
    }

    SunNativeProvider.debug("Imported " + printableName + " w/ type " +
                            printableType);
}