Basic Authentication and PrimeFaces Methods

Overview

In the chapter “Window Shopping,” we always used the Basic authentication method. However, many other standardized authentication methods are more helpful than this one. In the Basic authentication method, the end user has to fill in their credentials in a basic dialog. We want to present the user with a nice login form that can be styled according to the rest of the application. This can be achieved by the form-based authentication method. Other methods may be preferable depending on the application’s use case. These include OpenID Connect and identifications based on client certificates or tokens.

For the form-based method, a standard URL is defined within Jakarta Security, j_security_check, where the username and password (with standard names j_username and j_password) can be handled. The server picks up these values and validates them against a realm, as we did in the lesson Standards Basic Method.

Using OAuth2 and OpenID Connect requires an entirely different approach, as we will see in lessons OAuth2 and OpenID Connect. To get started, let’s look at the form-based authentication method for a web application.

PrimeFaces based form method

In this lesson’s example, we will use PrimeFacesPrimeFaces is a famous JavaServer Faces UI framework. It is used to develop sophisticated applications for enterprise or standard websites. is the default standard JSFJavaServer Faces component library, to integrate the requirements of form-based authentication. The standard URLs and post names for the credentials within a login page created with PrimeFaces.

We will define the protected resources using the security API configuration and indicate that we are using form based authentication using the standard names and endpoint.

We will define the protected resources using the security API configuration and indicate the form based authentication using the standard names and endpoint.

Create the project

We again start from the project template that we defined earlier and add the required dependencies and classes to it.

  • If you want to work within the Educative platform, simply use the project we’ve created at the end of this lesson. If you choose to work locally, you will need to create a Maven project formPF as described in “Introduction to Window Shopping."

Add Maven dependency

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy