jdk/src/java.security.jgss/share/classes/sun/security/jgss/SunProvider.java
changeset 31270 e6470b24700d
parent 25859 3317bb8137f4
child 33991 619bfc4d582d
equal deleted inserted replaced
31269:14968253ce7e 31270:e6470b24700d
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    25 
    25 
    26 package sun.security.jgss;
    26 package sun.security.jgss;
    27 
    27 
    28 import java.security.Provider;
    28 import java.security.Provider;
    29 import java.security.AccessController;
    29 import java.security.AccessController;
       
    30 import java.security.PrivilegedAction;
       
    31 import java.security.NoSuchAlgorithmException;
       
    32 import java.security.InvalidParameterException;
       
    33 import java.security.ProviderException;
       
    34 import sun.security.jgss.krb5.Krb5MechFactory;
       
    35 import sun.security.jgss.spnego.SpNegoMechFactory;
    30 
    36 
    31 /**
    37 /**
    32  * Defines the Sun JGSS provider.
    38  * Defines the Sun JGSS provider.
    33  * Will merger this with the Sun security provider
    39  * Will merger this with the Sun security provider
    34  * sun.security.provider.Sun when the JGSS src is merged with the JDK
    40  * sun.security.provider.Sun when the JGSS src is merged with the JDK
    56 
    62 
    57     private static final String INFO = "Sun " +
    63     private static final String INFO = "Sun " +
    58         "(Kerberos v5, SPNEGO)";
    64         "(Kerberos v5, SPNEGO)";
    59     //  "(Kerberos v5, Dummy GSS-API Mechanism)";
    65     //  "(Kerberos v5, Dummy GSS-API Mechanism)";
    60 
    66 
       
    67     private static final class ProviderService extends Provider.Service {
       
    68         ProviderService(Provider p, String type, String algo, String cn) {
       
    69             super(p, type, algo, cn, null, null);
       
    70         }
       
    71 
       
    72         @Override
       
    73         public Object newInstance(Object ctrParamObj)
       
    74             throws NoSuchAlgorithmException {
       
    75             String type = getType();
       
    76             if (ctrParamObj != null) {
       
    77                 throw new InvalidParameterException
       
    78                     ("constructorParameter not used with " + type +
       
    79                      " engines");
       
    80             }
       
    81             String algo = getAlgorithm();
       
    82             try {
       
    83                 if (type.equals("GssApiMechanism")) {
       
    84                     if (algo.equals("1.2.840.113554.1.2.2")) {
       
    85                         return new Krb5MechFactory();
       
    86                     } else if (algo.equals("1.3.6.1.5.5.2")) {
       
    87                         return new SpNegoMechFactory();
       
    88                     }
       
    89                 }
       
    90             } catch (Exception ex) {
       
    91                 throw new NoSuchAlgorithmException
       
    92                     ("Error constructing " + type + " for " +
       
    93                     algo + " using SunJGSS", ex);
       
    94             }
       
    95             throw new ProviderException("No impl for " + algo +
       
    96                 " " + type);
       
    97         }
       
    98     }
       
    99 
    61     public static final SunProvider INSTANCE = new SunProvider();
   100     public static final SunProvider INSTANCE = new SunProvider();
    62 
   101 
    63     public SunProvider() {
   102     public SunProvider() {
    64         /* We are the Sun JGSS provider */
   103         /* We are the Sun JGSS provider */
    65         super("SunJGSS", 1.9d, INFO);
   104         super("SunJGSS", 1.9d, INFO);
    66 
   105 
    67         AccessController.doPrivileged(
   106         final Provider p = this;
    68                         new java.security.PrivilegedAction<Void>() {
   107         AccessController.doPrivileged(new PrivilegedAction<Void>() {
    69             public Void run() {
   108             public Void run() {
    70                 put("GssApiMechanism.1.2.840.113554.1.2.2",
   109                 putService(new ProviderService(p, "GssApiMechanism",
    71                     "sun.security.jgss.krb5.Krb5MechFactory");
   110                            "1.2.840.113554.1.2.2",
    72                 put("GssApiMechanism.1.3.6.1.5.5.2",
   111                            "sun.security.jgss.krb5.Krb5MechFactory"));
    73                     "sun.security.jgss.spnego.SpNegoMechFactory");
   112                 putService(new ProviderService(p, "GssApiMechanism",
    74                 /*
   113                            "1.3.6.1.5.5.2",
    75                   put("GssApiMechanism.1.3.6.1.4.1.42.2.26.1.2",
   114                            "sun.security.jgss.spnego.SpNegoMechFactory"));
    76                   "sun.security.jgss.dummy.DummyMechFactory");
       
    77                 */
       
    78                 return null;
   115                 return null;
    79             }
   116             }
    80         });
   117         });
    81     }
   118     }
    82 }
   119 }