AnonymousSASLMechanismHandler.java revision 221
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the fields enclosed
0N/A * by brackets "[]" replaced with your own identifying * information:
0N/A * Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
0N/A * Portions Copyright 2006 Sun Microsystems, Inc.
0N/A */
0N/Apackage org.opends.server.extensions;
0N/A
0N/A
0N/A
0N/Aimport org.opends.server.api.SASLMechanismHandler;
0N/Aimport org.opends.server.config.ConfigEntry;
0N/Aimport org.opends.server.config.ConfigException;
0N/Aimport org.opends.server.core.BindOperation;
0N/Aimport org.opends.server.core.DirectoryServer;
0N/Aimport org.opends.server.core.InitializationException;
0N/Aimport org.opends.server.types.AuthenticationInfo;
0N/Aimport org.opends.server.types.ByteString;
0N/Aimport org.opends.server.types.ErrorLogCategory;
0N/Aimport org.opends.server.types.ErrorLogSeverity;
0N/Aimport org.opends.server.types.ResultCode;
0N/A
0N/Aimport static org.opends.server.loggers.Debug.*;
0N/Aimport static org.opends.server.loggers.Error.*;
0N/Aimport static org.opends.server.messages.ExtensionsMessages.*;
0N/Aimport static org.opends.server.util.ServerConstants.*;
0N/A
0N/A
0N/A
0N/A/**
0N/A * This class provides an implementation of a SASL mechanism, as defined in RFC
0N/A * 4505, that does not perform any authentication. That is, anyone attempting
0N/A * to bind with this SASL mechanism will be successful and will be given the
0N/A * rights of an unauthenticated user. The request may or may not include a set
0N/A * of SASL credentials which will serve as trace information. If provided,
0N/A * then that trace information will be written to the server error log.
0N/A */
0N/Apublic class AnonymousSASLMechanismHandler
0N/A extends SASLMechanismHandler
0N/A{
0N/A /**
0N/A * The fully-qualified name of this class for debugging purposes.
0N/A */
0N/A private static final String CLASS_NAME =
0N/A "org.opends.server.extensions.AnonymousSASLMechanismHandler";
0N/A
0N/A
0N/A
0N/A /**
0N/A * Creates a new instance of this SASL mechanism handler. No initialization
0N/A * should be done in this method, as it should all be performed in the
0N/A * <CODE>initializeSASLMechanismHandler</CODE> method.
0N/A */
0N/A public AnonymousSASLMechanismHandler()
0N/A {
0N/A super();
0N/A
0N/A assert debugConstructor(CLASS_NAME);
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Initializes this SASL mechanism handler based on the information in the
0N/A * provided configuration entry. It should also register itself with the
0N/A * Directory Server for the particular kinds of SASL mechanisms that it
0N/A * will process.
0N/A *
0N/A * @param configEntry The configuration entry that contains the information
0N/A * to use to initialize this SASL mechanism handler.
0N/A *
0N/A * @throws ConfigException If an unrecoverable problem arises in the
0N/A * process of performing the initialization.
0N/A *
0N/A * @throws InitializationException If a problem occurs during initialization
0N/A * that is not related to the server
0N/A * configuration.
0N/A */
0N/A public void initializeSASLMechanismHandler(ConfigEntry configEntry)
0N/A throws ConfigException, InitializationException
0N/A {
0N/A assert debugEnter(CLASS_NAME, "initializeSASLMechanismHandler",
0N/A String.valueOf(configEntry));
0N/A
0N/A
0N/A // No real implementation is required. Simply register with the Directory
0N/A // Server for the ANONYMOUS mechanism.
0N/A DirectoryServer.registerSASLMechanismHandler(SASL_MECHANISM_ANONYMOUS,
0N/A this);
0N/A }
0N/A
0N/A
0N/A
221N/A /**
221N/A * Performs any finalization that may be necessary for this SASL mechanism
221N/A * handler.
221N/A */
221N/A public void finalizeSASLMechanismHandler()
221N/A {
221N/A assert debugEnter(CLASS_NAME, "finalizeSASLMechanismHandler");
221N/A
221N/A DirectoryServer.deregisterSASLMechanismHandler(SASL_MECHANISM_ANONYMOUS);
221N/A }
221N/A
221N/A
221N/A
0N/A
0N/A /**
0N/A * Processes the provided SASL bind operation. Note that if the SASL
0N/A * processing gets far enough to be able to map the associated request to a
0N/A * user entry (regardless of whether the authentication is ultimately
0N/A * successful), then this method must call the
0N/A * <CODE>BindOperation.setSASLAuthUserEntry</CODE> to provide it with the
0N/A * entry for the user that attempted to authenticate.
0N/A *
0N/A * @param bindOperation The SASL bind operation to be processed.
0N/A */
0N/A public void processSASLBind(BindOperation bindOperation)
0N/A {
0N/A assert debugEnter(CLASS_NAME, "processSASLBind",
0N/A String.valueOf(bindOperation));
0N/A
0N/A
0N/A // See if the client provided SASL credentials including trace information.
0N/A // If so, then log it to the error log.
0N/A ByteString saslCredentials = bindOperation.getSASLCredentials();
0N/A if (saslCredentials != null)
0N/A {
0N/A String credString = saslCredentials.stringValue();
0N/A if (credString.length() > 0)
0N/A {
0N/A logError(ErrorLogCategory.REQUEST_HANDLING,
0N/A ErrorLogSeverity.INFORMATIONAL, MSGID_SASLANONYMOUS_TRACE,
0N/A bindOperation.getConnectionID(),
0N/A bindOperation.getOperationID(), credString);
0N/A
0N/A }
0N/A }
0N/A
0N/A
0N/A // Authenticate the client anonymously and indicate that the bind was
0N/A // successful.
0N/A AuthenticationInfo authInfo = new AuthenticationInfo();
0N/A bindOperation.getClientConnection().setAuthenticationInfo(authInfo);
0N/A bindOperation.setResultCode(ResultCode.SUCCESS);
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the specified SASL mechanism is password-based or uses
0N/A * some other form of credentials (e.g., an SSL client certificate or Kerberos
0N/A * ticket).
0N/A *
0N/A * @param mechanism The name of the mechanism for which to make the
0N/A * determination. This will only be invoked with names of
0N/A * mechanisms for which this handler has previously
0N/A * registered.
0N/A *
0N/A * @return <CODE>true</CODE> if this SASL mechanism is password-based, or
0N/A * <CODE>false</CODE> if it uses some other form of credentials.
0N/A */
0N/A public boolean isPasswordBased(String mechanism)
0N/A {
0N/A assert debugEnter(CLASS_NAME, "isPasswordBased", String.valueOf(mechanism));
0N/A
0N/A // This is not a password-based mechanism.
0N/A return false;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the specified SASL mechanism should be considered secure
0N/A * (i.e., it does not expose the authentication credentials in a manner that
0N/A * is useful to a third-party observer, and other aspects of the
0N/A * authentication are generally secure).
0N/A *
0N/A * @param mechanism The name of the mechanism for which to make the
0N/A * determination. This will only be invoked with names of
0N/A * mechanisms for which this handler has previously
0N/A * registered.
0N/A *
0N/A * @return <CODE>true</CODE> if this SASL mechanism should be considered
0N/A * secure, or <CODE>false</CODE> if not.
0N/A */
0N/A public boolean isSecure(String mechanism)
0N/A {
0N/A assert debugEnter(CLASS_NAME, "isSecure", String.valueOf(mechanism));
0N/A
0N/A // This is not a secure mechanism.
0N/A return false;
0N/A }
0N/A}
0N/A