Developing with the AuthDataProvider API to obtain authentication data

You can use the AuthDataProvider Application Programming Interface (API) to obtain the authentication data from your application.

About this task

Your application can use the AuthDataProvider API to obtain an AuthData object that contains the user name and password configured for an authData element.

Procedure

  1. Add the passwordUtilities-1.0 feature in the server.xml file. For example:
    <featureManager>
      <feature>passwordUtilities-1.0</feature>
    </featureManager>
  2. Configure an authData element in the server.xml file. For example:
    <authData id="myAuthData" user="myUser" password="myPassword"/> <!-- password can also be encoded -->

    Encode the password within the configuration. You can get the encoded value by using the securityUtility encode command.

  3. Use the AuthDataProvider API from your application servlet or enterprise bean as follows, replacing the authData alias with the one you need. For example:
    AuthData authData = AuthDataProvider.getAuthData("myAuthData"); // Replace value with your alias.
    Note: The error handling is not shown for simplicity. A javax.security.auth.login.LoginException is encountered if the authentication alias requested does not exist or is malformed.
  4. Obtain the user name and password from the AuthData object. For example:
    String userName = authData.getUserName();
    char[] password = authData.getPassword();
    // Do something with the userName and password.