public static void addDigestAuthHandler(Server server, Handler handler) { addAuthHandler(server, Constraint.__DIGEST_AUTH, new DigestAuthenticator(), handler); }
public static void addBasicAuthHandler(Server server, Handler handler) { addAuthHandler(server, Constraint.__BASIC_AUTH, new BasicAuthenticator(), handler); }
return new DeferredAuthentication(this); if (DeferredAuthentication.isDeferred(response)) return Authentication.UNAUTHENTICATED;
@Override public Authenticator getAuthenticator(Server server, ServletContext context, AuthConfiguration configuration, IdentityService identityService, LoginService loginService) { String auth=configuration.getAuthMethod(); Authenticator authenticator=null; if (auth==null || Constraint.__BASIC_AUTH.equalsIgnoreCase(auth)) authenticator=new BasicAuthenticator(); else if (Constraint.__DIGEST_AUTH.equalsIgnoreCase(auth)) authenticator=new DigestAuthenticator(); else if (Constraint.__FORM_AUTH.equalsIgnoreCase(auth)) authenticator=new FormAuthenticator(); else if ( Constraint.__SPNEGO_AUTH.equalsIgnoreCase(auth) ) authenticator = new SpnegoAuthenticator(); else if ( Constraint.__NEGOTIATE_AUTH.equalsIgnoreCase(auth) ) // see Bug #377076 authenticator = new SpnegoAuthenticator(Constraint.__NEGOTIATE_AUTH); if (Constraint.__CERT_AUTH.equalsIgnoreCase(auth)||Constraint.__CERT_AUTH2.equalsIgnoreCase(auth)) authenticator=new ClientCertAuthenticator(); return authenticator; }
@Override public UserIdentity login(String username, Object password, ServletRequest request) { UserIdentity user = super.login(username,password,request); if (user!=null) { HttpSession session = ((HttpServletRequest)request).getSession(true); Authentication cached=new SessionAuthentication(getAuthMethod(),user,password); session.setAttribute(SessionAuthentication.__J_AUTHENTICATED, cached); } return user; }
public FormAuthenticator(String login,String error,boolean dispatch) { this(); if (login!=null) setLoginPage(login); if (error!=null) setErrorPage(error); _dispatch=dispatch; }
private DigestAuthHandler() throws Exception { digestAuthenticator = new DigestAuthenticator(); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); final HashLoginService hashLoginService = new HashLoginService("realm", "src/test/resources/TestInvokeHttp/realm.properties"); hashLoginService.start(); securityHandler.setLoginService(hashLoginService); securityHandler.setIdentityService(new DefaultIdentityService()); digestAuthenticator.setConfiguration(securityHandler); }
@Override public void setDateHeader(String name, long date) { if (notIgnored(name)) super.setDateHeader(name,date); }
@Override public void setConfiguration(AuthConfiguration configuration) { super.setConfiguration(configuration); String mna = configuration.getInitParameter("maxNonceAge"); if (mna != null) setMaxNonceAge(Long.parseLong(mna)); String mnc = configuration.getInitParameter("maxNonceCount"); if (mnc != null) setMaxNonceCount(Integer.parseInt(mnc)); }
/** * @return * @return * @see http://www.eclipse.org/jetty/documentation/current/embedded-examples.html */ private ConstraintSecurityHandler createSecurityHandler(Config config) { ConstraintSecurityHandler security = new ConstraintSecurityHandler(); Set<String> knownRoles = ImmutableSet.of(ADMIN_ROLE); security.setConstraintMappings(Collections.<ConstraintMapping> emptyList(), knownRoles); security.setAuthenticator(new FormAuthenticator("/login", "/login", true)); security .setLoginService(new AmLoginService(AMSecurityManagerImpl.instance())); return security; }
@Override public void valueUnbound(HttpSessionBindingEvent event) { doLogout(); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { baseRequest.setHandled(true); try { Authentication authentication = digestAuthenticator.validateRequest(request, response, true); if (authentication instanceof Authentication.User) { response.setContentType("text/plain"); Authentication.User user = (Authentication.User) authentication; response.getWriter().println(user.getAuthMethod()); } else if (authentication instanceof Authentication.ResponseSent) { Authentication.ResponseSent responseSent = (Authentication.ResponseSent) authentication; } } catch (ServerAuthException e) { e.printStackTrace(); } } }
mapping.setConstraint( constraint ); securityHandler.setConstraintMappings(Collections.singletonList(mapping)); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(loginService);
@Override public void setHeader(String name, String value) { if (notIgnored(name)) super.setHeader(name,value); }
@Override public void logout() { if (_session!=null && _session.getAttribute(__J_AUTHENTICATED)!=null) _session.removeAttribute(__J_AUTHENTICATED); doLogout(); }
securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(loginService);
@Override public void addDateHeader(String name, long date) { if (notIgnored(name)) super.addDateHeader(name,date); }
csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("myrealm"); csh.addConstraintMapping(healthcheckConstraintMapping);
@Override public void addHeader(String name, String value) { if (notIgnored(name)) super.addHeader(name,value); }
securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(loginService);