📄 gssmanager.java
字号:
/* GSSManager.java -- manager class for the GSS-API. Copyright (C) 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. The documentation comments of this class are derived from the text of RFC 2853: Generic Security Service API Version 2: Java Bindings. That document is covered under the following license notice:Copyright (C) The Internet Society (2000). All Rights Reserved.This document and translations of it may be copied and furnished toothers, and derivative works that comment on or otherwise explain itor assist in its implementation may be prepared, copied, published anddistributed, in whole or in part, without restriction of any kind,provided that the above copyright notice and this paragraph areincluded on all such copies and derivative works. However, thisdocument itself may not be modified in any way, such as by removingthe copyright notice or references to the Internet Society or otherInternet organizations, except as needed for the purpose of developingInternet standards in which case the procedures for copyrights definedin the Internet Standards process must be followed, or as required totranslate it into languages other than English.The limited permissions granted above are perpetual and will not berevoked by the Internet Society or its successors or assigns.This document and the information contained herein is provided on an"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERINGTASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUTNOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREINWILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OFMERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. */package org.ietf.jgss;import java.security.Provider;import java.security.Security;/** * <p>The GSSManager class is an abstract class that serves as a factory * for three GSS interfaces: {@link GSSName}, {@link GSSCredential}, and * {@link GSSContext}. It also provides methods for applications to determine * what mechanisms are available from the GSS implementation and what * nametypes these mechanisms support. An instance of the default GSSManager * subclass may be obtained through the static method {@link #getInstance()}, * but applications are free to instantiate other subclasses of GSSManager.</p> * * <p>All but one method in this class are declared abstract. This means * that subclasses have to provide the complete implementation for those * methods. The only exception to this is the static method {@link * #getInstance()} which will have platform specific code to return an * instance of the default subclass.</p> * * <p>Platform providers of GSS are required not to add any constructors to * this class, private, public, or protected. This will ensure that all * subclasses invoke only the default constructor provided to the base * class by the compiler.</p> * * <p>A subclass extending the GSSManager abstract class may be implemented * as a modular provider based layer that utilizes some well known * service provider specification. The GSSManager API provides the * application with methods to set provider preferences on such an * implementation. These methods also allow the implementation to throw * a well-defined exception in case provider based configuration is not * supported. Applications that expect to be portable should be aware of * this and recover cleanly by catching the exception.</p> * * <p>It is envisioned that there will be three most common ways in which * providers will be used:</p> * * <ol> * <li>The application does not care about what provider is used (the * default case).</li> * * <li>The application wants a particular provider to be used * preferentially, either for a particular mechanism or all the * time, irrespective of mechanism.</li> * * <li>The application wants to use the locally configured providers * as far as possible but if support is missing for one or more * mechanisms then it wants to fall back on its own provider.</li> * </ol> * * <p>The GSSManager class has two methods that enable these modes of * usage: {@link #addProviderAtFront(java.security.Provider,org.ietf.jgss.Oid)} * and {@link #addProviderAtEnd(java.security.Provider,org.ietf.jgss.Oid)}. * These methods have the effect of creating an ordered list of * (<i>provider</i>, <i>oid</i>) pairs where each pair indicates a preference * of provider for a given oid.</p> * * <p>The use of these methods does not require any knowledge of whatever * service provider specification the GSSManager subclass follows. It is * hoped that these methods will serve the needs of most applications. * Additional methods may be added to an extended GSSManager that could * be part of a service provider specification that is standardized * later.</p> * * <h3>Example Code</h3> * * <pre>GSSManager mgr = GSSManager.getInstance();// What mechs are available to us?Oid[] supportedMechs = mgr.getMechs();// Set a preference for the provider to be used when support is needed// for the mechanisms "1.2.840.113554.1.2.2" and "1.3.6.1.5.5.1.1".Oid krb = new Oid("1.2.840.113554.1.2.2");Oid spkm1 = new Oid("1.3.6.1.5.5.1.1");Provider p = (Provider) (new com.foo.security.Provider());mgr.addProviderAtFront(p, krb);mgr.addProviderAtFront(p, spkm1);// What name types does this spkm implementation support?Oid[] nameTypes = mgr.getNamesForMech(spkm1);</pre> */public abstract class GSSManager{ // Constructor. // ------------------------------------------------------------------------- public GSSManager() { } // Class method. // ------------------------------------------------------------------------- /** * Returns the default GSSManager implementation. * * @return The default GSSManager implementation. */ public static synchronized GSSManager getInstance() { String impl = Security.getProperty("org.ietf.jgss.GSSManager"); if (impl == null) impl = "gnu.crypto.gssapi.GSSManagerImpl"; try { ClassLoader loader = GSSManager.class.getClassLoader(); if (loader == null) loader = ClassLoader.getSystemClassLoader(); Class c = loader.loadClass(impl); return (GSSManager) c.newInstance(); } catch (Exception x) { throw new RuntimeException(x.toString()); } } // Abstract methods. // ------------------------------------------------------------------------- /** * <p>This method is used to indicate to the GSSManager that the * application would like a particular provider to be used if no other * provider can be found that supports the given mechanism. When a value * of null is used instead of an Oid for the mechanism, the GSSManager * must use the indicated provider for any mechanism.</p> * * <p>Calling this method repeatedly preserves the older settings but * raises them above newer ones in preference thus forming an ordered * list of providers and Oid pairs that grows at the bottom. Thus the * older provider settings will be utilized first before this one is.</p> * * <p>If there are any previously existing preferences that conflict with * the preference being set here, then the GSSManager should ignore this * request.</p> * * <p>If the GSSManager implementation does not support an SPI with a * pluggable provider architecture it should throw a GSSException with * the status code {@link GSSException#UNAVAILABLE} to indicate that the * operation is unavailable.</p> * * @param p The provider instance that should be used whenever * support is needed for <i>mech</i>. * @param mech The mechanism for which the provider is being set. * @throws GSSException If this service is unavailable. */ public abstract void addProviderAtEnd(Provider p, Oid mech) throws GSSException; /** * <p>This method is used to indicate to the GSSManager that the * application would like a particular provider to be used ahead of all * others when support is desired for the given mechanism. When a value * of null is used instead of an Oid for the mechanism, the GSSManager * must use the indicated provider ahead of all others no matter what * the mechanism is. Only when the indicated provider does not support * the needed mechanism should the GSSManager move on to a different * provider.</p> * * <p>Calling this method repeatedly preserves the older settings but * lowers them in preference thus forming an ordered list of provider * and Oid pairs that grows at the top.</p> * * <p>Calling addProviderAtFront with a null Oid will remove all previous * preferences that were set for this provider in the GSSManager * instance. Calling addProviderAtFront with a non-null Oid will remove * any previous preference that was set using this mechanism and this * provider together.</p> * * <p>If the GSSManager implementation does not support an SPI with a * pluggable provider architecture it should throw a GSSException with * the status code {@link GSSException#UNAVAILABLE} to indicate that the * operation is unavailable.</p> * * @param p The provider instance that should be used whenever * support is needed for <i>mech</i>. * @param mech The mechanism for which the provider is being set.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -