com.ibm.as400.access

Class AS400

  • All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    SecureAS400


    public class AS400
    extends Object
    implements Serializable
    Represents the authentication information and a set of connections to the IBM i host servers.

    If running on IBM i or an older version of that operating system, the system name, user ID, and password do not need to be supplied. These values default to the local system. For the system name, the keyword localhost can be used to specify the local system. For the user ID and password, *CURRENT can be used.

    If running on another operating system, the system name, user ID, and password need to be supplied. If not supplied, the first 'open' request associated with this object will trigger a prompt to the workstation user. Subsequent opens associated with the same object will not prompt the workstation user. Keywords localhost and *CURRENT will not work when running on another operating system.

    For example:

        AS400 system = new AS400();
        system.connectService(AS400.DATAQUEUE);   // This causes a password prompt.
        ...
        system.connectService(AS400.FILE);        // This does not cause a prompt.
     
    See Also:
    Serialized Form
    • Field Detail

      • FILE

        public static final int FILE
        Constant indicating the File service.
        See Also:
        Constant Field Values
      • PRINT

        public static final int PRINT
        Constant indicating the Print service.
        See Also:
        Constant Field Values
      • COMMAND

        public static final int COMMAND
        Constant indicating the Command service.
        See Also:
        Constant Field Values
      • DATAQUEUE

        public static final int DATAQUEUE
        Constant indicating the Dataqueue service.
        See Also:
        Constant Field Values
      • DATABASE

        public static final int DATABASE
        Constant indicating the Database service.
        See Also:
        Constant Field Values
      • RECORDACCESS

        public static final int RECORDACCESS
        Constant indicating the Record Access service.
        See Also:
        Constant Field Values
      • CENTRAL

        public static final int CENTRAL
        Constant indicating the Central service.
        See Also:
        Constant Field Values
      • SIGNON

        public static final int SIGNON
        Constant indicating the Sign-on service.
        See Also:
        Constant Field Values
      • USE_PORT_MAPPER

        public static final int USE_PORT_MAPPER
        Special value indicating the service port should be retrieved from the port mapper server.
        See Also:
        Constant Field Values
      • AUTHENTICATION_SCHEME_PASSWORD

        public static final int AUTHENTICATION_SCHEME_PASSWORD
        Constant indicating the authentication scheme is password.
        See Also:
        Constant Field Values
      • AUTHENTICATION_SCHEME_GSS_TOKEN

        public static final int AUTHENTICATION_SCHEME_GSS_TOKEN
        Constant indicating the authentication scheme is GSS token.
        See Also:
        Constant Field Values
      • AUTHENTICATION_SCHEME_PROFILE_TOKEN

        public static final int AUTHENTICATION_SCHEME_PROFILE_TOKEN
        Constant indicating the authentication scheme is profile token.
        See Also:
        Constant Field Values
      • AUTHENTICATION_SCHEME_IDENTITY_TOKEN

        public static final int AUTHENTICATION_SCHEME_IDENTITY_TOKEN
        Constant indicating the authentication scheme is identity token.
        See Also:
        Constant Field Values
      • GSS_OPTION_MANDATORY

        public static final int GSS_OPTION_MANDATORY
        Constant indicating that the JGSS framework must be used when no password or authentication token is set. An object set to this option will not attempt to present a sign-on dialog or use the current user profile information. A failure to retrieve the GSS token will result in an exception returned to the user.
        See Also:
        Constant Field Values
      • GSS_OPTION_FALLBACK

        public static final int GSS_OPTION_FALLBACK
        Constant indicating that the JGSS framework will be attempted when no password or authentication token is set. An object set to this option will attempt to retrieve a GSS token, if that attempt fails, the object will present a sign-on dialog or use the current user profile information. This option is the default.
        See Also:
        Constant Field Values
      • GSS_OPTION_NONE

        public static final int GSS_OPTION_NONE
        Constant indicating that the JGSS framework will not be used when no password or authentication token is set. An object set to this option will only present a sign-on dialog or use the current user profile information.
        See Also:
        Constant Field Values
      • currentLib_

        public String currentLib_
      • librariesForThread_

        public String librariesForThread_
      • aspName

        public String aspName
      • bidiAS400Text

        public boolean bidiAS400Text
        Determines whether Bidi processing should occur in AS400Text.toBytes() method
    • Constructor Detail

      • AS400

        public AS400()
        Constructs an AS400 object.

        If running on IBM i, the target is the local system. This has the same effect as using localhost for the system name, *CURRENT for the user ID, and *CURRENT for the password.

        If running on another operating system, a sign-on prompt may be displayed. The user is then able to specify the system name, user ID, and password.

      • AS400

        public AS400(String systemName)
        Constructs an AS400 object. It uses the specified system name.

        If running on IBM i to another system or to itself, the user ID and password of the current job are used.

        If running on another operating system, the user may be prompted for the user ID and password if a default user has not been established for this system name.

        Parameters:
        systemName - The name of the IBM i system. Use localhost to access data locally.
      • AS400

        public AS400(String systemName,
             String userId)
        Constructs an AS400 object. It uses the specified system name and user ID. If the sign-on prompt is displayed, the user is able to specify the password. Note that the user ID may be overridden.
        Parameters:
        systemName - The name of the IBM i system. Use localhost to access data locally.
        userId - The user profile name to use to authenticate to the system. If running on IBM i, *CURRENT may be used to specify the current user ID.
      • AS400

        public AS400(String systemName,
             ProfileTokenCredential profileToken)
        Constructs an AS400 object. It uses the specified system name and profile token.
        Parameters:
        systemName - The name of the IBM i system. Use localhost to access data locally.
        profileToken - The profile token to use to authenticate to the system.
      • AS400

        public AS400(String systemName,
             ProfileTokenProvider tokenProvider)
        Constructs an AS400 object. The specified ProfileTokenProvider is used. The token refresh threshold is determined by the ProfileTokenProvider.
        Parameters:
        tokenProvider - The provider to use when a new profile token needs to be generated.
        See Also:
        AS400(String,ProfileTokenProvider,int)
      • AS400

        public AS400(String systemName,
             ProfileTokenProvider tokenProvider,
             int refreshThreshold)
        Constructs an AS400 object. The specified ProfileTokenProvider is used.
        Parameters:
        tokenProvider - The provider to use when a new profile token needs to be generated.
        refreshThreshold - The refresh threshold, in seconds, for the profile token. Used by the vault to manage the currency of the profile token to help ensure it remains current for an indefinite period of time.
        See Also:
        AS400(String,ProfileTokenProvider)
      • AS400

        public AS400(String systemName,
             String userId,
             String password)
        Constructs an AS400 object. It uses the specified system name, user ID, and password. No sign-on prompt is displayed unless the sign-on fails.
        Parameters:
        systemName - The name of the IBM i system. Use localhost to access data locally.
        userId - The user profile name to use to authenticate to the system. If running on IBM i, *CURRENT may be used to specify the current user ID.
        password - The user profile password to use to authenticate to the system. If running on IBM i, *CURRENT may be used to specify the current user ID.
      • AS400

        public AS400(String systemName,
             String userId,
             String password,
             String proxyServer)
        Constructs an AS400 object. It uses the specified system name, user ID, and password. No sign-on prompt is displayed unless the sign-on fails.
        Parameters:
        systemName - The name of the IBM i system. Use localhost to access data locally.
        userId - The user profile name to use to authenticate to the system. If running on IBM i, *CURRENT may be used to specify the current user ID.
        password - The user profile password to use to authenticate to the system. If running on IBM i, *CURRENT may be used to specify the current user ID.
        proxyServer - The name and port of the proxy server in the format serverName[:port]. If no port is specified, a default will be used.
      • AS400

        public AS400(AS400 system)
        Constructs an AS400 object. It uses the same system name and user ID. This does not create a clone. The new object has the same behavior, but results in a new set of socket connections.
        Parameters:
        system - A previously instantiated AS400 object.

    • Method Detail

      • addConnectionListener

        public void addConnectionListener(ConnectionListener listener)
        Adds a listener to be notified when a connection event occurs.
        Parameters:
        listener - The listener object.
      • addPasswordCacheEntry

        public static void addPasswordCacheEntry(String systemName,
                                 String userId,
                                 String password)
                                          throws AS400SecurityException,
                                                 IOException
        Validates the user ID and password, and if successful, adds the information to the password cache.
        Parameters:
        systemName - The name of the IBM i system.
        userId - The user profile name.
        password - The user profile password.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • addPasswordCacheEntry

        public static void addPasswordCacheEntry(String systemName,
                                 String userId,
                                 String password,
                                 String proxyServer)
                                          throws AS400SecurityException,
                                                 IOException
        Validates the user ID and password, and if successful, adds the information to the password cache.
        Parameters:
        systemName - The name of the IBM i system.
        userId - The user profile name.
        password - The user profile password.
        proxyServer - The name and port of the proxy server in the format serverName[:port]. If no port is specified, a default will be used.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • addPropertyChangeListener

        public void addPropertyChangeListener(PropertyChangeListener listener)
        Adds a listener to be notified when the value of any property is changed.
        Parameters:
        listener - The listener object.
      • addVetoableChangeListener

        public void addVetoableChangeListener(VetoableChangeListener listener)
        Adds a listener to be notified when the value of any constrained property is changed. The vetoableChange method will be called.
        Parameters:
        listener - The listener object.
      • arePropertiesFrozen

        public boolean arePropertiesFrozen()
        Indicates if properties are frozen. If this is true, property changes should not be made. Properties are not the same thing as attributes. Properties are basic pieces of information which must be set to make the object usable, such as the system name, user ID or other properties that identify the resource.
        Returns:
        true if properties are frozen, false otherwise.
      • authenticate

        public boolean authenticate(String userId,
                           String password)
                             throws AS400SecurityException,
                                    IOException
        Authenticates the user profile name and user profile password.

        This method is functionally equivalent to the validateSignon() method. It does not alter the user profile assigned to this object, impact the status of existing connections, or otherwise impact the user and authorities on which the application is running.

        The system name needs to be set prior to calling this method.

        Note: Providing an incorrect password increments the number of failed sign-on attempts for the user profile, and can result in the profile being disabled.

        Note: This will return true if the information is successfully validated. An unsuccessful validation will cause an exception to be thrown, false is never returned.

        Parameters:
        userId - The user profile name.
        password - The user profile password.
        Returns:
        true if successful.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • canUseNativeOptimizations

        public boolean canUseNativeOptimizations()
        Indicates if this AS400 object is enabled to exploit Toolbox native optimizations. This requires that the native optimization classes are available on the classpath, and this AS400 object represents the local system and is configured to allow the native optimizations to be used. Note: If the authentication scheme is other than AUTHENTICATION_SCHEME_PASSWORD, native optimizations will not be used.
        Returns:
        true if the native optimizations can be used; false otherwise.
        See Also:
        isLocal(), isMustUseSockets(), getAuthenticationScheme()
      • changePassword

        public void changePassword(String oldPassword,
                          String newPassword)
                            throws AS400SecurityException,
                                   IOException
        Changes the user profile password. The system name and user profile name need to be set prior to calling this method.
        Parameters:
        oldPassword - The old user profile password.
        newPassword - The new user profile password.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • clearPasswordCache

        public static void clearPasswordCache()
        Clears the password cache for all systems within this Java virtual machine.
      • clearPasswordCache

        public static void clearPasswordCache(String systemName)
        Clears all the passwords that are cached for the given system name within this Java virtual machine.
        Parameters:
        systemName - The name of the IBM i system.
      • connectService

        public void connectService(int service)
                            throws AS400SecurityException,
                                   IOException
        Connects to a service. Security is validated and a connection is established.

        Services typically connect implicitly; therefore, this method does not have to be called to use a service. This method can be used to control when the connection is established.

        Parameters:
        service - The name of the service. Valid services are:
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • connectToPort

        public Socket connectToPort(int port)
                             throws AS400SecurityException,
                                    IOException
        Connects to a port on the server, via DHCP. Security is validated and a connection is established.
        Parameters:
        port - The port number to connect to.
        Returns:
        A Socket object representing the connection.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • connectToPort

        public Socket connectToPort(int port,
                           boolean forceNonLocalhost)
                             throws AS400SecurityException,
                                    IOException
        Connects to a port on the server, via DHCP. Security is validated and a connection is established.
        Parameters:
        port - The port number to connect to.
        forceNonLocalhost - whether to use localhost when connect to the port if running on as400
        Returns:
        A Socket object representing the connection.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • disconnectAllServices

        public void disconnectAllServices()
        Disconnects all services. All socket connections associated with this object will be closed. The signon information is not changed, and connection properties remain frozen.
        See Also:
        resetAllServices()
      • disconnectService

        public void disconnectService(int service)
        Disconnects the service. All socket connections associated with this service and this object will be closed.
        Parameters:
        service - The name of the service. Valid services are:
      • generateProfileToken

        public ProfileTokenCredential generateProfileToken(String userIdentity,
                                                  int tokenType,
                                                  int timeoutInterval)
                                                    throws AS400SecurityException,
                                                           IOException
        Generates a profile token on behalf of the provided user identity. This user identity must be associated with a user profile via EIM.

        Invoking this method does not change the user ID and password assigned to the system or otherwise modify the user or authorities under which the application is running. The profile associated with this system object must have enough authority to generate an authentication token for another user.

        This function is only supported on i5/OS V5R3M0 or greater.

        Parameters:
        userIdentity - The LDAP distinguished name.
        tokenType - The type of profile token to create. Possible types are defined as fields on the ProfileTokenCredential class:
        timeoutInterval - The number of seconds to expiration when the token is created (1-3600).
        Returns:
        A ProfileTokenCredential representing the provided user identity.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • generateVRM

        public static int generateVRM(int version,
                      int release,
                      int modification)
        Generates a VRM from a version, release, and modification. This can then be used to compare against the VRM returned by getVRM().
        Parameters:
        version - The version.
        release - The release.
        modification - The modification level.
        Returns:
        The generated VRM.
      • getCcsid

        public int getCcsid()
        Returns the CCSID for this object. The CCSID returned either is the one retrieved based on the user profile or is set by the setCcsid() method.
        Returns:
        The CCSID in use for this object.
      • getDDMRDB

        public String getDDMRDB()
        Returns the relational database name (RDB name) used for record-level access (DDM) connections. The RDB name corresponds to the independent auxiliary storage pool (IASP) that is being used.
        Returns:
        The name of the IASP or RDB that is in use by this object's RECORDACCESS service, or null if the IASP used will be the default system pool (*SYSBAS).
        See Also:
        setDDMRDB(java.lang.String)
      • getDefaultUser

        public static String getDefaultUser(String systemName)
        Returns the default user ID for this system name. This user ID is used to connect if a user ID was not used to construct the object.
        Parameters:
        systemName - The name of the IBM i system.
        Returns:
        The default user ID for this system. A null is returned if there is not a default user.
      • getGSSName

        public String getGSSName()
        Returns the GSS name string. This method will only return the information provided on the setGSSName() method.
        Returns:
        The GSS name string, or an empty string ("") if not set.
      • getJobs

        public Job[] getJobs(int service)
        Returns an array of Job objects representing the jobs to which this object is connected. This information is only available when connecting to i5/OS V5R2M0 and later systems. The array will be of length zero if no connections are currently active.
        Parameters:
        service - The name of the service. Valid services are:
        Returns:
        The array of job objects.
      • getLocale

        public Locale getLocale()
        Returns the Locale associated with this system object. The Locale may have been set with the setLocale() method, or it may be the default Locale for the client environment. Unless specifically overridden, this Locale is used to set the National Language Version (NLV) on the system. Only the COMMAND, PRINT, and DATABASE services accept an NLV.
        Returns:
        The Locale object.
      • getModification

        public int getModification()
                            throws AS400SecurityException,
                                   IOException
        Returns the modification level of the IBM i system.

        A connection is required to the system to retrieve this information. If a connection has not been established, one is created to retrieve the information.

        Returns:
        The modification level. For example, version 5, release 1, modification level 0 returns 0.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • getNLV

        public String getNLV()
        Returns the National Language Version (NLV) that will be sent to the system. Only the COMMAND, PRINT, and DATABASE services accept an NLV.
        Returns:
        The NLV.
      • getPasswordExpirationDate

        public GregorianCalendar getPasswordExpirationDate()
                                                    throws AS400SecurityException,
                                                           IOException
        Returns the password expiration date for the signed-on user. If the profile's password expiration interval is set to *NOMAX, null is returned.

        A connection is required to retrieve this information. If a connection has not been established, one is created to retrieve the information.

        Returns:
        The password expiration date. If the profile has no password expiration data (*NOMAX), null is returned.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • setUseSystemPasswordExpirationWarningDays

        public void setUseSystemPasswordExpirationWarningDays(boolean useSystem)
        Set a flag to indicate whether or not to use the password expiration warning days from the QPWDEXPWRN system value. This capability is supported with V6R1M0 and later systems with V6R1M0 5761SS1 PTF SI48808 or V7R1M0 5770SS1 PTF SI48809.
        Parameters:
        useSystem - indicates whether or not to use password expiration warning days from the QPWDEXPWRN system value
      • getSystemPasswordExpirationWarningDays

        public int getSystemPasswordExpirationWarningDays()
                                                   throws AS400SecurityException,
                                                          IOException
        Returns the number of days before password expiration to start warning the user based on the value of the QPWDEXPWRN system value. This capability is supported with V6R1M0 and later systems with V6R1M0 5761SS1 PTF SI48808 or V7R1M0 5770SS1 PTF SI48809.
        Returns:
        The number of days before password expiration to start warning the user. If setUseSystemPasswordExpirationWarningDays(boolean) is enabled and supported, return the value of the QPWDEXPWRN system value. Otherwise, return getPasswordExpirationWarningDays().
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • isInPasswordExpirationWarningDays

        public boolean isInPasswordExpirationWarningDays()
                                                  throws AS400SecurityException,
                                                         IOException
        Determines if the password expiration date for the user profile is within the password expiration warning days for the system returned by getPasswordExpirationDays().
        Returns:
        true if the password expiration date for the user profile is within the password expiration days; otherwise, return false
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • getPasswordExpirationDays

        public int getPasswordExpirationDays()
                                      throws AS400SecurityException,
                                             IOException
        Returns the number of days until the user profile's password expires.

        A connection is required to retrieve this information. If a connection has not been established, one is created to retrieve the information.

        Returns:
        The number of days until the user profiles' password expires.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • getPasswordExpirationWarningDays

        public static int getPasswordExpirationWarningDays()
        Returns the number of days before password expiration to start warning the user.
        Returns:
        The number of days before expiration to warn the user.
      • getPreviousSignonDate

        public GregorianCalendar getPreviousSignonDate()
                                                throws AS400SecurityException,
                                                       IOException
        Returns the date of the last successful sign-on.

        A connection is required to retrieve this information. If a connection has not been established, one is created to retrieve the information.

        Returns:
        The date of the last successful sign-on.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • getProfileToken

        public ProfileTokenCredential getProfileToken()
                                               throws AS400SecurityException,
                                                      IOException,
                                                      InterruptedException
        Deprecated. Use getProfileToken(int,int) instead.
        Returns a profile token representing the signed-on user profile.

        The returned token will be created single-use with a one hour time to expiration. Subsequent method calls will return the same token, regardless of the token status.

        This function is not supported if the assigned password is *CURRENT.

        This function is only supported if the system is at i5/OS V4R5M0 or greater.

        Returns:
        A ProfileTokenCredential representing the currently signed on user.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
        InterruptedException - If this thread is interrupted.
      • getProfileToken

        public ProfileTokenCredential getProfileToken(int tokenType,
                                             int timeoutInterval)
                                               throws AS400SecurityException,
                                                      IOException,
                                                      InterruptedException
        Authenticates the assigned user profile and password and returns a corresponding ProfileTokenCredential if successful.

        This function is not supported if the assigned password is *CURRENT and cannot be used to generate a renewable token. This function is only supported if the system is at i5/OS V4R5M0 or greater.

        Parameters:
        tokenType - The type of profile token to create. Possible types are defined as fields on the ProfileTokenCredential class:
        timeoutInterval - The number of seconds to expiration when the token is created (1-3600).
        Returns:
        A ProfileTokenCredential representing the signed-on user.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
        InterruptedException - If this thread is interrupted.
      • getProfileToken

        public ProfileTokenCredential getProfileToken(String userId,
                                             String password)
                                               throws AS400SecurityException,
                                                      IOException,
                                                      InterruptedException
        Authenticates the given user profile and password and returns a corresponding ProfileTokenCredential if successful.

        Invoking this method does not change the user ID and password assigned to the system or otherwise modify the user or authorities under which the application is running.

        This method generates a single use token with a timeout of one hour.

        This function is only supported if the system is at i5/OS V4R5M0 or greater.

        Note: Providing an incorrect password increments the number of failed sign-on attempts for the user profile, and can result in the profile being disabled. Refer to documentation on the ProfileTokenCredential class for additional restrictions.

        Parameters:
        userId - The user profile name.
        password - The user profile password.
        Returns:
        A ProfileTokenCredential representing the authenticated profile and password.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
        InterruptedException - If this thread is interrupted.
      • getProfileToken

        public ProfileTokenCredential getProfileToken(String userId,
                                             String password,
                                             int tokenType,
                                             int timeoutInterval)
                                               throws AS400SecurityException,
                                                      IOException,
                                                      InterruptedException
        Authenticates the given user profile and password and returns a corresponding ProfileTokenCredential if successful.

        Invoking this method does not change the user ID and password assigned to the system or otherwise modify the user or authorities under which the application is running.

        This function is only supported if the system is at i5/OS V4R5M0 or greater.

        Note: Providing an incorrect password increments the number of failed sign-on attempts for the user profile, and can result in the profile being disabled. Refer to documentation on the ProfileTokenCredential class for additional restrictions.

        Parameters:
        userId - The user profile name.
        password - The user profile password.
        tokenType - The type of profile token to create. Possible types are defined as fields on the ProfileTokenCredential class:
        timeoutInterval - The number of seconds to expiration when the token is created (1-3600).
        Returns:
        A ProfileTokenCredential representing the authenticated profile and password.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
        InterruptedException - If this thread is interrupted.
      • getProxyServer

        public String getProxyServer()
        Returns the name of the middle-tier machine where the proxy server is running.
        Returns:
        The name of the middle-tier machine where the proxy server is running, or an empty string ("") if not set.
      • getRelease

        public int getRelease()
                       throws AS400SecurityException,
                              IOException
        Returns the release of the IBM i system.

        A connection is required to the system in order to retrieve this information. If a connection has not been established, one is created to retrieve the system information.

        Returns:
        The release of the IBM i system. For example, version 5, release 1, modification level 0, returns 1.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • getServerName

        public static String getServerName(int service)
      • getServicePort

        public int getServicePort(int service)
        Returns the service port stored in the service port table for the specified service.
        Parameters:
        service - The name of the service. Valid services are:
        Returns:
        The port specified in the service port table. The value USE_PORT_MAPPER will be returned if the service has not been set, and the service has not been connected.
      • getSignonDate

        public GregorianCalendar getSignonDate()
                                        throws AS400SecurityException,
                                               IOException
        Returns the date for the current sign-on.

        A connection is required to the system to retrieve this information. If a connection has not been established, one is created to retrieve the system information.

        Returns:
        The date for the current sign-on.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • getSocketProperties

        public SocketProperties getSocketProperties()
        Returns a copy of the socket options object.
        Returns:
        The socket options object.
      • getSystemName

        public String getSystemName()
        Returns the name of the IBM i system. The system name is provided on the constructor or may have been provided by the user at the sign-on prompt.
        Returns:
        The name of the IBM i system, or an empty string ("") if not set.
      • getDefaultTimeZone

        public static TimeZone getDefaultTimeZone(AS400 system)
        Returns the timezone of the IBM i, if available. If the timezone is not available, then the default timezone for the client will be return.
        Parameters:
        system - System to get the timezone from
        Returns:
        The timezone of the IBM i if available.
      • getUserId

        public String getUserId()
        Returns the user ID. The user ID returned may be set as a result of the constructor, or it may be what the user typed in at the sign-on prompt.
        Returns:
        The user ID, or an empty string ("") if not set.
      • getUserId

        public String getUserId(boolean forceRefresh)
        Returns the user ID. The user ID returned may be set as a result of the constructor, or it may be what the user typed in at the sign-on prompt.
        Parameters:
        forceRefresh - If true, force the current userID information to be reloaded. When running natively with system name specified as localhost, this will obtain the user profile under which the thread is currently running. This may have changed since object construction, if a profile swap has been performed on the thread. If false, or if running remotely, then this method behaves identically to getUserId().
        Returns:
        The user ID, or an empty string ("") if not set.
      • getVersion

        public int getVersion()
                       throws AS400SecurityException,
                              IOException
        Returns the version of the IBM i system.

        A connection is required to the system to retrieve this information. If a connection has not been established, one is created to retrieve the system information.

        Returns:
        The version of the IBM i system. For example, version 5, release 1, modification level 0, returns 5.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • getVRM

        public int getVRM()
                   throws AS400SecurityException,
                          IOException
        Returns the version, release, and modification level for the system.

        A connection is required to the system to retrieve this information. If a connection has not been established, one is created to retrieve the system information.

        Returns:
        The high 16-bit is the version, the next 8 bits is the release, and the low 8 bits is the modification level. Thus version 5, release 1, modification level 0, returns 0x00050100.
        Throws:
        AS400SecurityException - If a security or authority error occurs.
        IOException - If an error occurs while communicating with the system.
      • initializeConverter

        public void initializeConverter(int ccsid)
                                 throws UnsupportedEncodingException
        Initialize conversion table for the given CCSID. The default EBCDIC to unicode converters are not shipped with some browsers. This method can be used to check and download converters if they are not available locally.
        Parameters:
        ccsid - the CCSID for the conversion table to initialize.
        Throws:
        UnsupportedEncodingException
      • isConnected

        public boolean isConnected()
        Indicates if any service is currently connected through this object.

        A service is considered "connected" if connectService() has been called, or an implicit connect has been done by the service, and disconnectService() or disconnectAllServices() has not been called. If the most recent attempt to contact the service failed with an exception, the service is considered disconnected.

        Returns:
        true if any service is connected; false otherwise.
        See Also:
        isConnectionAlive()
      • isConnected

        public boolean isConnected(int service)
        Indicates if a service is currently connected through this object.

        A service is considered "connected" if connectService() has been called, or an implicit connect has been done by the service, and disconnectService() or disconnectAllServices() has not been called. If the most recent attempt to contact the service failed with an exception, the service is considered disconnected.

        Parameters:
        service - The name of the service. Valid services are:
        Returns:
        true if service is connected; false otherwise.
        See Also:
        isConnectionAlive()
      • isConnectionAlive

        public boolean isConnectionAlive()
        Tests the connection to the system, to verify that it is still working. This is similar in concept to "pinging" the system over the connection. If no services have been connected, this method returns false; it doesn't implicitly connect services.

        Note: This method is not fully supported until IBM i 7.1. If running to IBM i 6.1 or lower, then the behavior of this method matches that of isConnected(), and therefore may incorrectly return true if the connection has failed recently.

        Note: If the only service connected is RECORDACCESS, then this method defaults to the behavior of isConnected().

