Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.security.jgss/share/classes/org/ietf/jgss/GSSManager.java
41155 views
1
/*
2
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package org.ietf.jgss;
27
28
import java.security.Provider;
29
30
/**
31
* This class serves as a factory for other important
32
* GSS-API classes and also provides information about the mechanisms that
33
* are supported. It can create instances of classes
34
* implementing the following three GSS-API interfaces: {@link
35
* GSSName GSSName}, {@link GSSCredential GSSCredential}, and {@link
36
* GSSContext GSSContext}. It also has methods to query for the list
37
* of available mechanisms and the nametypes that each mechanism
38
* supports.<p>
39
*
40
* An instance of the default <code>GSSManager</code> subclass
41
* may be obtained through the static method {@link #getInstance()
42
* getInstance}, but applications are free to instantiate other subclasses
43
* of <code>GSSManager</code>. The default <code>GSSManager</code> instance
44
* will support the Kerberos v5 GSS-API mechanism in addition to any
45
* others. This mechanism is identified by the Oid "1.2.840.113554.1.2.2"
46
* and is defined in RFC 1964.<p>
47
*
48
* A subclass extending the <code>GSSManager</code> abstract class may be
49
* implemented as a modular provider based layer that utilizes some well
50
* known service provider specification. The <code>GSSManager</code> API
51
* allows the application to set provider preferences on
52
* such an implementation. These methods also allow the implementation to
53
* throw a well-defined exception in case provider based configuration is
54
* not supported. Applications that expect to be portable should be aware
55
* of this and recover cleanly by catching the exception.<p>
56
*
57
* It is envisioned that there will be three most common ways in which
58
* providers will be used:
59
* <ol>
60
* <li> The application does not care about what provider is used (the
61
* default case).
62
* <li> The application wants a particular provider to be used
63
* preferentially, either for a particular mechanism or all the
64
* time, irrespective of mechanism.
65
* <li> The application wants to use the locally configured providers
66
* as far as possible but if support is missing for one or more
67
* mechanisms then it wants to fall back on its own provider.
68
*</ol><p>
69
*
70
* The <code>GSSManager</code> class has two methods that enable these modes of
71
* usage: {@link #addProviderAtFront(Provider, Oid) addProviderAtFront} and
72
* {@link #addProviderAtEnd(Provider, Oid) addProviderAtEnd}. These methods
73
* have the effect of creating an ordered list of <i>&lt;provider,
74
* oid&gt;</i> pairs where each pair indicates a preference of provider
75
* for a given oid.<p>
76
*
77
* It is important to note that there are certain interactions
78
* between the different GSS-API objects that are created by a
79
* GSSManager, where the provider that is used for a particular mechanism
80
* might need to be consistent across all objects. For instance, if a
81
* GSSCredential contains elements from a provider <i>p</i> for a mechanism
82
* <i>m</i>, it should generally be passed in to a GSSContext that will use
83
* provider <i>p</i> for the mechanism <i>m</i>. A simple rule of thumb
84
* that will maximize portability is that objects created from different
85
* GSSManager's should not be mixed, and if possible, a different
86
* GSSManager instance should be created if the application wants to invoke
87
* the <code>addProviderAtFront</code> method on a GSSManager that has
88
* already created an object.<p>
89
*
90
* Here is some sample code showing how the GSSManager might be used:
91
* <pre>
92
* GSSManager manager = GSSManager.getInstance();
93
*
94
* Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2");
95
* Oid krb5PrincipalNameType = new Oid("1.2.840.113554.1.2.2.1");
96
*
97
* // Identify who the client wishes to be
98
* GSSName userName = manager.createName("duke", GSSName.NT_USER_NAME);
99
*
100
* // Identify the name of the server. This uses a Kerberos specific
101
* // name format.
102
* GSSName serverName = manager.createName("nfs/foo.sun.com",
103
* krb5PrincipalNameType);
104
*
105
* // Acquire credentials for the user
106
* GSSCredential userCreds = manager.createCredential(userName,
107
* GSSCredential.DEFAULT_LIFETIME,
108
* krb5Mechanism,
109
* GSSCredential.INITIATE_ONLY);
110
*
111
* // Instantiate and initialize a security context that will be
112
* // established with the server
113
* GSSContext context = manager.createContext(serverName,
114
* krb5Mechanism,
115
* userCreds,
116
* GSSContext.DEFAULT_LIFETIME);
117
* </pre><p>
118
*
119
* The server side might use the following variation of this source:
120
*
121
* <pre>
122
* // Acquire credentials for the server
123
* GSSCredential serverCreds = manager.createCredential(serverName,
124
* GSSCredential.DEFAULT_LIFETIME,
125
* krb5Mechanism,
126
* GSSCredential.ACCEPT_ONLY);
127
*
128
* // Instantiate and initialize a security context that will
129
* // wait for an establishment request token from the client
130
* GSSContext context = manager.createContext(serverCreds);
131
* </pre>
132
*
133
* @author Mayank Upadhyay
134
* @see GSSName
135
* @see GSSCredential
136
* @see GSSContext
137
* @since 1.4
138
*/
139
public abstract class GSSManager {
140
141
/**
142
* Constructor for subclasses to call.
143
*/
144
public GSSManager() {}
145
146
/**
147
* Returns the default GSSManager implementation.
148
*
149
* @return a GSSManager implementation
150
*/
151
public static GSSManager getInstance() {
152
return new sun.security.jgss.GSSManagerImpl();
153
}
154
155
/**
156
* Returns a list of mechanisms that are available to GSS-API callers
157
* through this GSSManager. The default GSSManager obtained from the
158
* {@link #getInstance() getInstance()} method includes the Oid
159
* "1.2.840.113554.1.2.2" in its list. This Oid identifies the Kerberos
160
* v5 GSS-API mechanism that is defined in RFC 1964.
161
*
162
* @return an array of Oid objects corresponding to the mechanisms that
163
* are available. A <code>null</code> value is returned when no
164
* mechanism are available (an example of this would be when mechanism
165
* are dynamically configured, and currently no mechanisms are
166
* installed).
167
*/
168
public abstract Oid[] getMechs();
169
170
/**
171
* Returns then name types supported by the indicated mechanism.<p>
172
*
173
* The default GSSManager instance includes support for the Kerberos v5
174
* mechanism. When this mechanism ("1.2.840.113554.1.2.2") is indicated,
175
* the returned list will contain at least the following nametypes:
176
* {@link GSSName#NT_HOSTBASED_SERVICE GSSName.NT_HOSTBASED_SERVICE},
177
* {@link GSSName#NT_EXPORT_NAME GSSName.NT_EXPORT_NAME}, and the
178
* Kerberos v5 specific Oid "1.2.840.113554.1.2.2.1". The namespace for
179
* the Oid "1.2.840.113554.1.2.2.1" is defined in RFC 1964.
180
*
181
* @return an array of Oid objects corresponding to the name types that
182
* the mechanism supports.
183
* @param mech the Oid of the mechanism to query
184
*
185
* @see #getMechsForName(Oid)
186
*
187
* @throws GSSException containing the following
188
* major error codes:
189
* {@link GSSException#BAD_MECH GSSException.BAD_MECH}
190
* {@link GSSException#FAILURE GSSException.FAILURE}
191
*/
192
public abstract Oid[] getNamesForMech(Oid mech)
193
throws GSSException;
194
195
/**
196
* Returns a list of mechanisms that support the indicated name type.<p>
197
*
198
* The Kerberos v5 mechanism ("1.2.840.113554.1.2.2") will always be
199
* returned in this list when the indicated nametype is one of
200
* {@link GSSName#NT_HOSTBASED_SERVICE GSSName.NT_HOSTBASED_SERVICE},
201
* {@link GSSName#NT_EXPORT_NAME GSSName.NT_EXPORT_NAME}, or
202
* "1.2.840.113554.1.2.2.1".
203
*
204
* @return an array of Oid objects corresponding to the mechanisms that
205
* support the specified name type. <code>null</code> is returned when no
206
* mechanisms are found to support the specified name type.
207
* @param nameType the Oid of the name type to look for
208
*
209
* @see #getNamesForMech(Oid)
210
*/
211
public abstract Oid[] getMechsForName(Oid nameType);
212
213
/**
214
* Factory method to convert a string name from the
215
* specified namespace to a GSSName object. In general, the
216
* <code>GSSName</code> object created will contain multiple
217
* representations of the name, one for each mechanism that is
218
* supported; two examples that are exceptions to this are when
219
* the namespace type parameter indicates NT_EXPORT_NAME or when the
220
* GSS-API implementation is not multi-mechanism. It is
221
* not recommended to use this method with a NT_EXPORT_NAME type because
222
* representing a previously exported name consisting of arbitrary bytes
223
* as a String might cause problems with character encoding schemes. In
224
* such cases it is recommended that the bytes be passed in directly to
225
* the overloaded form of this method {@link #createName(byte[],
226
* Oid) createName}.
227
*
228
* @param nameStr the string representing a printable form of the name to
229
* create.
230
* @param nameType the Oid specifying the namespace of the printable name
231
* supplied. <code>null</code> can be used to specify
232
* that a mechanism specific default printable syntax should
233
* be assumed by each mechanism that examines nameStr.
234
* It is not advisable to use the nametype NT_EXPORT_NAME with this
235
* method.
236
* @return a GSSName representing the indicated principal
237
*
238
* @see GSSName
239
* @see GSSName#NT_EXPORT_NAME
240
*
241
* @throws GSSException containing the following
242
* major error codes:
243
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
244
* {@link GSSException#BAD_NAME GSSException.BAD_NAME},
245
* {@link GSSException#BAD_MECH GSSException.BAD_MECH},
246
* {@link GSSException#FAILURE GSSException.FAILURE}
247
*/
248
public abstract GSSName createName(String nameStr, Oid nameType)
249
throws GSSException;
250
251
/**
252
* Factory method to convert a byte array containing a
253
* name from the specified namespace to a GSSName object. In general,
254
* the <code>GSSName</code> object created will contain multiple
255
* representations of the name, one for each mechanism that is
256
* supported; two examples that are exceptions to this are when the
257
* namespace type parameter indicates NT_EXPORT_NAME or when the
258
* GSS-API implementation is not multi-mechanism. The bytes that are
259
* passed in are interpreted by each underlying mechanism according to
260
* some encoding scheme of its choice for the given nametype.
261
*
262
* @param name the byte array containing the name to create
263
* @param nameType the Oid specifying the namespace of the name supplied
264
* in the byte array. <code>null</code> can be used to specify that a
265
* mechanism specific default syntax should be assumed by each mechanism
266
* that examines the byte array.
267
* @return a GSSName representing the indicated principal
268
*
269
* @see GSSName
270
* @see GSSName#NT_EXPORT_NAME
271
*
272
* @throws GSSException containing the following
273
* major error codes:
274
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
275
* {@link GSSException#BAD_NAME GSSException.BAD_NAME},
276
* {@link GSSException#BAD_MECH GSSException.BAD_MECH},
277
* {@link GSSException#FAILURE GSSException.FAILURE}
278
*/
279
public abstract GSSName createName(byte name[], Oid nameType)
280
throws GSSException;
281
282
/**
283
* Factory method to convert a string name from the
284
* specified namespace to a GSSName object and canonicalize it at the
285
* same time for a mechanism. In other words, this method is
286
* a utility that does the equivalent of two steps: the {@link
287
* #createName(String, Oid) createName} and then also the {@link
288
* GSSName#canonicalize(Oid) GSSName.canonicalize}.
289
*
290
* @param nameStr the string representing a printable form of the name to
291
* create.
292
* @param nameType the Oid specifying the namespace of the printable name
293
* supplied. <code>null</code> can be used to specify
294
* that a mechanism specific default printable syntax should
295
* be assumed by each mechanism that examines nameStr.
296
* It is not advisable to use the nametype NT_EXPORT_NAME with this
297
* method.
298
* @param mech Oid specifying the mechanism for which the name should be
299
* canonicalized
300
* @return a GSSName representing the indicated principal
301
*
302
* @see GSSName#canonicalize(Oid)
303
* @see GSSName#NT_EXPORT_NAME
304
*
305
* @throws GSSException containing the following
306
* major error codes:
307
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
308
* {@link GSSException#BAD_NAME GSSException.BAD_NAME},
309
* {@link GSSException#BAD_MECH GSSException.BAD_MECH},
310
* {@link GSSException#FAILURE GSSException.FAILURE}
311
*/
312
public abstract GSSName createName(String nameStr, Oid nameType,
313
Oid mech) throws GSSException;
314
315
/**
316
* Factory method to convert a byte array containing a
317
* name from the specified namespace to a GSSName object and canonicalize
318
* it at the same time for a mechanism. In other words, this method is a
319
* utility that does the equivalent of two steps: the {@link
320
* #createName(byte[], Oid) createName} and then also {@link
321
* GSSName#canonicalize(Oid) GSSName.canonicalize}.
322
*
323
* @param name the byte array containing the name to create
324
* @param nameType the Oid specifying the namespace of the name supplied
325
* in the byte array. <code>null</code> can be used to specify that a
326
* mechanism specific default syntax should be assumed by each mechanism
327
* that examines the byte array.
328
* @param mech Oid specifying the mechanism for which the name should be
329
* canonicalized
330
* @return a GSSName representing the indicated principal
331
*
332
* @see GSSName#canonicalize(Oid)
333
* @see GSSName#NT_EXPORT_NAME
334
*
335
* @throws GSSException containing the following
336
* major error codes:
337
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
338
* {@link GSSException#BAD_NAME GSSException.BAD_NAME},
339
* {@link GSSException#BAD_MECH GSSException.BAD_MECH},
340
* {@link GSSException#FAILURE GSSException.FAILURE}
341
*/
342
public abstract GSSName createName(byte name[], Oid nameType, Oid mech)
343
throws GSSException;
344
345
/**
346
* Factory method for acquiring default credentials. This will cause
347
* the GSS-API to use system specific defaults for the set of mechanisms,
348
* name, and lifetime.<p>
349
*
350
* GSS-API mechanism providers must impose a local access-control
351
* policy on callers to prevent unauthorized callers from acquiring
352
* credentials to which they are not entitled. The kinds of permissions
353
* needed by different mechanism providers will be documented on a
354
* per-mechanism basis. A failed permission check might cause a {@link
355
* java.lang.SecurityException SecurityException} to be thrown from
356
* this method.
357
*
358
* @param usage The intended usage for this credential object. The value
359
* of this parameter must be one of:
360
* {@link GSSCredential#INITIATE_AND_ACCEPT
361
* GSSCredential.INITIATE_AND_ACCEPT},
362
* {@link GSSCredential#ACCEPT_ONLY GSSCredential.ACCEPT_ONLY}, and
363
* {@link GSSCredential#INITIATE_ONLY GSSCredential.INITIATE_ONLY}.
364
* @return a GSSCredential of the requested type.
365
*
366
* @see GSSCredential
367
*
368
* @throws GSSException containing the following
369
* major error codes:
370
* {@link GSSException#BAD_MECH GSSException.BAD_MECH},
371
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
372
* {@link GSSException#BAD_NAME GSSException.BAD_NAME},
373
* {@link GSSException#CREDENTIALS_EXPIRED
374
* GSSException.CREDENTIALS_EXPIRED},
375
* {@link GSSException#NO_CRED GSSException.NO_CRED},
376
* {@link GSSException#FAILURE GSSException.FAILURE}
377
*/
378
public abstract GSSCredential createCredential (int usage)
379
throws GSSException;
380
381
/**
382
* Factory method for acquiring a single mechanism credential.<p>
383
*
384
* GSS-API mechanism providers must impose a local access-control
385
* policy on callers to prevent unauthorized callers from acquiring
386
* credentials to which they are not entitled. The kinds of permissions
387
* needed by different mechanism providers will be documented on a
388
* per-mechanism basis. A failed permission check might cause a {@link
389
* java.lang.SecurityException SecurityException} to be thrown from
390
* this method. <p>
391
*
392
* Non-default values for lifetime cannot always be honored by the
393
* underlying mechanisms, thus applications should be prepared to call
394
* {@link GSSCredential#getRemainingLifetime() getRemainingLifetime}
395
* on the returned credential.
396
*
397
* @param name the name of the principal for whom this credential is to be
398
* acquired. Use <code>null</code> to specify the default principal.
399
* @param lifetime The number of seconds that credentials should remain
400
* valid. Use {@link GSSCredential#INDEFINITE_LIFETIME
401
* GSSCredential.INDEFINITE_LIFETIME} to request that the credentials
402
* have the maximum permitted lifetime. Use {@link
403
* GSSCredential#DEFAULT_LIFETIME GSSCredential.DEFAULT_LIFETIME} to
404
* request default credential lifetime.
405
* @param mech the Oid of the desired mechanism. Use <code>(Oid) null
406
* </code> to request the default mechanism.
407
* @param usage The intended usage for this credential object. The value
408
* of this parameter must be one of:
409
* {@link GSSCredential#INITIATE_AND_ACCEPT
410
* GSSCredential.INITIATE_AND_ACCEPT},
411
* {@link GSSCredential#ACCEPT_ONLY GSSCredential.ACCEPT_ONLY}, and
412
* {@link GSSCredential#INITIATE_ONLY GSSCredential.INITIATE_ONLY}.
413
* @return a GSSCredential of the requested type.
414
*
415
* @see GSSCredential
416
*
417
* @throws GSSException containing the following
418
* major error codes:
419
* {@link GSSException#BAD_MECH GSSException.BAD_MECH},
420
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
421
* {@link GSSException#BAD_NAME GSSException.BAD_NAME},
422
* {@link GSSException#CREDENTIALS_EXPIRED
423
* GSSException.CREDENTIALS_EXPIRED},
424
* {@link GSSException#NO_CRED GSSException.NO_CRED},
425
* {@link GSSException#FAILURE GSSException.FAILURE}
426
*/
427
public abstract GSSCredential createCredential (GSSName name,
428
int lifetime, Oid mech, int usage)
429
throws GSSException;
430
431
/**
432
* Factory method for acquiring credentials over a set of
433
* mechanisms. This method attempts to acquire credentials for
434
* each of the mechanisms specified in the array called mechs. To
435
* determine the list of mechanisms for which the acquisition of
436
* credentials succeeded, the caller should use the {@link
437
* GSSCredential#getMechs() GSSCredential.getMechs} method.<p>
438
*
439
* GSS-API mechanism providers must impose a local access-control
440
* policy on callers to prevent unauthorized callers from acquiring
441
* credentials to which they are not entitled. The kinds of permissions
442
* needed by different mechanism providers will be documented on a
443
* per-mechanism basis. A failed permission check might cause a {@link
444
* java.lang.SecurityException SecurityException} to be thrown from
445
* this method.<p>
446
*
447
* Non-default values for lifetime cannot always be honored by the
448
* underlying mechanisms, thus applications should be prepared to call
449
* {@link GSSCredential#getRemainingLifetime() getRemainingLifetime}
450
* on the returned credential.
451
*
452
* @param name the name of the principal for whom this credential is to
453
* be acquired. Use <code>null</code> to specify the default
454
* principal.
455
* @param lifetime The number of seconds that credentials should remain
456
* valid. Use {@link GSSCredential#INDEFINITE_LIFETIME
457
* GSSCredential.INDEFINITE_LIFETIME} to request that the credentials
458
* have the maximum permitted lifetime. Use {@link
459
* GSSCredential#DEFAULT_LIFETIME GSSCredential.DEFAULT_LIFETIME} to
460
* request default credential lifetime.
461
* @param mechs an array of Oid's indicating the mechanisms over which
462
* the credential is to be acquired. Use <code>(Oid[]) null</code> for
463
* requesting a system specific default set of mechanisms.
464
* @param usage The intended usage for this credential object. The value
465
* of this parameter must be one of:
466
* {@link GSSCredential#INITIATE_AND_ACCEPT
467
* GSSCredential.INITIATE_AND_ACCEPT},
468
* {@link GSSCredential#ACCEPT_ONLY GSSCredential.ACCEPT_ONLY}, and
469
* {@link GSSCredential#INITIATE_ONLY GSSCredential.INITIATE_ONLY}.
470
* @return a GSSCredential of the requested type.
471
*
472
* @see GSSCredential
473
*
474
* @throws GSSException containing the following
475
* major error codes:
476
* {@link GSSException#BAD_MECH GSSException.BAD_MECH},
477
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
478
* {@link GSSException#BAD_NAME GSSException.BAD_NAME},
479
* {@link GSSException#CREDENTIALS_EXPIRED
480
* GSSException.CREDENTIALS_EXPIRED},
481
* {@link GSSException#NO_CRED GSSException.NO_CRED},
482
* {@link GSSException#FAILURE GSSException.FAILURE}
483
*/
484
public abstract GSSCredential createCredential(GSSName name,
485
int lifetime, Oid mechs[], int usage)
486
throws GSSException;
487
488
/**
489
* Factory method for creating a context on the initiator's
490
* side.
491
*
492
* Some mechanism providers might require that the caller be granted
493
* permission to initiate a security context. A failed permission check
494
* might cause a {@link java.lang.SecurityException SecurityException}
495
* to be thrown from this method.<p>
496
*
497
* Non-default values for lifetime cannot always be honored by the
498
* underlying mechanism, thus applications should be prepared to call
499
* {@link GSSContext#getLifetime() getLifetime} on the returned
500
* context.
501
*
502
* @param peer the name of the target peer.
503
* @param mech the Oid of the desired mechanism. Use <code>null</code>
504
* to request the default mechanism.
505
* @param myCred the credentials of the initiator. Use
506
* <code>null</code> to act as the default initiator principal.
507
* @param lifetime the lifetime, in seconds, requested for the
508
* context. Use {@link GSSContext#INDEFINITE_LIFETIME
509
* GSSContext.INDEFINITE_LIFETIME} to request that the context have the
510
* maximum permitted lifetime. Use {@link GSSContext#DEFAULT_LIFETIME
511
* GSSContext.DEFAULT_LIFETIME} to request a default lifetime for the
512
* context.
513
* @return an unestablished GSSContext
514
*
515
* @see GSSContext
516
*
517
* @throws GSSException containing the following
518
* major error codes:
519
* {@link GSSException#NO_CRED GSSException.NO_CRED}
520
* {@link GSSException#CREDENTIALS_EXPIRED
521
* GSSException.CREDENTIALS_EXPIRED}
522
* {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE}
523
* {@link GSSException#BAD_MECH GSSException.BAD_MECH}
524
* {@link GSSException#FAILURE GSSException.FAILURE}
525
*/
526
public abstract GSSContext createContext(GSSName peer, Oid mech,
527
GSSCredential myCred, int lifetime)
528
throws GSSException;
529
530
/**
531
* Factory method for creating a context on the acceptor' side. The
532
* context's properties will be determined from the input token supplied
533
* to the accept method.
534
*
535
* Some mechanism providers might require that the caller be granted
536
* permission to accept a security context. A failed permission check
537
* might cause a {@link java.lang.SecurityException SecurityException}
538
* to be thrown from this method.
539
*
540
* @param myCred the credentials for the acceptor. Use
541
* <code>null</code> to act as a default acceptor principal.
542
* @return an unestablished GSSContext
543
*
544
* @see GSSContext
545
*
546
* @throws GSSException containing the following
547
* major error codes:
548
* {@link GSSException#NO_CRED GSSException.NO_CRED}
549
* {@link GSSException#CREDENTIALS_EXPIRED
550
* GSSException.CREDENTIALS_EXPIRED}
551
* {@link GSSException#BAD_MECH GSSException.BAD_MECH}
552
* {@link GSSException#FAILURE GSSException.FAILURE}
553
*/
554
public abstract GSSContext createContext(GSSCredential myCred)
555
throws GSSException;
556
557
/**
558
* Factory method for creating a previously exported context. The
559
* context properties will be determined from the input token and
560
* cannot be modified through the set methods.<p>
561
*
562
* Implementations are not required to support the inter-process
563
* transfer of security contexts. Before exporting a context, calling
564
* the {@link GSSContext#isTransferable() GSSContext.isTransferable}
565
* will indicate if the context is transferable. Calling this method in
566
* an implementation that does not support it will result in a
567
* <code>GSSException</code> with the error
568
* code {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE}.
569
*
570
* Some mechanism providers might require that the caller be granted
571
* permission to initiate or accept a security context. A failed
572
* permission check might cause a {@link java.lang.SecurityException
573
* SecurityException} to be thrown from this method.
574
*
575
* @param interProcessToken the token previously emitted from the
576
* export method.
577
* @return the previously established GSSContext
578
*
579
* @see GSSContext
580
*
581
* @throws GSSException containing the following
582
* major error codes:
583
* {@link GSSException#NO_CONTEXT GSSException.NO_CONTEXT},
584
* {@link GSSException#DEFECTIVE_TOKEN GSSException.DEFECTIVE_TOKEN},
585
* {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE},
586
* {@link GSSException#UNAUTHORIZED GSSException.UNAUTHORIZED},
587
* {@link GSSException#FAILURE GSSException.FAILURE}
588
*/
589
public abstract GSSContext createContext(byte [] interProcessToken)
590
throws GSSException;
591
592
/**
593
* This method is used to indicate to the GSSManager that the
594
* application would like a particular provider to be used ahead of all
595
* others when support is desired for the given mechanism. When a value
596
* of null is used instead of an <code>Oid</code> for the mechanism,
597
* the GSSManager must use the indicated provider ahead of all others
598
* no matter what the mechanism is. Only when the indicated provider
599
* does not support the needed mechanism should the GSSManager move on
600
* to a different provider.<p>
601
*
602
* Calling this method repeatedly preserves the older settings but
603
* lowers them in preference thus forming an ordered list of provider
604
* and <code>Oid</code> pairs that grows at the top.<p>
605
*
606
* Calling addProviderAtFront with a null <code>Oid</code> will remove
607
* all previous preferences that were set for this provider in the
608
* GSSManager instance. Calling addProviderAtFront with a non-null
609
* <code>Oid</code> will remove any previous preference that was set
610
* using this mechanism and this provider together.<p>
611
*
612
* If the GSSManager implementation does not support an SPI with a
613
* pluggable provider architecture it should throw a GSSException with
614
* the status code GSSException.UNAVAILABLE to indicate that the
615
* operation is unavailable.<p>
616
*
617
* Suppose an application desired that the provider A always be checked
618
* first when any mechanism is needed, it would call:
619
* <pre>
620
* GSSManager mgr = GSSManager.getInstance();
621
* // mgr may at this point have its own pre-configured list
622
* // of provider preferences. The following will prepend to
623
* // any such list:
624
*
625
* mgr.addProviderAtFront(A, null);
626
* </pre>
627
* Now if it also desired that the mechanism of Oid m1 always be
628
* obtained from the provider B before the previously set A was checked,
629
* it would call:
630
* <pre>
631
* mgr.addProviderAtFront(B, m1);
632
* </pre>
633
* The GSSManager would then first check with B if m1 was needed. In
634
* case B did not provide support for m1, the GSSManager would continue
635
* on to check with A. If any mechanism m2 is needed where m2 is
636
* different from m1 then the GSSManager would skip B and check with A
637
* directly.<p>
638
*
639
* Suppose at a later time the following call is made to the same
640
* GSSManager instance:
641
* <pre>
642
* mgr.addProviderAtFront(B, null)
643
* </pre>
644
* then the previous setting with the pair (B, m1) is subsumed by this
645
* and should be removed. Effectively the list of preferences now
646
* becomes {(B, null), (A, null),
647
* ... //followed by the pre-configured list.<p>
648
*
649
* Please note, however, that the following call:
650
* <pre>
651
* mgr.addProviderAtFront(A, m3)
652
* </pre>
653
* does not subsume the previous setting of (A, null) and the list will
654
* effectively become {(A, m3), (B, null), (A, null), ...}
655
*
656
* @param p the provider instance that should be used whenever support
657
* is needed for mech.
658
* @param mech the mechanism for which the provider is being set
659
*
660
* @throws GSSException containing the following
661
* major error codes:
662
* {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE},
663
* {@link GSSException#FAILURE GSSException.FAILURE}
664
*/
665
public abstract void addProviderAtFront(Provider p, Oid mech)
666
throws GSSException;
667
668
/**
669
* This method is used to indicate to the GSSManager that the
670
* application would like a particular provider to be used if no other
671
* provider can be found that supports the given mechanism. When a value
672
* of null is used instead of an Oid for the mechanism, the GSSManager
673
* must use the indicated provider for any mechanism.<p>
674
*
675
* Calling this method repeatedly preserves the older settings but
676
* raises them above newer ones in preference thus forming an ordered
677
* list of providers and Oid pairs that grows at the bottom. Thus the
678
* older provider settings will be utilized first before this one is.<p>
679
*
680
* If there are any previously existing preferences that conflict with
681
* the preference being set here, then the GSSManager should ignore this
682
* request.<p>
683
*
684
* If the GSSManager implementation does not support an SPI with a
685
* pluggable provider architecture it should throw a GSSException with
686
* the status code GSSException.UNAVAILABLE to indicate that the
687
* operation is unavailable.<p>
688
*
689
* Suppose an application desired that when a mechanism of Oid m1 is
690
* needed the system default providers always be checked first, and only
691
* when they do not support m1 should a provider A be checked. It would
692
* then make the call:
693
* <pre>
694
* GSSManager mgr = GSSManager.getInstance();
695
* mgr.addProviderAtEnd(A, m1);
696
* </pre>
697
* Now, if it also desired that for all mechanisms the provider B be
698
* checked after all configured providers have been checked, it would
699
* then call:
700
* <pre>
701
* mgr.addProviderAtEnd(B, null);
702
* </pre>
703
* Effectively the list of preferences now becomes {..., (A, m1), (B,
704
* null)}.<p>
705
*
706
* Suppose at a later time the following call is made to the same
707
* GSSManager instance:
708
* <pre>
709
* mgr.addProviderAtEnd(B, m2)
710
* </pre>
711
* then the previous setting with the pair (B, null) subsumes this and
712
* therefore this request should be ignored. The same would happen if a
713
* request is made for the already existing pairs of (A, m1) or (B,
714
* null).<p>
715
*
716
* Please note, however, that the following call:
717
* <pre>
718
* mgr.addProviderAtEnd(A, null)
719
* </pre>
720
* is not subsumed by the previous setting of (A, m1) and the list will
721
* effectively become {..., (A, m1), (B, null), (A, null)}
722
*
723
* @param p the provider instance that should be used whenever support
724
* is needed for mech.
725
* @param mech the mechanism for which the provider is being set
726
*
727
* @throws GSSException containing the following
728
* major error codes:
729
* {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE},
730
* {@link GSSException#FAILURE GSSException.FAILURE}
731
*/
732
public abstract void addProviderAtEnd(Provider p, Oid mech)
733
throws GSSException;
734
}
735
736