Debian Codegraph @

ssl-proxies/src/main/java/org/gridforum/jgss/ExtendedGSSManager.java

raw
1 /*
2 * Copyright 1999-2010 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.gridforum.jgss;
16
17 import org.ietf.jgss.GSSManager;
18 import org.ietf.jgss.Oid;
19 import org.ietf.jgss.GSSCredential;
20 import org.ietf.jgss.GSSException;
21
22 /**
23 * Defines Java API for credential import extension as defined in the
24 * <a href="http://www.gridforum.org/security/gsi/draft-ggf-gss-extensions-07.pdf">GSS-API Extensions document</a>.
25 * Some of the functions might not specify all the parameters as in the document.
26 * <BR><BR>Notes:
27 * <UL>
28 * <LI>Protection key is currently not supported.</LI>
29 * </UL>
30 */
31 public abstract class ExtendedGSSManager extends GSSManager {
32
33 private static ExtendedGSSManager gssManager;
34
35 protected ExtendedGSSManager() {}
36
37 /**
38 * A factory method for creating a previously exported credential.
39 *
40 * @param buff
41 * The token emitted from the {@link ExtendedGSSCredential#export(int, Oid)
42 * ExtendedGSSCredential.export} method.
43 * @param option
44 * The import type. The import type must be the same as the
45 * option used to export the buffer.
46 * @param lifetime
47 * The number of seconds that credentials should remain valid. Use
48 * GSSCredential.INDEFINITE_LIFETIME to request that the credentials have
49 * the maximum permitted lifetime. Use GSSCredential.DEFAULT_LIFETIME to request
50 * default credential lifetime.
51 * @param mech
52 * The desired mechanism for the imported credential, may be null to indicate system default.
53 * @param usage
54 * The intended usage for this credential object. The value of this parameter must be one of:
55 * GSSCredential.INITIATE_AND_ACCEPT, GSSCredential.ACCEPT_ONLY, and GSSCredential.INITIATE_ONLY.
56 * @exception GSSException containing the following major error codes: <code>GSSException.BAD_MECH,
57 * GSSException.DEFECTIVE_TOKEN, GSSException.NO_CRED, GSSException.CREDENTIAL_EXPIRED,
58 * GSSException.FAILURE</code>
59 */
60 public abstract GSSCredential createCredential (byte[] buff,
61 int option,
62 int lifetime,
63 Oid mech,
64 int usage)
65 throws GSSException;
66
67 public synchronized static GSSManager getInstance() {
68 if (gssManager == null) {
69 String className = System.getProperty("org.globus.gsi.gssapi.provider");
70 if (className == null) {
71 className = "org.globus.gsi.gssapi.GlobusGSSManagerImpl";
72 }
73 try {
74 Class clazz = Class.forName(className);
75 if (!ExtendedGSSManager.class.isAssignableFrom(clazz)) {
76 throw new RuntimeException("Invalid ExtendedGSSManager provider class: '" +
77 className + "'");
78 }
79 gssManager = (ExtendedGSSManager)clazz.newInstance();
80 } catch (ClassNotFoundException e) {
81 throw new RuntimeException("Unable to load '" + className + "' class: " +
82 e.getMessage());
83 } catch (InstantiationException e) {
84 throw new RuntimeException("Unable to instantiate '" + className + "' class: " +
85 e.getMessage());
86 } catch (IllegalAccessException e) {
87 throw new RuntimeException("Unable to instantiate '" + className + "' class: " +
88 e.getMessage());
89 }
90 }
91 return gssManager;
92 }
93
94 }