Returns:
true if the connection is still working; false otherwise.
See Also:
isConnected(), AS400JPing
  • isConnectionAlive

    public boolean isConnectionAlive(int service)
    Tests the connection to a service on the system, to verify that it is still working. This is similar in concept to "pinging" the system over the connection. If no services have been connected, this method returns false; it doesn't implicitly connect services.

    Note: This method is not fully supported until IBM i 7.1. If running to IBM i 6.1 or lower, then the behavior of this method matches that of isConnected(), and therefore may incorrectly return true if the connection has failed recently.

    Note: If the specified service is RECORDACCESS, then this method defaults to the behavior of isConnected().

    Parameters:
    service - The name of the service. Valid services are:
    Returns:
    true if the connection to the service is still working; false otherwise.
    See Also:
    isConnected(), AS400JPing
  • isGuiAvailable

    public boolean isGuiAvailable()
    Returns the sign-on prompting mode for this object. If true, then messages are displayed. If warnings or errors occur, the sign-on and change password dialogs are displayed if needed. If false, warnings and errors result in exceptions, and password dialogs are not displayed. The caller has to provide the user ID and password.
    Returns:
    true if using GUI; false otherwise.
  • isLocal

    public boolean isLocal()
    Indicates if this object is representing the system you are currently running on.
    Returns:
    true if you are running on the local system; false otherwise.
  • isMustUseSockets

    public boolean isMustUseSockets()
    When your Java program runs on the system, some Toolbox classes access data via a call to an API instead of making a socket call to the system. There are minor differences in the behavior of the classes when they use API calls instead of socket calls. If your program is affected by these differences you can check whether the Toolbox classes will use socket calls instead of API calls by using this method.
    Returns:
    true if you have indicated that the services must use sockets; false otherwise.
  • isShowCheckboxes

    public boolean isShowCheckboxes()
    Indicates if checkboxes should be shown on the sign-on dialog.
    Returns:
    true if checkboxes should be shown; false otherwise.
  • isThreadUsed

    public boolean isThreadUsed()
    Indicates whether threads are used in communication with the host servers.
    Returns:
    true if threads are used; false otherwise.
  • isUseDefaultUser

    public boolean isUseDefaultUser()
    Indicates if the default user should be used by this object. If the default user is not used and a user ID was not specified on the constructor, then the user will be prompted for a user ID.
    Returns:
    true if default user should be used; false otherwise.
  • isUsePasswordCache

    public boolean isUsePasswordCache()
    Indicates if the password cache is being used by this object. If the password cache is not used, the user will always be prompted for password if one was not provided.
    Returns:
    true if password cache is being used; false otherwise.
  • removeConnectionListener

    public void removeConnectionListener(ConnectionListener listener)
    Removes a listener from the connection event list.
    Parameters:
    listener - The listener object.
  • removeDefaultUser

    public static void removeDefaultUser(String systemName)
    Removes the default user for the given system name.
    Parameters:
    systemName - The name of the IBM i system.
  • removePasswordCacheEntry

    public static void removePasswordCacheEntry(String systemName,
                                String userId)
    Removes the password cache entry associated with this system name and user ID. Only applies within this Java virtual machine.
    Parameters:
    systemName - The name of the IBM i system.
    userId - The user profile name.
  • removePropertyChangeListener

    public void removePropertyChangeListener(PropertyChangeListener listener)
    Removes a property changed listener from the listener list.
    Parameters:
    listener - The listener object.
  • removeVetoableChangeListener

    public void removeVetoableChangeListener(VetoableChangeListener listener)
    Removes a listener from the veto list.
    Parameters:
    listener - The listener object.
  • resetAllServices

    public void resetAllServices()
    Disconnects all services, and clears the sign-on information. This intent of this method is to "wipe the slate clean" for this AS400 object, enabling connection properties to be subsequently reset.
    See Also:
    disconnectAllServices()
  • setIdentityToken

    public void setIdentityToken(byte[] identityToken)
    Sets or resets the identity token for this object. Using this method will clear any previously set authentication information.

    Note: Authentication via IdentityToken is supported in operating system release V5R3M0 and by PTF in operating system releases V5R2M0 and V5R1M0.

    Parameters:
    identityToken - The identity token.
  • setCcsid

    public void setCcsid(int ccsid)
                  throws PropertyVetoException
    Sets the CCSID to be used for this object. The CCSID property cannot be changed once a connection to the system has been established.
    Parameters:
    ccsid - The CCSID to use for this object.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
  • setDDMRDB

    public void setDDMRDB(String ddmRDB)
    Sets the relational database name (RDB name) used for record-level access (DDM) connections. The RDB name corresponds to the independent auxiliary storage pool (IASP) that it is using on the system. The RDB name cannot be changed while this object is actively connected to the RECORDACCESS service; you must call AS400.disconnectService(AS400.RECORDACCESS) first.
    Parameters:
    ddmRDB - The name of the IASP or RDB to use, or null to indicate the default system ASP should be used.
    See Also:
    isConnected(int), getDDMRDB()
  • setDefaultSignonHandler

    public static void setDefaultSignonHandler(SignonHandler handler)
    Sets the default sign-on handler, globally across the JVM. The specified handler object will be called at runtime if any AS400 object needs to obtain additional signon information, and a sign-on handler has not been set on the AS400 object via setSignonHandler().
    Users are advised to implement the default sign-on handler in a thread-safe manner, since it may occasionally be in simultaneous use by multiple threads.
    If a default sign-on handler is not set, then the name of the default sign-on handler class is retrieved from the com.ibm.as400.access.AS400.signonHandler system property.
    If not specified, an internal AWT-based sign-on handler is used.

    Note: This property may also be set by specifying a fully-qualified class name in Java system property com.ibm.as400.access.AS400.signonHandler

    Parameters:
    handler - The sign-on handler. Specifying null will reset the default sign-on handler to the internal AWT-based handler.
    See Also:
    getDefaultSignonHandler()
  • setDefaultUser

    public static boolean setDefaultUser(String systemName,
                         String userId)
    Sets the default user for a given system name. The default user is the user ID that is used to connect if a user ID is not provided for that system name. There can be only one default user per system name. Once the default user is set, it cannot be overridden. To change the default user, the caller should remove the default user and then set it.
    Parameters:
    systemName - The name of the IBM i system.
    userId - The user profile name.
    Returns:
    true if default user has been set; false otherwise.
  • setGSSManager

    public static void setGSSManager(Object gssMgr)
    Sets the GSS manager to be used for all GSS operations.
    Parameters:
    gssMgr - The GSS manager object. The object's type must be org.ietf.jgss.GSSManager, the object is set to type Object only to avoid a JDK release dependency.
  • setGSSCredential

    public void setGSSCredential(Object gssCredential)
    Sets the GSS credential for this object. Using this method will set the authentication scheme to AUTHENTICATION_SCHEME_GSS_TOKEN. Only one authentication means (Kerberos ticket, profile token, identity token, or password) can be used at a single time. Using this method will clear any previously set authentication information.
    Parameters:
    gssCredential - The GSS credential object. The object's type must be org.ietf.jgss.GSSCredential, the object is set to type Object only to avoid a JDK release dependency.
  • setGSSOption

    public void setGSSOption(int gssOption)
    Sets the option for how the JGSS framework will be used to retrieve a GSS token for authenticating to the system. By default, if no password or profile token is set on this object, it will attempt to retrieve a GSS token. If that retrieval fails, a sign-on dialog can be presented, or on the system, the current user profile information can be used. This option can also be set to only do the GSS token retrieval or to skip the GSS token retrieval.
    Parameters:
    gssOption - A constant indicating how GSS will be used. Valid values are:
  • setGSSName

    public void setGSSName(String gssName)
    Sets the GSS name for this object. Using this method will set the authentication scheme to AUTHENTICATION_SCHEME_GSS_TOKEN. Only one authentication means (Kerberos ticket, profile token, identity token, or password) can be used at a single time. Using this method will clear any previously set authentication information.
    Parameters:
    gssName - The GSS name string.
  • setGuiAvailable

    public void setGuiAvailable(boolean guiAvailable)
                         throws PropertyVetoException
    Sets the environment in which you are running. If guiAvailable is set to true, then prompting may occur during sign-on to display error conditions, to prompt for additional information, or to prompt for change password. If guiAvailable is set to false, then error conditions or missing information will result in exceptions. Applications that are running as IBM i applications or want to control the sign-on user interface may want to run with prompting mode set to false. Prompting mode is set to true by default.

    Note: This property may also be set by specifying 'true' or 'false' in Java system property com.ibm.as400.access.AS400.guiAvailable

    Parameters:
    guiAvailable - true to prompt; false otherwise.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
    See Also:
    SignonHandler
  • setLocale

    public void setLocale(Locale locale)
    Sets the Locale used to set the National Language Version (NLV) on the system. Only the COMMAND, PRINT, and DATABASE services accept an NLV. This method will set the NLV based on a mapping from the Locale object to the NLV.
    Parameters:
    locale - The Locale object.
  • setLocale

    public void setLocale(Locale locale,
                 String nlv)
    Sets the Locale and a specific National Language Version (NLV) to send to the system. Only the COMMAND, PRINT, and DATABASE services accept an NLV.
    Parameters:
    locale - The Locale object.
    nlv - The NLV.
  • setMustAddLanguageLibrary

    public void setMustAddLanguageLibrary(boolean mustAddLanguageLibrary)
    Sets this object to attempt to add the appropriate secondary language library to the library list, when running on the system. The default is false. Setting the language library will ensure that any system error messages that are returned, will be returned in the appropriate national language for the client locale. If the user profile has insufficient authority to call CHGSYSLIBL, an error entry will appear in the job log, and the Toolbox will disregard the error and proceed normally.

    Note: This property may also be set by specifying 'true' or 'false' in Java system property com.ibm.as400.access.AS400.mustAddLanguageLibrary

    Parameters:
    mustAddLanguageLibrary - true to add language library; false otherwise.
  • isMustAddLanguageLibrary

    public boolean isMustAddLanguageLibrary()
    Indicates whether this object will attempt to add the appropriate secondary language library to the library list, when running on the system.
    Returns:
    true if you have indicated that the secondary language library must be added; false otherwise.
  • setMustUseSockets

    public void setMustUseSockets(boolean mustUseSockets)
    Sets this object to using sockets. When your Java program runs on the system, some Toolbox classes access data via a call to an API instead of making a socket call to the system. There are minor differences in the behavior of the classes when they use API calls instead of socket calls. If your program is affected by these differences you can force the Toolbox classes to use socket calls instead of API calls by using this method. The default is false. The must use sockets property cannot be changed once a connection to the system has been established.

    Note: This property may also be set by specifying 'true' or 'false' in Java system property com.ibm.as400.access.AS400.mustUseSockets

    Parameters:
    mustUseSockets - true to use sockets; false otherwise.
  • isMustUseNetSockets

    public boolean isMustUseNetSockets()
    Indicates if Internet domain sockets only will be used.
    Returns:
    true if must use Internet domain sockets only; false otherwise.
  • setMustUseNetSockets

    public void setMustUseNetSockets(boolean mustUseNetSockets)
    Sets this object to using Internet domain sockets only. When your Java program runs on the system, some Toolbox classes create UNIX domain socket connections. Using this method forces the Toolbox to only use Internet domain sockets. The default is false. The must use net sockets property cannot be changed once a connection to the system has been established.

    Note: This property may also be set by specifying 'true' or 'false' in Java system property com.ibm.as400.access.AS400.mustUseNetSockets

    Parameters:
    mustUseNetSockets - true to use Internet domain sockets only; false otherwise.
  • isMustUseSuppliedProfile

    public boolean isMustUseSuppliedProfile()
    Indicates if only a supplied profile will be used.
    Returns:
    true if must use a supplied profile only; false otherwise.
  • setMustUseSuppliedProfile

    public void setMustUseSuppliedProfile(boolean mustUseSuppliedProfile)
    Sets this object to using a supplied profile only. When your Java program runs on the system, the information from the currently signed-on user profile can be used. Using this method prevents the Toolbox from retrieving the current user profile information. The default is false. The must use supplied profile property cannot be changed once a connection to the system has been established.

    Note: This property may also be set by specifying 'true' or 'false' in Java system property com.ibm.as400.access.AS400.mustUseSuppliedProfile

    Parameters:
    mustUseSuppliedProfile - true to use a supplied profile only; false otherwise.
  • setPassword

    public void setPassword(String password)
    Sets the password for this object. Only one authentication means (Kerberos ticket, profile token, identity token, or password) can be used at a single time. Using this method will clear any previously set authentication information.
    Parameters:
    password - The user profile password.
  • setPasswordExpirationWarningDays

    public static void setPasswordExpirationWarningDays(int days)
    Sets the number of days before password expiration to warn the user.
    Parameters:
    days - The number of days before expiration to start the warning. Set to -1 to turn off warning.
  • setProfileToken

    public void setProfileToken(ProfileTokenCredential profileToken)
    Sets or resets the profile token for this object. Using this method will clear any previously set authentication information.
    Parameters:
    profileToken - The profile token.
  • setProxyServer

    public void setProxyServer(String proxyServer)
                        throws PropertyVetoException
    Sets the name and port of the middle-tier machine where the proxy server is running. If this is not set, then the name is retrieved from the com.ibm.as400.access.AS400.proxyServer system property. The ProxyServer must be running on the middle-tier machine.

    The name of the middle-tier machine is ignored in a two-tier environment. If no middle-tier machine is specified, then it is assumed that no middle-tier will be accessed. The name of the middle-tier machine cannot be changed once a connection to this machine has been established.

    Parameters:
    proxyServer - The name and port of the proxy server in the format serverName[:port]. If no port is specified, a default will be used.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
  • setServicePort

    public void setServicePort(int service,
                      int port)
    Sets the service port in the service port table for the specified service for this system name.
    Parameters:
    service - The name of the service. Valid services are:
    port - The port to use for this service. The value USE_PORT_MAPPER can be used to specify that the next connection to this service should ask the port mapper server for the port number.
  • setServicePortsToDefault

    public void setServicePortsToDefault()
    Sets the ports in the service port table for all the services for this system name to their default values. This causes the connections to this system name to use the default ports for those services rather than querying the port number through a port mapper connection. The use of this method can reduce the number of connections made to the system.
  • setShowCheckboxes

    public void setShowCheckboxes(boolean showCheckboxes)
    Indicates if checkboxes should be shown on the sign-on dialog.
    Parameters:
    showCheckboxes - true to show checkboxes; false otherwise.
  • setSignonHandler

    public void setSignonHandler(SignonHandler handler)
    Sets the sign-on handler for this AS400 object. The specified handler will be called at runtime if the AS400 object needs to obtain additional signon information.
    By default, an internal AWT-based implementation is used, if no sign-on handler has been statically set via setDefaultSignonHandler().
    Parameters:
    handler - The sign-on handler. Specifying null will reset the default sign-on handler to the internal AWT-based handler.
    See Also:
    getSignonHandler(), setDefaultSignonHandler(com.ibm.as400.access.SignonHandler)
  • setSocketProperties

    public void setSocketProperties(SocketProperties socketProperties)
    Sets the socket options the IBM Toolbox for Java will set on its client side sockets. The socket properties cannot be changed once a connection to the system has been established.
    Parameters:
    socketProperties - The set of socket options to set. The options are copied from this object, not shared.
  • setSystemName

    public void setSystemName(String systemName)
                       throws PropertyVetoException
    Sets the system name for this object. The system name cannot be changed once a connection to the system has been established.
    Parameters:
    systemName - The name of the IBM i system. Use localhost to access data locally.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
  • setThreadUsed

    public void setThreadUsed(boolean useThreads)
                       throws PropertyVetoException
    Sets whether the IBM Toolbox for Java uses threads in communication with the host servers. The default is true. Letting the IBM Toolbox for Java use threads may be beneficial to performance, turning threads off may be necessary if your application needs to be compliant with the Enterprise Java Beans specification. The thread used property cannot be changed once a connection to the system has been established.

    Note: This property may also be set by specifying 'true' or 'false' in Java system property com.ibm.as400.access.AS400.threadUsed

    Parameters:
    useThreads - true to use threads; false otherwise.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
  • setUseDefaultUser

    public void setUseDefaultUser(boolean useDefaultUser)
                           throws PropertyVetoException
    Sets the indicator for whether the default user is used. The default user is used if a system name is provided, but a user ID is not. If a default user is set for that system, then the default user is used.
    Parameters:
    useDefaultUser - The value indicating if the default user should be used. Set to true if default user should be used; false otherwise. The default is true, indicating that the default user is used.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
  • setUsePasswordCache

    public void setUsePasswordCache(boolean usePasswordCache)
                             throws PropertyVetoException
    Sets the indicator for whether the password cache is used. If password cache is used, then the user would only have to enter password once within a Java virtual machine. The default is to use the cache.
    Unless the application is running in its own private JVM, users are advised to turn off password caching, in order to ensure that another application within the same JVM cannot create a connection using the cached password.
    Parameters:
    usePasswordCache - The value indicating whether the password cache should be used. Set to true to use the password cache; false otherwise.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
  • setUserId

    public void setUserId(String userId)
                   throws PropertyVetoException
    Sets the user ID for this object. The user ID cannot be changed once a connection to the system has been established. If this method is used in conjunction with a Kerberos ticket, profile token, or identity token, the user profile associated with the authentication token must match this user ID.
    Parameters:
    userId - The user profile name.
    Throws:
    PropertyVetoException - If any of the registered listeners vetos the property change.
  • toString

    public String toString()
    Returns the text representation of this AS400 object.
    Overrides:
    toString in class Object
    Returns:
    The string representing this AS400 object.
  • validateSignon

    public boolean validateSignon()
                           throws AS400SecurityException,
                                  IOException
    Validates the user ID and password on the system but does not add to the signed-on list. The system name, user ID, and password need to be set prior to calling this method.

    Note: This will return true if the information is successfully validated. An unsuccessful validation will cause an exception to be thrown, false is never returned.

    Returns:
    true if successful.
    Throws:
    AS400SecurityException - If a security or authority error occurs.
    IOException - If an error occurs while communicating with the system.
  • validateSignon

    public boolean validateSignon(String password)
                           throws AS400SecurityException,
                                  IOException
    Validates the user ID and password on the system but does not add to the signed-on list. The user ID and system name need to be set before calling this method.

    Note: This will return true if the information is successfully validated. An unsuccessful validation will cause an exception to be thrown, false is never returned.

    Parameters:
    password - The user profile password to validate.
    Returns:
    true if successful.
    Throws:
    AS400SecurityException - If a security or authority error occurs.
    IOException - If an error occurs while communicating with the system.
  • validateSignon

    public boolean validateSignon(String userId,
                         String password)
                           throws AS400SecurityException,
                                  IOException
    Validates the user ID and password on the system but does not add to the signed-on list. The system name needs to be set prior to calling this method.

    Note: This will return true if the information is successfully validated. An unsuccessful validation will cause an exception to be thrown, false is never returned.

    Parameters:
    userId - The user profile name to validate.
    password - The user profile password to validate.
    Returns:
    true if successful.
    Throws:
    AS400SecurityException - If a security or authority error occurs.
    IOException - If an error occurs while communicating with the system.
  • setBidiStringType

    public void setBidiStringType(int bidiStringType)
    Sets bidi string type of the connection. See BidiStringType for more information and valid values.
  • getBidiStringType

    public int getBidiStringType()
    Returns bidi string type of the connection. See BidiStringType for more information and valid values.