ExternalSASLMechanismHandler.java revision 1008
/*
* 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
* 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
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. 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
*
*
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
/**
* This class provides an implementation of a SASL mechanism that relies on some
* form of authentication that has already been done outside the LDAP layer. At
* the present time, this implementation only provides support for SSL-based
* clients that presented their own certificate to the Directory Server during
* the negotiation process. Future implementations may be updated to look in
* other places to find and evaluate this external authentication information.
*/
public class ExternalSASLMechanismHandler
implements ConfigurationChangeListener<
{
// The attribute type that should hold the certificates to use for the
// validation.
private AttributeType certificateAttributeType;
// Indicates whether to attempt to validate the certificate presented by the
// client with a certificate in the user's entry.
// The DN of the configuration entry for this SASL mechanism handler.
private DN configEntryDN;
// 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 ExternalSASLMechanismHandler()
{
super();
}
/**
* {@inheritDoc}
*/
@Override()
public void initializeSASLMechanismHandler(
{
// See if we should attempt to validate client certificates against those in
// the corresponding user's entry.
switch (configuration.getCertificateValidationPolicy())
{
case NEVER:
break;
case IFPRESENT:
break;
case ALWAYS:
break;
}
// Get the attribute type to use for validating the certificates. If none
// is provided, then default to the userCertificate type.
if (attrTypeName == null)
{
}
if (certificateAttributeType == null)
{
}
// Make sure that the configured certificate mapper is valid.
if (certificateMapper == null)
{
}
}
/**
* {@inheritDoc}
*/
@Override()
public void finalizeSASLMechanismHandler()
{
}
/**
* {@inheritDoc}
*/
@Override()
{
// Get the client connection used for the bind request, and get the
// security manager for that connection. If either are null, then fail.
if (clientConnection == null)
{
return;
}
if (securityProvider == null)
{
return;
}
// Make sure that the client connection is using the TLS security provider.
// If not, then fail.
if (! (securityProvider instanceof TLSConnectionSecurityProvider))
{
return;
}
// Get the certificate chain that the client presented to the server, if
// possible. If there isn't one, then fail.
{
return;
}
// Get the certificate mapper to use to map the certificate to a user entry.
if (certificateMapper == null)
{
return;
}
// Use the Directory Server certificate mapper to map the client certificate
// chain to a single user DN.
try
{
}
catch (DirectoryException de)
{
if (debugEnabled())
{
}
return;
}
// If the user DN is null, then we couldn't establish a mapping and
// therefore the authentication failed.
{
return;
}
else
{
}
// Get the userCertificate attribute from the user's entry for use in the
// validation process.
switch (validationPolicy)
{
case ALWAYS:
if (certAttrList == null)
{
{
return;
}
}
else
{
try
{
AttributeValue v =
new ASN1OctetString(certBytes));
boolean found = false;
for (Attribute a : certAttrList)
{
if (a.hasValue(v))
{
found = true;
break;
}
}
if (! found)
{
return;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return;
}
}
break;
case IFPRESENT:
if (certAttrList != null)
{
try
{
AttributeValue v =
new ASN1OctetString(certBytes));
boolean found = false;
for (Attribute a : certAttrList)
{
if (a.hasValue(v))
{
found = true;
break;
}
}
if (! found)
{
return;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return;
}
}
}
}
/**
* {@inheritDoc}
*/
@Override()
{
// This is not a password-based mechanism.
return false;
}
/**
* {@inheritDoc}
*/
@Override()
{
// This may be considered a secure mechanism.
return true;
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
boolean configAcceptable = true;
// Get the attribute type to use for validating the certificates. If none
// is provided, then default to the userCertificate type.
if (attrTypeName != null)
{
}
if (newCertificateType == null)
{
configAcceptable = false;
}
// Make sure that the configured certificate mapper is valid.
if (certificateMapper == null)
{
configAcceptable = false;
}
return configAcceptable;
}
/**
* {@inheritDoc}
*/
{
boolean adminActionRequired = false;
// See if we should attempt to validate client certificates against those in
// the corresponding user's entry.
switch (configuration.getCertificateValidationPolicy())
{
case NEVER:
break;
case IFPRESENT:
break;
case ALWAYS:
break;
}
// Get the attribute type to use for validating the certificates. If none
// is provided, then default to the userCertificate type.
if (attrTypeName == null)
{
}
if (newCertificateType == null)
{
{
}
}
{
}
}
}