0N/A/*
2362N/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.net.httpserver;
0N/Aimport java.net.*;
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/A/**
0N/A * Authenticator represents an implementation of an HTTP authentication
0N/A * mechanism. Sub-classes provide implementations of specific mechanisms
0N/A * such as Digest or Basic auth. Instances are invoked to provide verification
0N/A * of the authentication information provided in all incoming requests.
0N/A * Note. This implies that any caching of credentials or other authentication
0N/A * information must be done outside of this class.
0N/A */
0N/Apublic abstract class Authenticator {
0N/A
0N/A /**
0N/A * Base class for return type from authenticate() method
0N/A */
0N/A public abstract static class Result {}
0N/A
0N/A /**
0N/A * Indicates an authentication failure. The authentication
0N/A * attempt has completed.
0N/A */
0N/A public static class Failure extends Result {
0N/A
0N/A private int responseCode;
0N/A
0N/A public Failure (int responseCode) {
0N/A this.responseCode = responseCode;
0N/A }
0N/A
0N/A /**
0N/A * returns the response code to send to the client
0N/A */
0N/A public int getResponseCode() {
0N/A return responseCode;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Indicates an authentication has succeeded and the
0N/A * authenticated user principal can be acquired by calling
0N/A * getPrincipal().
0N/A */
0N/A public static class Success extends Result {
0N/A private HttpPrincipal principal;
0N/A
0N/A public Success (HttpPrincipal p) {
0N/A principal = p;
0N/A }
0N/A /**
0N/A * returns the authenticated user Principal
0N/A */
0N/A public HttpPrincipal getPrincipal() {
0N/A return principal;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Indicates an authentication must be retried. The
0N/A * response code to be sent back is as returned from
0N/A * getResponseCode(). The Authenticator must also have
0N/A * set any necessary response headers in the given HttpExchange
0N/A * before returning this Retry object.
0N/A */
0N/A public static class Retry extends Result {
0N/A
0N/A private int responseCode;
0N/A
0N/A public Retry (int responseCode) {
0N/A this.responseCode = responseCode;
0N/A }
0N/A
0N/A /**
0N/A * returns the response code to send to the client
0N/A */
0N/A public int getResponseCode() {
0N/A return responseCode;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * called to authenticate each incoming request. The implementation
0N/A * must return a Failure, Success or Retry object as appropriate :-
0N/A * <p>
0N/A * Failure means the authentication has completed, but has failed
0N/A * due to invalid credentials.
0N/A * <p>
0N/A * Sucess means that the authentication
0N/A * has succeeded, and a Principal object representing the user
0N/A * can be retrieved by calling Sucess.getPrincipal() .
0N/A * <p>
0N/A * Retry means that another HTTP exchange is required. Any response
0N/A * headers needing to be sent back to the client are set in the
0N/A * given HttpExchange. The response code to be returned must be provided
0N/A * in the Retry object. Retry may occur multiple times.
0N/A */
0N/A public abstract Result authenticate (HttpExchange exch);
0N/A}