0N/A/*
2362N/A * Copyright (c) 2000, 2004, 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 javax.security.sasl;
0N/A
0N/A/**
0N/A * Performs SASL authentication as a server.
0N/A *<p>
0N/A * A server such an LDAP server gets an instance of this
0N/A * class in order to perform authentication defined by a specific SASL
0N/A * mechanism. Invoking methods on the <tt>SaslServer</tt> instance
0N/A * generates challenges according to the SASL
0N/A * mechanism implemented by the <tt>SaslServer</tt>.
0N/A * As the authentication proceeds, the instance
0N/A * encapsulates the state of a SASL server's authentication exchange.
0N/A *<p>
0N/A * Here's an example of how an LDAP server might use a <tt>SaslServer</tt>.
0N/A * It first gets an instance of a <tt>SaslServer</tt> for the SASL mechanism
0N/A * requested by the client:
0N/A *<blockquote><pre>
0N/A * SaslServer ss = Sasl.createSaslServer(mechanism,
0N/A * "ldap", myFQDN, props, callbackHandler);
0N/A *</pre></blockquote>
0N/A * It can then proceed to use the server for authentication.
0N/A * For example, suppose the LDAP server received an LDAP BIND request
0N/A * containing the name of the SASL mechanism and an (optional) initial
0N/A * response. It then might use the server as follows:
0N/A *<blockquote><pre>
0N/A * while (!ss.isComplete()) {
0N/A * try {
0N/A * byte[] challenge = ss.evaluateResponse(response);
0N/A * if (ss.isComplete()) {
0N/A * status = ldap.sendBindResponse(mechanism, challenge, SUCCESS);
0N/A * } else {
0N/A * status = ldap.sendBindResponse(mechanism, challenge,
0N/A SASL_BIND_IN_PROGRESS);
0N/A * response = ldap.readBindRequest();
0N/A * }
0N/A * } catch (SaslException e) {
0N/A * status = ldap.sendErrorResponse(e);
0N/A * break;
0N/A * }
0N/A * }
0N/A * if (ss.isComplete() && status == SUCCESS) {
0N/A * String qop = (String) sc.getNegotiatedProperty(Sasl.QOP);
0N/A * if (qop != null
0N/A * && (qop.equalsIgnoreCase("auth-int")
0N/A * || qop.equalsIgnoreCase("auth-conf"))) {
0N/A *
0N/A * // Use SaslServer.wrap() and SaslServer.unwrap() for future
0N/A * // communication with client
0N/A * ldap.in = new SecureInputStream(ss, ldap.in);
0N/A * ldap.out = new SecureOutputStream(ss, ldap.out);
0N/A * }
0N/A * }
0N/A *</pre></blockquote>
0N/A *
0N/A * @since 1.5
0N/A *
0N/A * @see Sasl
0N/A * @see SaslServerFactory
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Rob Weltman
0N/A */
0N/Apublic abstract interface SaslServer {
0N/A
0N/A /**
0N/A * Returns the IANA-registered mechanism name of this SASL server.
0N/A * (e.g. "CRAM-MD5", "GSSAPI").
0N/A * @return A non-null string representing the IANA-registered mechanism name.
0N/A */
0N/A public abstract String getMechanismName();
0N/A
0N/A /**
0N/A * Evaluates the response data and generates a challenge.
0N/A *
0N/A * If a response is received from the client during the authentication
0N/A * process, this method is called to prepare an appropriate next
0N/A * challenge to submit to the client. The challenge is null if the
0N/A * authentication has succeeded and no more challenge data is to be sent
0N/A * to the client. It is non-null if the authentication must be continued
0N/A * by sending a challenge to the client, or if the authentication has
0N/A * succeeded but challenge data needs to be processed by the client.
0N/A * <tt>isComplete()</tt> should be called
0N/A * after each call to <tt>evaluateResponse()</tt>,to determine if any further
0N/A * response is needed from the client.
0N/A *
0N/A * @param response The non-null (but possibly empty) response sent
0N/A * by the client.
0N/A *
0N/A * @return The possibly null challenge to send to the client.
0N/A * It is null if the authentication has succeeded and there is
0N/A * no more challenge data to be sent to the client.
0N/A * @exception SaslException If an error occurred while processing
0N/A * the response or generating a challenge.
0N/A */
0N/A public abstract byte[] evaluateResponse(byte[] response)
0N/A throws SaslException;
0N/A
0N/A /**
0N/A * Determines whether the authentication exchange has completed.
0N/A * This method is typically called after each invocation of
0N/A * <tt>evaluateResponse()</tt> to determine whether the
0N/A * authentication has completed successfully or should be continued.
0N/A * @return true if the authentication exchange has completed; false otherwise.
0N/A */
0N/A public abstract boolean isComplete();
0N/A
0N/A /**
0N/A * Reports the authorization ID in effect for the client of this
0N/A * session.
0N/A * This method can only be called if isComplete() returns true.
0N/A * @return The authorization ID of the client.
0N/A * @exception IllegalStateException if this authentication session has not completed
0N/A */
0N/A public String getAuthorizationID();
0N/A
0N/A /**
0N/A * Unwraps a byte array received from the client.
0N/A * This method can be called only after the authentication exchange has
0N/A * completed (i.e., when <tt>isComplete()</tt> returns true) and only if
0N/A * the authentication exchange has negotiated integrity and/or privacy
0N/A * as the quality of protection; otherwise,
0N/A * an <tt>IllegalStateException</tt> is thrown.
0N/A *<p>
0N/A * <tt>incoming</tt> is the contents of the SASL buffer as defined in RFC 2222
0N/A * without the leading four octet field that represents the length.
0N/A * <tt>offset</tt> and <tt>len</tt> specify the portion of <tt>incoming</tt>
0N/A * to use.
0N/A *
0N/A * @param incoming A non-null byte array containing the encoded bytes
0N/A * from the client.
0N/A * @param offset The starting position at <tt>incoming</tt> of the bytes to use.
0N/A * @param len The number of bytes from <tt>incoming</tt> to use.
0N/A * @return A non-null byte array containing the decoded bytes.
0N/A * @exception SaslException if <tt>incoming</tt> cannot be successfully
0N/A * unwrapped.
0N/A * @exception IllegalStateException if the authentication exchange has
0N/A * not completed, or if the negotiated quality of protection
0N/A * has neither integrity nor privacy
0N/A */
0N/A public abstract byte[] unwrap(byte[] incoming, int offset, int len)
0N/A throws SaslException;
0N/A
0N/A /**
0N/A * Wraps a byte array to be sent to the client.
0N/A * This method can be called only after the authentication exchange has
0N/A * completed (i.e., when <tt>isComplete()</tt> returns true) and only if
0N/A * the authentication exchange has negotiated integrity and/or privacy
0N/A * as the quality of protection; otherwise, a <tt>SaslException</tt> is thrown.
0N/A *<p>
0N/A * The result of this method
0N/A * will make up the contents of the SASL buffer as defined in RFC 2222
0N/A * without the leading four octet field that represents the length.
0N/A * <tt>offset</tt> and <tt>len</tt> specify the portion of <tt>outgoing</tt>
0N/A * to use.
0N/A *
0N/A * @param outgoing A non-null byte array containing the bytes to encode.
0N/A * @param offset The starting position at <tt>outgoing</tt> of the bytes to use.
0N/A * @param len The number of bytes from <tt>outgoing</tt> to use.
0N/A * @return A non-null byte array containing the encoded bytes.
0N/A * @exception SaslException if <tt>outgoing</tt> cannot be successfully
0N/A * wrapped.
0N/A * @exception IllegalStateException if the authentication exchange has
0N/A * not completed, or if the negotiated quality of protection has
0N/A * neither integrity nor privacy.
0N/A */
0N/A public abstract byte[] wrap(byte[] outgoing, int offset, int len)
0N/A throws SaslException;
0N/A
0N/A /**
0N/A * Retrieves the negotiated property.
0N/A * This method can be called only after the authentication exchange has
0N/A * completed (i.e., when <tt>isComplete()</tt> returns true); otherwise, an
0N/A * <tt>IllegalStateException</tt> is thrown.
0N/A *
0N/A * @param propName the property
0N/A * @return The value of the negotiated property. If null, the property was
0N/A * not negotiated or is not applicable to this mechanism.
0N/A * @exception IllegalStateException if this authentication exchange has not completed
0N/A */
0N/A
0N/A public abstract Object getNegotiatedProperty(String propName);
0N/A
0N/A /**
0N/A * Disposes of any system resources or security-sensitive information
0N/A * the SaslServer might be using. Invoking this method invalidates
0N/A * the SaslServer instance. This method is idempotent.
0N/A * @throws SaslException If a problem was encountered while disposing
0N/A * the resources.
0N/A */
0N/A public abstract void dispose() throws SaslException;
0N/A}