< prev index next >

src/java.security.jgss/share/classes/sun/security/jgss/GSSUtil.java

Print this page
rev 11805 : 8078439: SPNEGO auth fails if client proposes MS krb5 OID


  42 import java.security.AccessController;
  43 import java.security.AccessControlContext;
  44 import java.security.PrivilegedExceptionAction;
  45 import java.security.PrivilegedActionException;
  46 import javax.security.auth.callback.CallbackHandler;
  47 import javax.security.auth.login.LoginContext;
  48 import javax.security.auth.login.LoginException;
  49 import sun.security.action.GetBooleanAction;
  50 import sun.security.util.ConsoleCallbackHandler;
  51 
  52 /**
  53  * The GSSUtilImplementation that knows how to work with the internals of
  54  * the GSS-API.
  55  */
  56 public class GSSUtil {
  57 
  58     public static final Oid GSS_KRB5_MECH_OID =
  59                 GSSUtil.createOid("1.2.840.113554.1.2.2");
  60     public static final Oid GSS_KRB5_MECH_OID2 =
  61                 GSSUtil.createOid("1.3.5.1.5.2");


  62 
  63     public static final Oid GSS_SPNEGO_MECH_OID =
  64                 GSSUtil.createOid("1.3.6.1.5.5.2");
  65 
  66     public static final Oid NT_GSS_KRB5_PRINCIPAL =
  67                 GSSUtil.createOid("1.2.840.113554.1.2.2.1");
  68 
  69     private static final String DEFAULT_HANDLER =
  70             "auth.login.defaultCallbackHandler";
  71 
  72     static final boolean DEBUG;
  73     static {
  74         DEBUG = (AccessController.doPrivileged
  75                         (new GetBooleanAction("sun.security.jgss.debug"))).
  76                                 booleanValue();
  77     }
  78 
  79     static void debug(String message) {
  80         if (DEBUG) {
  81             assert(message != null);


  84     }
  85 
  86     // NOTE: this method is only for creating Oid objects with
  87     // known to be valid <code>oidStr</code> given it ignores
  88     // the GSSException
  89     public static Oid createOid(String oidStr) {
  90         try {
  91             return new Oid(oidStr);
  92         } catch (GSSException e) {
  93             debug("Ignored invalid OID: " + oidStr);
  94             return null;
  95         }
  96     }
  97 
  98     public static boolean isSpNegoMech(Oid oid) {
  99         return (GSS_SPNEGO_MECH_OID.equals(oid));
 100     }
 101 
 102     public static boolean isKerberosMech(Oid oid) {
 103         return (GSS_KRB5_MECH_OID.equals(oid) ||
 104                 GSS_KRB5_MECH_OID2.equals(oid));

 105 
 106     }
 107 
 108     public static String getMechStr(Oid oid) {
 109         if (isSpNegoMech(oid)) {
 110             return "SPNEGO";
 111         } else if (isKerberosMech(oid)) {
 112             return "Kerberos V5";
 113         } else {
 114             return oid.toString();
 115         }
 116     }
 117 
 118     /**
 119      * Note: The current impl only works with Sun's impl of
 120      * GSSName and GSSCredential since it depends on package
 121      * private APIs.
 122      */
 123     public static Subject getSubject(GSSName name,
 124                                      GSSCredential creds) {




  42 import java.security.AccessController;
  43 import java.security.AccessControlContext;
  44 import java.security.PrivilegedExceptionAction;
  45 import java.security.PrivilegedActionException;
  46 import javax.security.auth.callback.CallbackHandler;
  47 import javax.security.auth.login.LoginContext;
  48 import javax.security.auth.login.LoginException;
  49 import sun.security.action.GetBooleanAction;
  50 import sun.security.util.ConsoleCallbackHandler;
  51 
  52 /**
  53  * The GSSUtilImplementation that knows how to work with the internals of
  54  * the GSS-API.
  55  */
  56 public class GSSUtil {
  57 
  58     public static final Oid GSS_KRB5_MECH_OID =
  59                 GSSUtil.createOid("1.2.840.113554.1.2.2");
  60     public static final Oid GSS_KRB5_MECH_OID2 =
  61                 GSSUtil.createOid("1.3.5.1.5.2");
  62     public static final Oid GSS_KRB5_MECH_OID_MS =
  63                 GSSUtil.createOid("1.2.840.48018.1.2.2");
  64 
  65     public static final Oid GSS_SPNEGO_MECH_OID =
  66                 GSSUtil.createOid("1.3.6.1.5.5.2");
  67 
  68     public static final Oid NT_GSS_KRB5_PRINCIPAL =
  69                 GSSUtil.createOid("1.2.840.113554.1.2.2.1");
  70 
  71     private static final String DEFAULT_HANDLER =
  72             "auth.login.defaultCallbackHandler";
  73 
  74     static final boolean DEBUG;
  75     static {
  76         DEBUG = (AccessController.doPrivileged
  77                         (new GetBooleanAction("sun.security.jgss.debug"))).
  78                                 booleanValue();
  79     }
  80 
  81     static void debug(String message) {
  82         if (DEBUG) {
  83             assert(message != null);


  86     }
  87 
  88     // NOTE: this method is only for creating Oid objects with
  89     // known to be valid <code>oidStr</code> given it ignores
  90     // the GSSException
  91     public static Oid createOid(String oidStr) {
  92         try {
  93             return new Oid(oidStr);
  94         } catch (GSSException e) {
  95             debug("Ignored invalid OID: " + oidStr);
  96             return null;
  97         }
  98     }
  99 
 100     public static boolean isSpNegoMech(Oid oid) {
 101         return (GSS_SPNEGO_MECH_OID.equals(oid));
 102     }
 103 
 104     public static boolean isKerberosMech(Oid oid) {
 105         return (GSS_KRB5_MECH_OID.equals(oid) ||
 106                 GSS_KRB5_MECH_OID2.equals(oid) ||
 107                 GSS_KRB5_MECH_OID_MS.equals(oid));
 108 
 109     }
 110 
 111     public static String getMechStr(Oid oid) {
 112         if (isSpNegoMech(oid)) {
 113             return "SPNEGO";
 114         } else if (isKerberosMech(oid)) {
 115             return "Kerberos V5";
 116         } else {
 117             return oid.toString();
 118         }
 119     }
 120 
 121     /**
 122      * Note: The current impl only works with Sun's impl of
 123      * GSSName and GSSCredential since it depends on package
 124      * private APIs.
 125      */
 126     public static Subject getSubject(GSSName name,
 127                                      GSSCredential creds) {


< prev index next >