Code example for LoginException

        if (login != null) {
            return Framework.login(login[0], login[1]);
        // TODO no login provided - use anonymous ? 
        // for now no anonymous user supported - we require a login 
        throw new LoginException("User must login");
        //return null; 
    protected void handleLoginFailure(HttpServletRequest request, HttpServletResponse response, LoginException e) {
        String s = "Basic realm=\""+realmName+"\"";
        response.setHeader("WWW-Authenticate", s);
    protected HttpServletRequest wrapRequest(HttpServletRequest request, LoginContext lc) {
        Set<Principal> set = lc.getSubject().getPrincipals();
        if (!set.isEmpty()) {
            final Principal principal = set.iterator().next();
        return new HttpServletRequestWrapper(request) {
Connect your IDE to all the code out there  Get Codota for Java