Managing default user IDs

To minimize the number of times a user has to sign on, use a default user ID. The Java™ program uses the default user ID when a the program does not provide a user ID. The default user ID can be set either by the Java program or through the user interface. If the default user ID has not been established, the Sign-On dialog allows the user to set the default user ID.

Once the default user ID is established for a given server, the Sign-On dialog does not allow the default user ID to be changed. When an AS400 object is constructed, the Java program can supply the user ID and password. When a program supplies the user ID to the AS400 object, the default user ID is not affected. The program must explicitly set the default user ID setUseDefaultUser() if the program wants to set or change the default user ID. See Prompting, default user ID, and password caching summary for more information.

The AS400 object has methods to get, set, and remove the default user ID. The Java program can also disable default user ID processing through the setUseDefaultUser() method. If default user ID processing is disabled and the Java application does not supply a user ID, the AS400 object prompts for user ID every time a connection is made to the iSeries™ server.

All AS400 objects that represent the same iSeries server within a Java virtual machine use the same default user ID.

In the following example, two connections to the server are created by using two AS400 objects. If the user checked the Default User ID box when signing on, the user is not prompted for a user ID when the second connection is made.

                       // Create two AS400 objects to the
                       // same iSeries.
     AS400 sys1 = new AS400("mySystem.myCompany.com");
     AS400 sys2 = new AS400("mySystem.myCompany.com");

                       // Start a connection to the command
                       // call service. The user is prompted
                       // for user ID and password.
     sys1.connectService(AS400.COMMAND);

                       // Start another connection to the
                       // command call service. The user is
                       // not prompted.
     sys2.connectService(AS400.COMMAND);

The default user ID information is discarded when the last AS400 object for the an iSeries server is garbage collected.