0N/A/*
2362N/A * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage org.ietf.jgss;
0N/A
0N/A/**
0N/A * This interface encapsulates the GSS-API credentials for an entity. A
0N/A * credential contains all the necessary cryptographic information to
0N/A * enable the creation of a context on behalf of the entity that it
0N/A * represents. It may contain multiple, distinct, mechanism specific
0N/A * credential elements, each containing information for a specific
0N/A * security mechanism, but all referring to the same entity. A credential
0N/A * may be used to perform context initiation, acceptance, or both.<p>
0N/A *
0N/A * Credentials are instantiated using one of the
0N/A * <code>createCredential</code> methods in the {@link GSSManager
0N/A * GSSManager} class. GSS-API credential creation is not
0N/A * intended to provide a "login to the network" function, as such a
0N/A * function would involve the creation of new credentials rather than
0N/A * merely acquiring a handle to existing credentials. The
0N/A * <a href=package-summary.html#useSubjectCredsOnly>section on credential
0N/A * acquisition</a> in the package level description describes
0N/A * how existing credentials are acquired in the Java platform. GSS-API
0N/A * implementations must impose a local access-control policy on callers to
0N/A * prevent unauthorized callers from acquiring credentials to which they
0N/A * are not entitled. <p>
0N/A *
0N/A * Applications will create a credential object passing the desired
0N/A * parameters. The application can then use the query methods to obtain
0N/A * specific information about the instantiated credential object.
0N/A * When the credential is no longer needed, the application should call
0N/A * the {@link #dispose() dispose} method to release any resources held by
0N/A * the credential object and to destroy any cryptographically sensitive
0N/A * information.<p>
0N/A *
0N/A * This example code demonstrates the creation of a GSSCredential
0N/A * implementation for a specific entity, querying of its fields, and its
0N/A * release when it is no longer needed:<p>
0N/A * <pre>
0N/A * GSSManager manager = GSSManager.getInstance();
0N/A *
0N/A * // start by creating a name object for the entity
0N/A * GSSName name = manager.createName("myusername", GSSName.NT_USER_NAME);
0N/A *
0N/A * // now acquire credentials for the entity
0N/A * GSSCredential cred = manager.createCredential(name,
0N/A * GSSCredential.ACCEPT_ONLY);
0N/A *
0N/A * // display credential information - name, remaining lifetime,
0N/A * // and the mechanisms it has been acquired over
0N/A * System.out.println(cred.getName().toString());
0N/A * System.out.println(cred.getRemainingLifetime());
0N/A *
0N/A * Oid [] mechs = cred.getMechs();
0N/A * if (mechs != null) {
0N/A * for (int i = 0; i < mechs.length; i++)
0N/A * System.out.println(mechs[i].toString());
0N/A * }
0N/A *
0N/A * // release system resources held by the credential
0N/A * cred.dispose();
0N/A * </pre>
0N/A *
0N/A * @see GSSManager#createCredential(int)
0N/A * @see GSSManager#createCredential(GSSName, int, Oid, int)
0N/A * @see GSSManager#createCredential(GSSName, int, Oid[], int)
0N/A * @see #dispose()
0N/A *
0N/A * @author Mayank Upadhyay
0N/A * @since 1.4
0N/A */
0N/Apublic interface GSSCredential extends Cloneable{
0N/A
0N/A /**
0N/A * Credential usage flag requesting that it be usable
0N/A * for both context initiation and acceptance.
0N/A *
0N/A */
0N/A public static final int INITIATE_AND_ACCEPT = 0;
0N/A
0N/A
0N/A /**
0N/A * Credential usage flag requesting that it be usable
0N/A * for context initiation only.
0N/A *
0N/A */
0N/A public static final int INITIATE_ONLY = 1;
0N/A
0N/A
0N/A /**
0N/A * Credential usage flag requesting that it be usable
0N/A * for context acceptance only.
0N/A *
0N/A */
0N/A public static final int ACCEPT_ONLY = 2;
0N/A
0N/A
0N/A /**
0N/A * A lifetime constant representing the default credential lifetime. This
0N/A * value it set to 0.
0N/A */
0N/A public static final int DEFAULT_LIFETIME = 0;
0N/A
0N/A /**
0N/A * A lifetime constant representing indefinite credential lifetime.
0N/A * This value must is set to the maximum integer value in Java -
0N/A * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}.
0N/A */
0N/A public static final int INDEFINITE_LIFETIME = Integer.MAX_VALUE;
0N/A
0N/A /**
0N/A * Releases any sensitive information that the GSSCredential object may
0N/A * be containing. Applications should call this method as soon as the
0N/A * credential is no longer needed to minimize the time any sensitive
0N/A * information is maintained.
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public void dispose() throws GSSException;
0N/A
0N/A /**
0N/A * Retrieves the name of the entity that the credential asserts.
0N/A *
0N/A * @return a GSSName representing the entity
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public GSSName getName() throws GSSException;
0N/A
0N/A /**
0N/A * Retrieves a Mechanism Name of the entity that the credential
0N/A * asserts. This is equivalent to calling {@link
0N/A * GSSName#canonicalize(Oid) canonicalize} on the value returned by
0N/A * the other form of {@link #getName() getName}.
0N/A *
0N/A * @param mech the Oid of the mechanism for which the Mechanism Name
0N/A * should be returned.
0N/A * @return a GSSName representing the entity canonicalized for the
0N/A * desired mechanism
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public GSSName getName(Oid mech) throws GSSException;
0N/A
0N/A /**
0N/A * Returns the remaining lifetime in seconds for a credential. The
0N/A * remaining lifetime is the minimum lifetime amongst all of the underlying
0N/A * mechanism specific credential elements.
0N/A *
0N/A * @return the minimum remaining lifetime in seconds for this
0N/A * credential. A return value of {@link #INDEFINITE_LIFETIME
0N/A * INDEFINITE_LIFETIME} indicates that the credential does
0N/A * not expire. A return value of 0 indicates that the credential is
0N/A * already expired.
0N/A *
0N/A * @see #getRemainingInitLifetime(Oid)
0N/A * @see #getRemainingAcceptLifetime(Oid)
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public int getRemainingLifetime() throws GSSException;
0N/A
0N/A /**
0N/A * Returns the lifetime in seconds for the credential to remain capable
0N/A * of initiating security contexts using the specified mechanism. This
0N/A * method queries the initiator credential element that belongs to the
0N/A * specified mechanism.
0N/A *
0N/A * @return the number of seconds remaining in the life of this credential
0N/A * element. A return value of {@link #INDEFINITE_LIFETIME
0N/A * INDEFINITE_LIFETIME} indicates that the credential element does not
0N/A * expire. A return value of 0 indicates that the credential element is
0N/A * already expired.
0N/A *
0N/A * @param mech the Oid of the mechanism whose intiator credential element
0N/A * should be queried.
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public int getRemainingInitLifetime(Oid mech) throws GSSException;
0N/A
0N/A /**
0N/A * Returns the lifetime in seconds for the credential to remain capable
0N/A * of accepting security contexts using the specified mechanism. This
0N/A * method queries the acceptor credential element that belongs to the
0N/A * specified mechanism.
0N/A *
0N/A * @return the number of seconds remaining in the life of this credential
0N/A * element. A return value of {@link #INDEFINITE_LIFETIME
0N/A * INDEFINITE_LIFETIME} indicates that the credential element does not
0N/A * expire. A return value of 0 indicates that the credential element is
0N/A * already expired.
0N/A *
0N/A * @param mech the Oid of the mechanism whose acceptor credential element
0N/A * should be queried.
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public int getRemainingAcceptLifetime(Oid mech) throws GSSException;
0N/A
0N/A /**
0N/A * Returns the credential usage mode. In other words, it
0N/A * tells us if this credential can be used for initiating or accepting
0N/A * security contexts. It does not tell us which mechanism(s) has to be
0N/A * used in order to do so. It is expected that an application will allow
0N/A * the GSS-API to pick a default mechanism after calling this method.
0N/A *
0N/A * @return The return value will be one of {@link #INITIATE_ONLY
0N/A * INITIATE_ONLY}, {@link #ACCEPT_ONLY ACCEPT_ONLY}, and {@link
0N/A * #INITIATE_AND_ACCEPT INITIATE_AND_ACCEPT}.
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public int getUsage() throws GSSException;
0N/A
0N/A /**
0N/A * Returns the credential usage mode for a specific mechanism. In other
0N/A * words, it tells us if this credential can be used
0N/A * for initiating or accepting security contexts with a given underlying
0N/A * mechanism.
0N/A *
0N/A * @return The return value will be one of {@link #INITIATE_ONLY
0N/A * INITIATE_ONLY}, {@link #ACCEPT_ONLY ACCEPT_ONLY}, and {@link
0N/A * #INITIATE_AND_ACCEPT INITIATE_AND_ACCEPT}.
0N/A * @param mech the Oid of the mechanism whose credentials usage mode is
0N/A * to be determined.
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public int getUsage(Oid mech) throws GSSException;
0N/A
0N/A /**
0N/A * Returns a list of mechanisms supported by this credential. It does
0N/A * not tell us which ones can be used to initiate
0N/A * contexts and which ones can be used to accept contexts. The
0N/A * application must call the {@link #getUsage(Oid) getUsage} method with
0N/A * each of the returned Oid's to determine the possible modes of
0N/A * usage.
0N/A *
0N/A * @return an array of Oid's corresponding to the supported mechanisms.
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public Oid[] getMechs() throws GSSException;
0N/A
0N/A /**
0N/A * Adds a mechanism specific credential-element to an existing
0N/A * credential. This method allows the construction of credentials, one
0N/A * mechanism at a time.<p>
0N/A *
0N/A * This routine is envisioned to be used mainly by context acceptors
0N/A * during the creation of acceptor credentials which are to be used
0N/A * with a variety of clients using different security mechanisms.<p>
0N/A *
0N/A * This routine adds the new credential element "in-place". To add the
0N/A * element in a new credential, first call <code>clone</code> to obtain a
0N/A * copy of this credential, then call its <code>add</code> method.<p>
0N/A *
0N/A * As always, GSS-API implementations must impose a local access-control
0N/A * policy on callers to prevent unauthorized callers from acquiring
0N/A * credentials to which they are not entitled.
0N/A *
0N/A * Non-default values for initLifetime and acceptLifetime cannot always
0N/A * be honored by the underlying mechanisms, thus callers should be
0N/A * prepared to call {@link #getRemainingInitLifetime(Oid)
0N/A * getRemainingInitLifetime} and {@link #getRemainingAcceptLifetime(Oid)
0N/A * getRemainingAcceptLifetime} on the credential.
0N/A *
0N/A * @param name the name of the principal for whom this credential is to
0N/A * be acquired. Use <code>null</code> to specify the default
0N/A * principal.
0N/A * @param initLifetime the number of seconds that the credential element
0N/A * should remain valid for initiating of security contexts. Use {@link
0N/A * GSSCredential#INDEFINITE_LIFETIME GSSCredential.INDEFINITE_LIFETIME}
0N/A * to request that the credentials have the maximum permitted lifetime
0N/A * for this. Use {@link GSSCredential#DEFAULT_LIFETIME
0N/A * GSSCredential.DEFAULT_LIFETIME} to request default credential lifetime
0N/A * for this.
0N/A * @param acceptLifetime the number of seconds that the credential
0N/A * element should remain valid for accepting security contexts. Use {@link
0N/A * GSSCredential#INDEFINITE_LIFETIME GSSCredential.INDEFINITE_LIFETIME}
0N/A * to request that the credentials have the maximum permitted lifetime
0N/A * for this. Use {@link GSSCredential#DEFAULT_LIFETIME
0N/A * GSSCredential.DEFAULT_LIFETIME} to request default credential lifetime
0N/A * for this.
0N/A * @param mech the mechanism over which the credential is to be acquired.
0N/A * @param usage the usage mode that this credential
0N/A * element should add to the credential. The value
0N/A * of this parameter must be one of:
0N/A * {@link #INITIATE_AND_ACCEPT INITIATE_AND_ACCEPT},
0N/A * {@link #ACCEPT_ONLY ACCEPT_ONLY}, and
0N/A * {@link #INITIATE_ONLY INITIATE_ONLY}.
0N/A *
0N/A * @throws GSSException containing the following
0N/A * major error codes:
0N/A * {@link GSSException#DUPLICATE_ELEMENT
0N/A * GSSException.DUPLICATE_ELEMENT},
0N/A * {@link GSSException#BAD_MECH GSSException.BAD_MECH},
0N/A * {@link GSSException#BAD_NAMETYPE GSSException.BAD_NAMETYPE},
0N/A * {@link GSSException#NO_CRED GSSException.NO_CRED},
0N/A * {@link GSSException#CREDENTIALS_EXPIRED
0N/A * GSSException.CREDENTIALS_EXPIRED},
0N/A * {@link GSSException#FAILURE GSSException.FAILURE}
0N/A */
0N/A public void add(GSSName name, int initLifetime, int acceptLifetime,
0N/A Oid mech, int usage) throws GSSException;
0N/A
0N/A /**
0N/A * Tests if this GSSCredential asserts the same entity as the supplied
0N/A * object. The two credentials must be acquired over the same
0N/A * mechanisms and must refer to the same principal.
0N/A *
0N/A * @return <code>true</code> if the two GSSCredentials assert the same
0N/A * entity; <code>false</code> otherwise.
0N/A * @param another another GSSCredential for comparison to this one
0N/A */
0N/A public boolean equals(Object another);
0N/A
0N/A /**
0N/A * Returns a hashcode value for this GSSCredential.
0N/A *
0N/A * @return a hashCode value
0N/A */
0N/A public int hashCode();
0N/A
0N/A}