1870N/A/*
3261N/A * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
1870N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1870N/A *
1870N/A * This code is free software; you can redistribute it and/or modify it
1870N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1870N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1870N/A *
1870N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1870N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3121N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1870N/A * version 2 for more details (a copy is included in the LICENSE file that
1870N/A * accompanied this code).
1870N/A *
1870N/A * You should have received a copy of the GNU General Public License version
1870N/A * 2 along with this work; if not, write to the Free Software Foundation,
1870N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1870N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1870N/A */
1870N/A
1870N/Apackage sun.security.ssl;
1870N/A
1870N/Aimport java.security.AccessControlContext;
1870N/Aimport java.security.AccessController;
1870N/Aimport java.security.Permission;
1870N/Aimport java.security.Principal;
1870N/Aimport java.security.PrivilegedAction;
1870N/Aimport javax.crypto.SecretKey;
1870N/Aimport javax.security.auth.Subject;
1870N/Aimport javax.security.auth.login.LoginException;
1870N/A
1870N/A/**
1870N/A * A helper class for Kerberos APIs.
1870N/A */
1870N/Apublic final class Krb5Helper {
1870N/A
1870N/A private Krb5Helper() { }
1870N/A
1870N/A // loads Krb5Proxy implementation class if available
1870N/A private static final String IMPL_CLASS =
1870N/A "sun.security.ssl.krb5.Krb5ProxyImpl";
1870N/A
1870N/A private static final Krb5Proxy proxy =
1870N/A AccessController.doPrivileged(new PrivilegedAction<Krb5Proxy>() {
1870N/A public Krb5Proxy run() {
1870N/A try {
1870N/A Class<?> c = Class.forName(IMPL_CLASS, true, null);
1870N/A return (Krb5Proxy)c.newInstance();
1870N/A } catch (ClassNotFoundException cnf) {
1870N/A return null;
1870N/A } catch (InstantiationException e) {
1870N/A throw new AssertionError(e);
1870N/A } catch (IllegalAccessException e) {
1870N/A throw new AssertionError(e);
1870N/A }
1870N/A }});
1870N/A
1870N/A /**
1870N/A * Returns true if Kerberos is available.
1870N/A */
1870N/A public static boolean isAvailable() {
1870N/A return proxy != null;
1870N/A }
1870N/A
1870N/A private static void ensureAvailable() {
1870N/A if (proxy == null)
1870N/A throw new AssertionError("Kerberos should have been available");
1870N/A }
1870N/A
1870N/A /**
1870N/A * Returns the Subject associated with client-side of the SSL socket.
1870N/A */
1870N/A public static Subject getClientSubject(AccessControlContext acc)
1870N/A throws LoginException {
1870N/A ensureAvailable();
1870N/A return proxy.getClientSubject(acc);
1870N/A }
1870N/A
1870N/A /**
1870N/A * Returns the Subject associated with server-side of the SSL socket.
1870N/A */
1870N/A public static Subject getServerSubject(AccessControlContext acc)
1870N/A throws LoginException {
1870N/A ensureAvailable();
1870N/A return proxy.getServerSubject(acc);
1870N/A }
1870N/A
1870N/A /**
1870N/A * Returns the KerberosKeys for the default server-side principal.
1870N/A */
1870N/A public static SecretKey[] getServerKeys(AccessControlContext acc)
1870N/A throws LoginException {
1870N/A ensureAvailable();
1870N/A return proxy.getServerKeys(acc);
1870N/A }
1870N/A
1870N/A /**
1870N/A * Returns the server-side principal name associated with the KerberosKey.
1870N/A */
1870N/A public static String getServerPrincipalName(SecretKey kerberosKey) {
1870N/A ensureAvailable();
1870N/A return proxy.getServerPrincipalName(kerberosKey);
1870N/A }
1870N/A
1870N/A /**
1870N/A * Returns the hostname embedded in the principal name.
1870N/A */
1870N/A public static String getPrincipalHostName(Principal principal) {
1870N/A ensureAvailable();
1870N/A return proxy.getPrincipalHostName(principal);
1870N/A }
1870N/A
1870N/A /**
1870N/A * Returns a ServicePermission for the principal name and action.
1870N/A */
1870N/A public static Permission getServicePermission(String principalName,
1870N/A String action) {
1870N/A ensureAvailable();
1870N/A return proxy.getServicePermission(principalName, action);
1870N/A }
1870N/A}