com.ibm.as400.security.auth

Class ProfileTokenCredential

  • All Implemented Interfaces:
    AS400BasicAuthenticationCredential, AS400SwappableCredential, java.io.Serializable


    public final class ProfileTokenCredential
    extends AS400Credential
    implements AS400BasicAuthenticationCredential
    The ProfileTokenCredential class represents an IBM i system profile token.

    A profile token provides a timed credential representing an authenticated system user profile and password. A profile token can be established in either a remote (not running on the target system) or local (running on the target system) context. Once created, it may be serialized or distributed as required by the application.

    When referenced from a running process on the associated IBM i system, a profile token can be used to modify or swap the thread identity and perform a specific task or tasks on behalf of the authenticated user. However, a profile token generated on one IBM i system cannot be used to swap thread identity on any other system.

    An application of this support would be in a single tier application running on the system when a designated operation must be run under the system authorities and permissions of a specific user profile. A profile token can be used to swap identity prior to performing the operation. Support is also provided to swap back to the original identity upon completion.

    Another application of this support might be in a two tier application, with authentication of a user profile and password being performed by a graphical user interface on the first tier (i.e. a PC) and work being performed for that user on the second tier (the IBM i system). By utilizing ProfileTokenCredentials, the application can avoid directly passing the user ID and password over the network. The profile token can be distributed as required to the program on the second tier, which can perform the swap() and run designated operations under the system authorities and permissions assigned to the user.

    Note: While inherently more secure than passing a user profile and password due to limited life span, profile tokens should still be considered sensitive information by the application and handled accordingly. Since the token represents an authenticated user and password, it could potentially be exploited by a hostile application to perform work on behalf of that user. It is ultimately the responsibility of the application to ensure that credentials are accessed in a secure manner.

    Profile tokens are only supported for IBM i systems at release V4R5M0 or greater.

    The following example demonstrates the use of a ProfileTokenCredential when run on the local IBM i system. (Note: swap() is an unsupported remote operation.)

      // Prepare to work with the local IBM i system.
       AS400 system = new AS400("localhost", "*CURRENT", "*CURRENT");
    
      // Create a single-use ProfileTokenCredential with a 60 second timeout.
      // A valid user ID and password must be substituted.
       ProfileTokenCredential pt = new ProfileTokenCredential();
       pt.setSystem(system);
       pt.setTimeoutInterval(60);
       pt.setTokenType(ProfileTokenCredential.TYPE_SINGLE_USE);
       pt.setTokenExtended("USERID", "PASSWORD");
    
      // Swap the thread identity, retrieving a credential to
      // later swap back to the original identity.
       AS400Credential cr = pt.swap(true);
    
      // Perform work under the swapped identity at this point.
      // Newly-connected AS400 objects will run under the new (swapped-to) identity.
       AS400 swapped = new AS400("localhost", "*CURRENT", "*CURRENT");
    
      // Swap back to the original thread identity.
       cr.swap();
    
      // Clean up the credentials.
       cr.destroy();
       pt.destroy();
     

    General restrictions:

    • Creating a token updates the last-used date for the associated user and group profiles.
    • Creating a token resets the 'signon attempts not valid' count to zero for the user profile.
    • If security-related events are being audited, creating a token adds an entry to the AUDJRN audit journal.
    • The maximum number of profile tokens that can be generated is approximately 2,000,000; after that, the space to store them is full. Message CPF4AAA is sent to the caller, and no more profile tokens can be generated until one is removed.
    • You cannot obtain a profile token for the following system-supplied user profiles:
      • QAUTPROF
      • QFNC
      • QNETSPLF
      • QSPLJOB
      • QDBSHR
      • QGATE
      • QNFSANON
      • QSYS
      • QDFTOWN
      • QLPAUTO
      • QRJE
      • QTCP
      • QDIRSRV
      • QLPINSTALL
      • QSNADS
      • QTFTP
      • QDOC
      • QMSF
      • QSPL
      • QTSTRQS
      • QDSNX

    Guidelines and restrictions for generating profile tokens based on a specified user profile name and password:

    • On level 10 systems, only the user ID is validated because no passwords are required.
    • If a provided password is not correct, the incorrect password count for the user profile is increased. (The QMAXSIGN system value contains the maximum number of incorrect attempts to sign on.)
    • If the QMAXSGNACN system value is set to disable user profiles, repeated attempts to validate an incorrect password disables the user ID. This keeps applications from methodically determining user passwords.
    • Considerations when specifying a password of *NOPWD or *NOPWDCHK:
      • To obtain a profile token for a profile that does not have a password, specify *NOPWD or *NOPWDCHK for the password parameter.
      • The user requesting the profile token must have *USE authority to the user profile.
      • *NOPWD is not allowed if the user profile name is the name of the currently running user profile.
      • If the password is *NOPWDCHK and the user requesting the profile token has *ALLOBJ and *SECADM special authorities, a profile token will be generated even when the status of the profile is disabled or its password is expired.
      • No profile token is created in the following situations:
        • The user profile is disabled and *NOPWDCHK is not specified for the password parameter, or *NOPWDCHK was specified but the user requesting the profile token does not have *ALLOBJ or *SECADM special authority.
        • The password is expired and *NOPWDCHK is not specified for the password parameter, or *NOPWDCHK was specified but the user requesting the profile token does not have *ALLOBJ or *SECADM special authority.
        • The password is *NONE, and *NOPWD or *NOPWDCHK is not specified for the password parameter.
    See Also:
    AS400Credential, Serialized Form
    • Field Detail

      • TYPE_SINGLE_USE

        public static final int TYPE_SINGLE_USE
        ID indicating a single use token.
        See Also:
        Constant Field Values
      • TYPE_MULTIPLE_USE_NON_RENEWABLE

        public static final int TYPE_MULTIPLE_USE_NON_RENEWABLE
        ID indicating a multiple use token that cannot be regenerated.
        See Also:
        Constant Field Values
      • TYPE_MULTIPLE_USE_RENEWABLE

        public static final int TYPE_MULTIPLE_USE_RENEWABLE
        ID indicating a multiple use token that can be regenerated.
        See Also:
        Constant Field Values
      • TOKEN_LENGTH

        public static final int TOKEN_LENGTH
        Indicates the length of a profile token (in bytes)
        See Also:
        Constant Field Values
      • PW_NOPWD

        public static final int PW_NOPWD
        Password special value indicating that the current password is not verified.

        The user requesting the profile token must have *USE authority to the user profile.

        This value is not allowed if the name of the currently running profile is specified for the user profile name parameter.

        See Also:
        Constant Field Values
      • PW_NOPWDCHK

        public static final int PW_NOPWDCHK
        Password special value indicating that a profile token can be generated for a profile that is disabled or has an expired password.

        The user requesting the profile token must have *USE authority to the user profile.

        If the profile is disabled, the user requesting the profile token must have *ALLOBJ and *SECADM special authorities to get a token.

        If the password is expired, the user requesting the profile token must have *ALLOBJ and *SECADM special authorities to get a token.

        If the requesting user does not have *ALLOBJ and *SECADM special authorities, then the request will be handled as if they had indicated *NOPWD.

        See Also:
        Constant Field Values
    • Constructor Detail

      • ProfileTokenCredential

        public ProfileTokenCredential()
        Constructs a ProfileTokenCredential object.

        The system and token must be set prior to accessing host information or taking action against the credential.

      • ProfileTokenCredential

        public ProfileTokenCredential(AS400 system,
                              byte[] token,
                              int tokenType,
                              int timeoutInterval)
        Constructs and initializes a ProfileTokenCredential object.

        The system, token, tokenType, and timeoutInterval properties are initialized to the specified values.

        This method allows a credential to be constructed based on an existing token (i.e. previously created using the QSYGENPT system API). It is the responsibility of the application to ensure the tokenType and timeoutInterval are consistent with the specified token value.

        Parameters:
        system - The system associated with the credential.
        token - The actual bytes for the token as it exists on the IBM i system.
        tokenType - The type of token provided. Possible types are defined as fields on this class:
        • TYPE_SINGLE_USE
        • TYPE_MULTIPLE_USE_NON_RENEWABLE
        • TYPE_MULTIPLE_USE_RENEWABLE
        timeoutInterval - The number of seconds to expiration, used as the default value when the token is refreshed (1-3600).
    >
    • Method Detail

      • equals

        public boolean equals(java.lang.Object o)
        Compares the specified Object with the credential for equality.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - Object to be compared for equality.
        Returns:
        true if equal; otherwise false.
      • getTimeoutInterval

        public int getTimeoutInterval()
        Returns the number of seconds to expiration assigned when the token was last initialized or refreshed.

        This value also provides the default value for subsequent refresh attempts.

        The default value is 3600 (1 hour).

        Returns:
        The number of seconds.
      • getToken

        public byte[] getToken()
        Returns the actual bytes for the token as it exists on the IBM i system.
        Returns:
        The token bytes; null if not set.
      • getTokenType

        public int getTokenType()
        Returns an integer indicating the type assigned when the token was last initialized or refreshed.

        This value also provides the default value for subsequent refresh attempts.

        The default is TYPE_SINGLE_USE.

        Returns:
        The type of token. Possible types are defined as fields on this class:
        • TYPE_SINGLE_USE
        • TYPE_MULTIPLE_USE_NON_RENEWABLE
        • TYPE_MULTIPLE_USE_RENEWABLE
      • superHashCode

        public int superHashCode()
        Returns the hashcode for the super class @E1A
        Returns:
        hashcode for super class
      • hashCode

        public int hashCode()
        Returns a hash code for this credential.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code for this credential.
      • initialize

        public void initialize(AS400BasicAuthenticationPrincipal principal,
                      java.lang.String password,
                      boolean isPrivate,
                      boolean isReusable,
                      boolean isRenewable,
                      int timeoutInterval)
                        throws java.lang.Exception
        Initializes and validates a credential for the local IBM i system.
        Specified by:
        initialize in interface AS400BasicAuthenticationCredential
        Parameters:
        principal - The principal identifying the authenticated user. If not an instance of AS400Principal, a corresponding UserProfilePrincipal is generated and assigned.
        password - The password for the authenticated user.
        isPrivate - Indicates whether the credential is considered private.
        isReusable - true if the credential can be used to swap thread identity multiple times; otherwise false.
        isRenewable - true if the validity period of the credential can be programmatically updated or extended; otherwise false.
        timeoutInterval - The number of seconds to expiration when the credential is initially created; ignored if the credential does not expire based on time.
        Throws:
        java.lang.Exception - If an exception occurs.
      • isRenewable

        public boolean isRenewable()
        Indicates if the credential can be refreshed.
        Overrides:
        isRenewable in class AS400Credential
        Returns:
        true if the validity period of the credential can be programmatically updated or extended using refresh(); otherwise false.
        See Also:
        refresh()
      • isReusable

        public boolean isReusable()
        Indicates if the credential can be used multiple times prior to expiration.
        Returns:
        true if the credential can be used to swap thread identity multiple times; otherwise false.
      • refresh

        public void refresh()
                     throws AS400SecurityException
        Updates or extends the validity period for the credential.

        Does nothing if the credential cannot be programmatically updated or extended.

        Otherwise, generates a new profile token based on the previously established token, type, and timeoutInterval.

        Overrides:
        refresh in class AS400Credential
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
      • refresh

        public void refresh(int type,
                   int timeoutInterval)
                     throws AS400SecurityException
        Updates or extends the validity period for the credential.

        Does nothing if the credential cannot be programmatically updated or extended.

        Otherwise, generates a new profile token based on the previously established token with the given type and timeoutInterval.

        If successful, the specified type and interval become the default values for future refresh attempts.

        This method is provided to handle cases where it is desirable to allow for a more restrictive type of token or a different timeout interval when a new token is generated during the refresh.

        Parameters:
        type - The type of token. Possible types are defined as fields on this class:
        • TYPE_SINGLE_USE
        • TYPE_MULTIPLE_USE_NON_RENEWABLE
        • TYPE_MULTIPLE_USE_RENEWABLE
        timeoutInterval - The number of seconds before expiration (1-3600).
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
        ExtendedIllegalArgumentException - If a parameter value is out of range.
      • setTimeoutInterval

        public void setTimeoutInterval(int seconds)
                                throws java.beans.PropertyVetoException
        Sets the number of seconds to expiration when the token is generated or refreshed.

        It is the application's responsibility to maintain consistency between explicitly set token values (those not generated from a user and password) and the tokenType and timeoutInterval.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        seconds - The number of seconds to expiration (1-3600).
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If the provided value is out of range.
        ExtendedIllegalStateException - If the property cannot be changed due to the current state.
      • setToken

        public void setToken(byte[] bytes)
                      throws java.beans.PropertyVetoException
        Sets the actual bytes for the token as it exists on the IBM i system.

        This method allows a credential to be constructed based on an existing token (i.e. previously created using the QSYGENPT system API). It is the responsibility of the application to ensure the tokenType and timeoutInterval are consistent with the specified token value.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        bytes - The token bytes.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If the provided value is not the correct length.
        ExtendedIllegalStateException - If the property cannot be changed due to the current state.
      • setToken

        public void setToken(AS400Principal principal,
                    java.lang.String password)
                      throws java.beans.PropertyVetoException,
                             AS400SecurityException
        Deprecated. As of V5R3, replaced by setTokenExtended(AS400Principal,String) for password strings or setToken(AS400Principal,int) for password special values.
        Sets the token bytes based on the provided principal and password.

        The system property must be set prior to invoking this method.

        If successful, this method results in a new token being created on the IBM i system. The new token is generated using the previously established tokenType and timeoutInterval settings.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        principal - The principal identifying the user profile for which the token is to be generated.
        password - The user profile password. The following special values are allowed:
        • *NOPWD - The password is not verified. This value is not allowed if the name of the currently running profile is specified for the name parameter. If specified, the user requesting the profile token must have *USE authority to the user profile.
        • *NOPWDCHK - The password is not verified. This value allows a profile token to be generated for a profile that is disabled or has an expired password. If disabled or expired, the user requesting the profile token must have *ALLOBJ and *SECADM special authority.
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If errors occur during parameter validation.
        ExtendedIllegalStateException - If the token cannot be initialized due to the current state.
      • setToken

        public void setToken(java.lang.String name,
                    java.lang.String password)
                      throws java.beans.PropertyVetoException,
                             AS400SecurityException
        Deprecated. As of V5R3, replaced by setTokenExtended(String,String) for password strings or setToken(String,int) for password special values.
        Sets the token bytes based on the provided user profile and password.

        The system property must be set prior to invoking this method.

        If successful, this method results in a new token being created on the IBM i system. The new token is generated using the previously established tokenType and timeoutInterval settings.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        name - The name of the user profile for which the token is to be generated.
        password - The user profile password. The following special values are allowed:
        • *NOPWD - The password is not verified. This value is not allowed if the name of the currently running profile is specified for the name parameter. If specified, the user requesting the profile token must have *USE authority to the user profile.
        • *NOPWDCHK - The password is not verified. This value allows a profile token to be generated for a profile that is disabled or has an expired password. If disabled or expired, the user requesting the profile token must have *ALLOBJ and *SECADM special authority.
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If errors occur during parameter validation.
        ExtendedIllegalStateException - If the token cannot be initialized due to the current state.
      • setToken

        public void setToken(AS400Principal principal,
                    int passwordSpecialValue)
                      throws java.beans.PropertyVetoException,
                             AS400SecurityException
        Sets the token bytes based on the provided principal and special value for a password.

        This method requires a special value to be specified for the user password parameter. If you need to validate a user password, see the setTokenExtended(AS400Principal, String).

        The system property must be set prior to invoking this method.

        If successful, this method results in a new token being created on the IBM i system. The new token is generated using the previously established tokenType and timeoutInterval settings.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        principal - The principal identifying the user profile for which the token is to be generated.
        passwordSpecialValue - The special value for the user profile password. The following special values are allowed:
        • PW_NOPWD - The password is not verified. This value is not allowed if the name of the currently running profile is specified for the name parameter. If specified, the user requesting the profile token must have *USE authority to the user profile.
        • PW_NOPWDCHK - The password is not verified. This value allows a profile token to be generated for a profile that is disabled or has an expired password. If specified, the user requesting the profile token must have *USE authority to the user profile. If disabled or expired, the user requesting the profile token must have *ALLOBJ and *SECADM special authority.
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If errors occur during parameter validation.
        ExtendedIllegalStateException - If the token cannot be initialized due to the current state.
      • setToken

        public void setToken(java.lang.String name,
                    int passwordSpecialValue)
                      throws java.beans.PropertyVetoException,
                             AS400SecurityException
        Sets the token bytes based on the provided user profile and special value for a password.

        This method requires a special value to be specified for the user password parameter. If you need to validate a user password, see the setTokenExtended(String, String).

        The system property must be set prior to invoking this method.

        If successful, this method results in a new token being created on the IBM i system. The new token is generated using the previously established tokenType and timeoutInterval settings.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        name - The name of the user profile for which the token is to be generated.
        passwordSpecialValue - The special value for the user profile password. The following special values are allowed:
        • PW_NOPWD - The password is not verified. This value is not allowed if the name of the currently running profile is specified for the name parameter. If specified, the user requesting the profile token must have *USE authority to the user profile.
        • PW_NOPWDCHK - The password is not verified. This value allows a profile token to be generated for a profile that is disabled or has an expired password. If specified, the user requesting the profile token must have *USE authority to the user profile. If disabled or expired, the user requesting the profile token must have *ALLOBJ and *SECADM special authority.
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If errors occur during parameter validation.
        ExtendedIllegalStateException - If the token cannot be initialized due to the current state.
      • setTokenExtended

        public void setTokenExtended(AS400Principal principal,
                            java.lang.String password)
                              throws java.beans.PropertyVetoException,
                                     AS400SecurityException
        Sets the token bytes based on the provided principal and password.

        The system property must be set prior to invoking this method.

        If successful, this method results in a new token being created on the IBM i system. The new token is generated using the previously established tokenType and timeoutInterval settings.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        principal - The principal identifying the user profile for which the token is to be generated.
        password - The user profile password.
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If errors occur during parameter validation.
        ExtendedIllegalStateException - If the token cannot be initialized due to the current state.
      • setTokenExtended

        public void setTokenExtended(java.lang.String name,
                            java.lang.String password)
                              throws java.beans.PropertyVetoException,
                                     AS400SecurityException
        Sets the token bytes based on the provided user profile and password.

        The system property must be set prior to invoking this method.

        If successful, this method results in a new token being created on the IBM i system. The new token is generated using the previously established tokenType and timeoutInterval settings.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        name - The name of the user profile for which the token is to be generated.
        password - The user profile password.
        Throws:
        AS400SecurityException - If an IBM i system security or authentication error occurs.
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If errors occur during parameter validation.
        ExtendedIllegalStateException - If the token cannot be initialized due to the current state.
      • setTokenType

        public void setTokenType(int type)
                          throws java.beans.PropertyVetoException
        Sets the type of token.

        It is the application's responsibility to maintain consistency between explicitly set token values (those not generated from a user and password) and the tokenType and timeoutInterval.

        This property cannot be changed once a request initiates a connection for the object to the IBM i system (for example, refresh).

        Parameters:
        type - The type of token. Possible types are defined as fields on this class:
        • TYPE_SINGLE_USE
        • TYPE_MULTIPLE_USE_NON_RENEWABLE
        • TYPE_MULTIPLE_USE_RENEWABLE
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
        ExtendedIllegalArgumentException - If the provided value is out of range.
        ExtendedIllegalStateException - If the property cannot be changed due to the current state.
      • toString

        public java.lang.String toString()
        Returns a string representation of the object
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the object.
      • preventRefresh

        public void preventRefresh()
                            throws java.lang.InterruptedException
        Block the thread to refresh profile token credential.
        Throws:
        java.lang.InterruptedException
      • allowRefresh

        public void allowRefresh()
        Notify the wait thread to refresh profile token credential.