PlainSASLMechanismHandler.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS.
*/
/**
* This class provides an implementation of a SASL mechanism that uses
* plain-text authentication. It is based on the proposal defined in
* draft-ietf-sasl-plain-08 in which the SASL credentials are in the form:
* <BR>
* <BLOCKQUOTE>[authzid] UTF8NULL authcid UTF8NULL passwd</BLOCKQUOTE>
* <BR>
* Note that this is a weak mechanism by itself and does not offer any
* protection for the password, so it may need to be used in conjunction with a
* connection security provider to prevent exposing the password.
*/
public class PlainSASLMechanismHandler
implements ConfigurationChangeListener<
{
/** The identity mapper that will be used to map ID strings to user entries.*/
private IdentityMapper<?> identityMapper;
/** The current configuration for this SASL mechanism handler. */
/**
* Creates a new instance of this SASL mechanism handler. No initialization
* should be done in this method, as it should all be performed in the
* <CODE>initializeSASLMechanismHandler</CODE> method.
*/
public PlainSASLMechanismHandler()
{
super();
}
/**
* {@inheritDoc}
*/
public void initializeSASLMechanismHandler(
{
// Get the identity mapper that should be used to find users.
}
/**
* {@inheritDoc}
*/
public void finalizeSASLMechanismHandler()
{
}
/**
* {@inheritDoc}
*/
{
// Get the SASL credentials provided by the user and decode them.
if (saslCredentials == null)
{
return;
}
if (nullPos1 < 0)
{
return;
}
if (nullPos1 > 0)
{
}
if (nullPos2 < 0)
{
return;
}
{
return;
}
{
return;
}
// Get the user entry for the authentication ID. Allow for an
// authentication ID that is just a username (as per the SASL PLAIN spec),
// but also allow a value in the authzid form specified in RFC 2829.
{
// Try to decode the user DN and retrieve the corresponding entry.
try
{
}
catch (DirectoryException de)
{
return;
}
{
return;
}
{
}
// Acquire a read lock on the user entry. If this fails, then so will the
// authentication.
{
return;
}
try
{
}
catch (DirectoryException de)
{
LocalizableMessage message = ERR_SASLPLAIN_CANNOT_GET_ENTRY_BY_DN.get(userDN, de.getMessageObject());
return;
}
finally
{
}
}
else
{
// Use the identity mapper to resolve the username to an entry.
{
}
try
{
}
catch (DirectoryException de)
{
return;
}
}
// At this point, we should have a user entry. If we don't then fail.
{
return;
}
else
{
}
// If an authorization ID was provided, then make sure that it is
// acceptable.
{
{
try
{
}
catch (DirectoryException de)
{
return;
}
if (actualAuthzDN != null)
{
}
{
{
LocalizableMessage message = ERR_SASLPLAIN_AUTHZID_INSUFFICIENT_PRIVILEGES.get(userEntry.getName());
return;
}
{
authZEntry = null;
}
else
{
try
{
if (authZEntry == null)
{
return;
}
}
catch (DirectoryException de)
{
LocalizableMessage message = ERR_SASLPLAIN_AUTHZID_CANNOT_GET_ENTRY.get(authzDN, de.getMessageObject());
return;
}
}
}
}
else
{
{
}
else
{
}
{
authZEntry = null;
}
else
{
try
{
if (authZEntry == null)
{
authzID);
return;
}
}
catch (DirectoryException de)
{
return;
}
}
if ((authZEntry == null) ||
{
{
LocalizableMessage message = ERR_SASLPLAIN_AUTHZID_INSUFFICIENT_PRIVILEGES.get(userEntry.getName());
return;
}
}
}
}
// Get the password policy for the user and use it to determine if the
// provided password was correct.
try
{
// FIXME: we should store store the auth state in with the bind operation
// so that any state updates, such as cached passwords, are persisted to
// the user's entry when the bind completes.
userEntry, false);
if (authState.isDisabled())
{
// Check to see if the user is administratively disabled or locked.
return;
}
{
return;
}
}
catch (Exception e)
{
logger.traceException(e);
LocalizableMessage message = ERR_SASLPLAIN_CANNOT_CHECK_PASSWORD_VALIDITY.get(userEntry.getName(), e);
return;
}
// If we've gotten here, then the authentication was successful.
return;
}
/**
* {@inheritDoc}
*/
{
// This is a password-based mechanism.
return true;
}
/**
* {@inheritDoc}
*/
{
// This is not a secure mechanism.
return false;
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationAcceptable(
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
return true;
}
/**
* {@inheritDoc}
*/
{
// Get the identity mapper that should be used to find users.
return ccr;
}
}