The Java EE 6 Tutorial

ProcedureTo Run the Basic Authentication Servlet

  1. In a web browser, navigate to the following URL:

    https://localhost:8181/hello2_basicauth/greeting

    You may be prompted to accept the security certificate for the server. If so, accept the security certificate. If the browser warns that the certificate is invalid because it is self-signed, add a security exception for the application.

    An Authentication Required dialog box appears. Its appearance varies, depending on the browser you use. Figure 25–6 shows an example.

    Figure 25–6 Sample Basic Authentication Dialog Box

    Example of a basic authentication dialog box

  2. Type a user name and password combination that corresponds to a user who has already been created in the file realm of the GlassFish Server and has been assigned to the group of TutorialUser; then click OK.

    Basic authentication is case sensitive for both the user name and password, so type the user name and password exactly as defined for the GlassFish Server.

    The server returns the requested resource if all the following conditions are met.

    • A user with the user name you entered is defined for the GlassFish Server.

    • The user with the user name you entered has the password you entered.

    • The user name and password combination you entered is assigned to the group TutorialUser on the GlassFish Server.

    • The role of TutorialUser, as defined for the application, is mapped to the group TutorialUser, as defined for the GlassFish Server.

    When these conditions are met and the server has authenticated the user, the application will appear as shown in Figure 3–2 but with a different URL.

  3. Type a name in the text field and click the Submit button.

    Because you have already been authorized, the name you enter in this step does not have any limitations. You have unlimited access to the application now.

    The application responds by saying “Hello” to you, as shown in Figure 3–3 but with a different URL.

Next Steps

For repetitive testing of this example, you may need to close and reopen your browser. You should also run the ant undeploy and ant clean targets or the NetBeans IDE Clean and Build option to get a fresh start.