Class GSSCredential


  • public class GSSCredential
    extends java.lang.Object
    This class manages GSS-API credentials and their associated operations. A credential contains all the necessary cryptographic information to enable the creation of a context on behalf of the entity that it represents. It may contain multiple distinct mechanism specific credential elements, each containing mechanism specific information, and all referring to the same entity.

    A credential may be used to perform context initiation, acceptance, or both.

    RFC 2078
    This class represents the credential management GSS-API calls, which are:
    • gs_acquire_cred
    • gss_release_cred
    • gss_inquire_cred
    • gss_add_cred
    • gss_inquire_cred_by_mech
    The gss_inquire_cred and gss_inquire_cred_by_mech calls have been distributed over several property querying methods each returning specific GSSCredential information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ACCEPT_ONLY
      Credential usage flag requesting that it be able to be used for context acceptance only.
      static int INDEFINITE
      Indefinite lifetime for a credential.
      static int INITIATE_AND_ACCEPT
      Credential usage flag requesting that it be able to be used for both context initiation and acceptance.
      static int INITIATE_ONLY
      Credential usage flag requesting that it be able to be used for context initiation only.
    • Constructor Summary

      Constructors 
      Constructor Description
      GSSCredential​(int usage)
      Constructor for default credentials.
      GSSCredential​(GSSName aName, int usage)
      Constructor for default mechanism credential.
      GSSCredential​(GSSName aName, int lifetime, Oid[] mechs, int usage)
      Constructor for a credential over a set of mechanisms.
      GSSCredential​(GSSName aName, int lifetime, Oid mechOid, int usage)
      Constructor for a single mechanism credential.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(GSSName aName, int initLifetime, int acceptLifetime, Oid mech, int usage)
      This method enables the construction of credentials one mechanism at a time.
      void dispose()
      Used to dispose of any sensitive information that the GSSCredential may be containing.
      boolean equals​(java.lang.Object another)
      Tests if this GSSCredential refers to the same entity as the supplied object.
      GSSName getGSSName()
      Retrieves the name of the entity that the credential has been acquired for.
      GSSName getGSSName​(Oid mechOID)
      Queries the selected mechanism for the principal name of the credential.
      Oid[] getMechs()
      Returns the mechanism oids over which the credential has been acquired.
      int getRemainingAcceptLifetime​(Oid mech)
      Returns the remaining lifetime in seconds for the credential to remain capable of accepting security context under the specified mechanism.
      int getRemainingInitLifetime​(Oid mech)
      Returns the remaining lifetime in seconds for the credential to remain capable of initiating security context under the specified mechanism.
      int getRemainingLifetime()
      Obtains the remaining lifetime for a credential.
      int getUsage()
      Retrieve the credential usage flag, which is one of INITIATE_ONLY, ACCEPT_ONLY, INITIATE_AND_ACCEPT.
      int getUsage​(Oid mechOID)
      Retrieve the credential usage flag, which is one of INITIATE_ONLY, ACCEPT_ONLY, INITIATE_AND_ACCEPT, for a specific credential mechanism.
      java.lang.String toString()
      Debugging aid.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • INITIATE_AND_ACCEPT

        public static final int INITIATE_AND_ACCEPT
        Credential usage flag requesting that it be able to be used for both context initiation and acceptance.
        See Also:
        Constant Field Values
      • INITIATE_ONLY

        public static final int INITIATE_ONLY
        Credential usage flag requesting that it be able to be used for context initiation only.
        See Also:
        Constant Field Values
      • ACCEPT_ONLY

        public static final int ACCEPT_ONLY
        Credential usage flag requesting that it be able to be used for context acceptance only.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GSSCredential

        public GSSCredential​(int usage)
                      throws GSSException
        Constructor for default credentials. This will use the default mechanism, default mechanism name, and an INDEFINITE lifetime.
        RFC 2078
        equivalent to gss_acquire_cred
        Parameters:
        usage - - the intended usage for this credential; this must be one of the constants defined in this class.
        Throws:
        GSSException - with possible major code of FAILURE
      • GSSCredential

        public GSSCredential​(GSSName aName,
                             int usage)
                      throws GSSException
        Constructor for default mechanism credential. Uses default mechanism and INDEFINITE lifetime.
        RFC 2078
        equivalent to gss_acquire_cred
        Parameters:
        aName - - name of the principal for whom this credential is to be acquired
        usage - - the intended usage for this credential; this must be one of the constants defined in this class
        Throws:
        GSSException - with possible major codes of FAILURE and BAD_NAME
      • GSSCredential

        public GSSCredential​(GSSName aName,
                             int lifetime,
                             Oid mechOid,
                             int usage)
                      throws GSSException
        Constructor for a single mechanism credential. null values can be specified for name and mechanism to obtain system specific defaults.
        RFC 2078
        equivalent to gss_acquire_cred
        Parameters:
        aName - - name of the principal for whom this credential is to be acquired; use null for system specific default principal
        lifetime - - the duration of this credential
        mechOid - - mechanism over which this credential is to be acquired
        usage - - the intended usage for this credential; this must be one of the constants defined in this class
        Throws:
        GSSException - with possible major codes of FAILURE, BAD_MECH, and BAD_NAME
      • GSSCredential

        public GSSCredential​(GSSName aName,
                             int lifetime,
                             Oid[] mechs,
                             int usage)
                      throws GSSException
        Constructor for a credential over a set of mechanisms. Acquires credentials for each of the mechanisms specified in mechs array. null value can be used for Name to obtain system specific default. To determine for which mechanisms acquiring of the credential was successful use the getMechs method. Note that this call is equivalent to creating a single mechanism credential and using addCred to extend the credential over other mechanisms.
        RFC 2078
        equivalent to gss_acquire_cred
        Parameters:
        aName - - name of the principal for whom this credential is to be acquired; use null for system specific default principal
        lifetime - - the desired duration of this credential
        mechs - - mechanisms over which this credential is to be acquired
        usage - - the intended usage for this credential; this must be one of the constants defined in this class
        Throws:
        GSSException - with possible major codes of FAILURE, BAD_MECH, and BAD_NAME
    • Method Detail

      • dispose

        public void dispose()
                     throws GSSException
        Used to dispose of any sensitive information that the GSSCredential may be containing. Should be called as soon as the credential is no longer needed to minimize the time sensitive information is maintained.
        RFC 2078
        equivalent to gss_release_cred
        Throws:
        GSSException - with possible major code of FAILURE
      • getGSSName

        public GSSName getGSSName()
                           throws GSSException
        Retrieves the name of the entity that the credential has been acquired for.
        RFC 2078
        equivalent to obtaining the cred_name parameter from gss_inquire_cred
        Returns:
        GSSName for the credential's principal
        Throws:
        GSSException - with possible major codes of FAILURE, NO_CRED, DEFECTIVE_CREDENTIAL, CREDENTIAL_EXPIRED
      • getGSSName

        public GSSName getGSSName​(Oid mechOID)
                           throws GSSException
        Queries the selected mechanism for the principal name of the credential. The mechanism must be one of the mechanisms over which the credential is acquired.
        RFC 2078
        equivalent to obtaining the cred_name parameter from gss_inquire_cred_by_mech
        Parameters:
        mechOID - the credential mechanism to be queried
        Throws:
        GSSException - with possible major codes of NO_CRED, DEFECTIVE_CREDENTIAL, CREDENTIALS_EXPIRED, FAILURE and BAD_MECH
      • getRemainingLifetime

        public int getRemainingLifetime()
                                 throws GSSException
        Obtains the remaining lifetime for a credential. The remaining lifetime is the minimum lifetime for any of the credential elements. Return of 0 indicates the credential is already expired.
        RFC 2078
        equivalent to lifetime parameter in gss_inquire_cred
        Returns:
        lifetime in seconds
        Throws:
        GSSException - with possible major codes of NO_CRED, DEFECTIVE_CREDENTIAL, FAILURE.
      • getRemainingInitLifetime

        public int getRemainingInitLifetime​(Oid mech)
                                     throws GSSException
        Returns the remaining lifetime in seconds for the credential to remain capable of initiating security context under the specified mechanism. Return of 0 indicates that the credential is already expired.
        RFC 2078
        equivalent to lifetime_init parameter in gss_inquire_cred_by_mech
        Parameters:
        mech - Oid for the credential mechanism to be queried
        Returns:
        the remaining initiation lifetime in seconds
        Throws:
        GSSException - with possible major codes of NO_CRED, DEFECTIVE_CREDENTIAL, FAILURE and BAD_MECH
      • getRemainingAcceptLifetime

        public int getRemainingAcceptLifetime​(Oid mech)
                                       throws GSSException
        Returns the remaining lifetime in seconds for the credential to remain capable of accepting security context under the specified mechanism. Return of 0 indicates that the credential is already expired.
        RFC 2078
        equivalent to lifetime_accept parameter in gss_inquire_cred_by_mech
        Parameters:
        mech - Oid for the credential mechanism to be queried
        Returns:
        the remaining acceptance lifetime in seconds
        Throws:
        GSSException - with possible major codes of NO_CRED, DEFECTIVE_CREDENTIAL, FAILURE and BAD_MECH
      • getUsage

        public int getUsage()
                     throws GSSException
        Retrieve the credential usage flag, which is one of INITIATE_ONLY, ACCEPT_ONLY, INITIATE_AND_ACCEPT.
        RFC 2078
        equivalent to usage parameter in gss_inquire_cred
        Returns:
        credential usage which will be only of INITIATE_ONLY, ACCEPT_ONLY, or INITIATE_AND_ACCEPT
        Throws:
        GSSException - with possible major codes of NO_CRED, DEFECTIVE_CREDENTIAL, CREDENTIALS_EXPIRED, FAILURE.
      • getUsage

        public int getUsage​(Oid mechOID)
                     throws GSSException
        Retrieve the credential usage flag, which is one of INITIATE_ONLY, ACCEPT_ONLY, INITIATE_AND_ACCEPT, for a specific credential mechanism.
        RFC 2078
        equivalent to usage parameter in gss_inquire_cred_by_mech
        Parameters:
        oid - for the credential mechanism to query
        Returns:
        credential usage which will be only of INITIATE_ONLY, ACCEPT_ONLY, or INITIATE_AND_ACCEPT
        Throws:
        GSSException - with possible major codes of NO_CRED, DEFECTIVE_CREDENTIAL, CREDENTIALS_EXPIRED, FAILURE.
      • getMechs

        public Oid[] getMechs()
                       throws GSSException
        Returns the mechanism oids over which the credential has been acquired.
        RFC 2078
        equivalent to mech_set parameter of gss_inquire_cred
        Returns:
        the array of mechanism oid's over which this credential has been acquired
        Throws:
        GSSException - with possible major codes of FAILURE, NO_CRED, DEFECTIVE_CREDENTIAL, CREDENTIAL_EXPIRED
      • add

        public void add​(GSSName aName,
                        int initLifetime,
                        int acceptLifetime,
                        Oid mech,
                        int usage)
                 throws GSSException
        This method enables the construction of credentials one mechanism at a time. A single mechanism credential will be added as specified by the mech parameter. This is equivalent to using the constructor for multiple mechanism but gives finer control and feedback.
        RFC 2078
        equivalent to gss_add_cred
        to obtain a new credential as in gss_add_cred, first call clone and then addCred
        Parameters:
        aName - - name of the principal for whom this credential is to be acquired; use null for system specific default principal
        initLifetime - - the desired duration of this credential initiation lifetime; value in seconds
        acceptLifetime - - the desired duration of this credential accept lifetime; value in seconds
        mechs - - mechanism over which this credential is to be acquired
        usage - - the intended usage for this credential; this must be one of the constants defined in this class
        Throws:
        GSSException - with possible major codes of DUPLICATE_ELEMENT, BAD_MECH, BAD_NAME, BAD_NAME, NO_CRED, or FAILURE.
      • equals

        public boolean equals​(java.lang.Object another)
        Tests if this GSSCredential refers to the same entity as the supplied object. The two GSSCredentials must be acquired over the same mechanisms.
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if the two GSSCredentials refer to the same entity; false otherwise.
      • toString

        public java.lang.String toString()
        Debugging aid. Returns string with information about this credential object.
        Overrides:
        toString in class java.lang.Object