javax.security.auth.spi


1. Get User Principal from HttpServletRequest

import javax.security.auth.Subject;
import javax.security.auth.spi.LoginContext;

public class GetUserPrincipal {
    public static void main(String[] args) {
        try {
            // Get the current Subject from the HttpServletRequest
            Subject subject = (Subject) request.getAttribute("javax.security.auth.subject");

            // Get the UserPrincipal from the Subject
            UserPrincipal principal = subject.getPrincipals(UserPrincipal.class).iterator().next();

            // Print the UserPrincipal
            System.out.println("UserPrincipal: " + principal.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

2. Get LoginModule Configuration

3. Create a Custom LoginModule

4. Create a Custom CallbackHandler

5. Use the JAAS Login API

6. Use the JAAS Subject API