FingerprintCertificateMapper.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 2007-2008 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS
*/
/**
* This class implements a very simple Directory Server certificate mapper that
* will map a certificate to a user only if that user's entry contains an
* attribute with the fingerprint of the client certificate. There must be
* exactly one matching user entry for the mapping to be successful.
*/
public class FingerprintCertificateMapper
implements ConfigurationChangeListener<
{
// The DN of the configuration entry for this certificate mapper.
private DN configEntryDN;
// The current configuration for this certificate mapper.
// The algorithm that will be used to generate the fingerprint.
private String fingerprintAlgorithm;
// The set of attributes to return in search result entries.
/**
* Creates a new instance of this certificate mapper. Note that all actual
* initialization should be done in the
* <CODE>initializeCertificateMapper</CODE> method.
*/
public FingerprintCertificateMapper()
{
super();
}
/**
* {@inheritDoc}
*/
public void initializeCertificateMapper(
{
// Get the algorithm that will be used to generate the fingerprint.
switch (configuration.getFingerprintAlgorithm())
{
case MD5:
fingerprintAlgorithm = "MD5";
break;
case SHA1:
fingerprintAlgorithm = "SHA1";
break;
}
// Make sure that the fingerprint attribute is configured for equality in
// all appropriate backends.
{
}
{
{
t.getNameOrOID(), b.getBackendID());
}
}
// Create the attribute list to include in search requests. We want to
// include all user and operational attributes.
}
/**
* {@inheritDoc}
*/
public void finalizeCertificateMapper()
{
}
/**
* {@inheritDoc}
*/
throws DirectoryException
{
// Make sure that a peer certificate was provided.
{
}
// Get the first certificate in the chain. It must be an X.509 certificate.
try
{
}
catch (Exception e)
{
logger.traceException(e);
}
// Get the signature from the peer certificate and create a digest of it
// using the configured algorithm.
try
{
}
catch (Exception e)
{
logger.traceException(e);
}
// Create the search filter from the fingerprint.
// If we have an explicit set of base DNs, then use it. Otherwise, use the
// set of public naming contexts in the server.
{
}
// For each base DN, issue an internal search in an attempt to map the
// certificate.
{
.setSizeLimit(1)
.setTimeLimit(10)
{
case SUCCESS:
// This is fine. No action needed.
break;
case NO_SUCH_OBJECT:
// The search base doesn't exist. Not an ideal situation, but we'll
// ignore it.
break;
case SIZE_LIMIT_EXCEEDED:
// Multiple entries matched the filter. This is not acceptable.
throw new DirectoryException(
case TIME_LIMIT_EXCEEDED:
case ADMIN_LIMIT_EXCEEDED:
// The search criteria was too inefficient.
message);
default:
// Just pass on the failure that was returned for this search.
message);
}
{
{
}
else
{
}
}
}
// If we've gotten here, then we either found exactly one user entry or we
// didn't find any. Either way, return the entry or null to the caller.
return userEntry;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
boolean configAcceptable = true;
return configAcceptable;
}
/**
* {@inheritDoc}
*/
{
// Get the algorithm that will be used to generate the fingerprint.
switch (configuration.getFingerprintAlgorithm())
{
case MD5:
newFingerprintAlgorithm = "MD5";
break;
case SHA1:
newFingerprintAlgorithm = "SHA1";
break;
}
{
}
// Make sure that the fingerprint attribute is configured for equality in
// all appropriate backends.
{
}
{
{
}
}
return ccr;
}
}