SubjectDNToUserAttributeCertificateMapper.java revision a89f7014aeb71dba5c94404dfea7eb89e7eeee74
/*
* 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 subject of the client certificate. There must be exactly
* one matching user entry for the mapping to be successful.
*/
public class SubjectDNToUserAttributeCertificateMapper
extends CertificateMapper<
implements ConfigurationChangeListener<
{
/** The DN of the configuration entry for this certificate mapper. */
private DN configEntryDN;
/** The current configuration for this certificate mapper. */
/** 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.
*/
{
super();
}
/** {@inheritDoc} */
public void initializeCertificateMapper(
{
// Make sure that the subject 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 subject from the peer certificate and use it to create a search
// filter.
// 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.
peerName);
throw new DirectoryException(
case TIME_LIMIT_EXCEEDED:
case ADMIN_LIMIT_EXCEEDED:
// The search criteria was too inefficient.
default:
// Just pass on the failure that was returned for this search.
}
{
{
}
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(
{
return true;
}
/** {@inheritDoc} */
{
return new ConfigChangeResult();
}
}