Authentication mechanisms
As mentioned earlier, an authentication mechanism is the way the user identifies themselves to your application via the web browser. In the following sections, we're going to take a closer look at basic and form authentication methods.
Basic authentication
As mentioned earlier, basic authentication displays the browser's native login dialog before the user can access the protected resource. Although this method is not popular in real-world applications now, it's still useful in cases where you need a handy login mechanism for a quick or internal application.
In the following example, we're creating a basic authentication mechanism using the Java new security API:
@BasicAuthenticationMechanismDefinition(realmName="user-realm") @WebServlet("/home") @DeclareRoles({"user"}) @ServletSecurity(@HttpConstraint(rolesAllowed = "user")) public class HomeServlet extends HttpServlet { ... }
Let's see how we annotated our class:
@BasicAuthenticationMechanismDefinition
: This...