jdk/src/share/classes/com/sun/security/jgss/ExtendedGSSContext.java
author weijun
Tue, 11 Aug 2009 12:20:32 +0800
changeset 3483 a16fce1820ef
parent 3482 4aaa66ce712d
child 4336 4c792c19266e
permissions -rw-r--r--
6821190: more InquireType values for ExtendedGSSContext Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     1
/*
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     4
 *
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    10
 *
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    15
 * accompanied this code).
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    16
 *
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    20
 *
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    23
 * have any questions.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    24
 */
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    25
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    26
package com.sun.security.jgss;
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    27
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    28
import org.ietf.jgss.*;
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    29
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    30
/**
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    31
 * The extended GSSContext interface for supporting additional
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    32
 * functionalities not defined by {@code org.ietf.jgss.GSSContext},
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    33
 * such as querying context-specific attributes.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    34
 */
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    35
public interface ExtendedGSSContext extends GSSContext {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    36
    /**
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    37
     * Return the mechanism-specific attribute associated with {@code type}.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    38
     * <br><br>
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    39
     * For each supported attribute type, the type for the output are
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    40
     * defined below.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    41
     * <ol>
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    42
     * <li>{@code KRB5_GET_TKT_FLAGS}:
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    43
     * the returned object is a boolean array for the service ticket flags,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    44
     * which is long enough to contain all true bits. This means if
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    45
     * the user wants to get the <em>n</em>'th bit but the length of the
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    46
     * returned array is less than <em>n</em>, it is regarded as false.
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    47
     * <li>{@code KRB5_GET_SESSION_KEY}:
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    48
     * the returned object is an instance of {@link java.security.Key},
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    49
     * which has the following properties:
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    50
     *    <ul>
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    51
     *    <li>Algorithm: enctype as a string, where
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    52
     *        enctype is defined in RFC 3961, section 8.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    53
     *    <li>Format: "RAW"
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    54
     *    <li>Encoded form: the raw key bytes, not in any ASN.1 encoding
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    55
     *    </ul>
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    56
     * <li>{@code KRB5_GET_AUTHZ_DATA}:
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    57
     * the returned object is an array of
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    58
     * {@link com.sun.security.jgss.AuthorizationDataEntry}, or null if the
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    59
     * optional field is missing in the service ticket.
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    60
     * <li>{@code KRB5_GET_AUTHTIME}:
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    61
     * the returned object is a String object in the standard KerberosTime
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    62
     * format defined in RFC 4120 5.2.3
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    63
     * </ol>
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    64
     *
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    65
     * If there is a security manager, an {@link InquireSecContextPermission}
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    66
     * with the name {@code type.mech} must be granted. Otherwise, this could
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    67
     * result in a {@link SecurityException}.<p>
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    68
     *
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    69
     * Example:
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    70
     * <pre>
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    71
     *      GSSContext ctxt = m.createContext(...)
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    72
     *      // Establishing the context
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    73
     *      if (ctxt instanceof ExtendedGSSContext) {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    74
     *          ExtendedGSSContext ex = (ExtendedGSSContext)ctxt;
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    75
     *          try {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    76
     *              Key key = (key)ex.inquireSecContext(
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    77
     *                      InquireType.KRB5_GET_SESSION_KEY);
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    78
     *              // read key info
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    79
     *          } catch (GSSException gsse) {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    80
     *              // deal with exception
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    81
     *          }
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    82
     *      }
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    83
     * </pre>
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    84
     * @param type the type of the attribute requested
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    85
     * @return the attribute, see the method documentation for details.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    86
     * @throws GSSException containing  the following
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    87
     * major error codes:
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    88
     *   {@link GSSException#BAD_MECH GSSException.BAD_MECH} if the mechanism
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    89
     *   does not support this method,
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    90
     *   {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE} if the
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    91
     *   type specified is not supported,
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    92
     *   {@link GSSException#NO_CONTEXT GSSException.NO_CONTEXT} if the
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    93
     *   security context is invalid,
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    94
     *   {@link GSSException#FAILURE GSSException.FAILURE} for other
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    95
     *   unspecified failures.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    96
     * @throws SecurityException if a security manager exists and a proper
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    97
     *   {@link InquireSecContextPermission} is not granted.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    98
     * @see InquireSecContextPermission
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
    99
     */
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
   100
    public Object inquireSecContext(InquireType type)
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
   101
            throws GSSException;
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents:
diff changeset
   102
}