SubjectAttributeToUserAttributeCertificateMapper.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
* Portions Copyright 2013 Manuel Gaupp
*/
/**
* This class implements a very simple Directory Server certificate mapper that
* will map a certificate to a user based on attributes contained in both the
* certificate subject and the user's entry. The configuration may include
* mappings from certificate attributes to attributes in user entries, and all
* of those certificate attributes that are present in the subject will be used
* to search for matching user entries.
*/
public class SubjectAttributeToUserAttributeCertificateMapper
extends CertificateMapper<
implements ConfigurationChangeListener<
{
// The DN of the configuration entry for this certificate mapper.
private DN configEntryDN;
// The mappings between certificate attribute names and user attribute types.
// 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(
{
// Get and validate the subject attribute to user attribute mappings.
{
if (colonPos <= 0)
{
throw new ConfigException(message);
}
{
throw new ConfigException(message);
}
// Try to normalize the provided certAttrName
{
throw new ConfigException(message);
}
if (userAttrType == null)
{
throw new ConfigException(message);
}
{
{
throw new ConfigException(ERR_SATUACM_DUPLICATE_USER_ATTR.get(configEntryDN, attrType.getNameOrOID()));
}
}
}
// Make sure that all the user attributes are configured with equality
// indexes 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.
try
{
}
catch (DirectoryException de)
{
de);
}
{
{
// Try to normalize lowerName
{
rdn.getAttributeValue(j)));
}
}
}
if (filterComps.isEmpty())
{
}
// 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.
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(
{
boolean configAcceptable = true;
// Get and validate the subject attribute to user attribute mappings.
{
if (colonPos <= 0)
{
configAcceptable = false;
break;
}
{
configAcceptable = false;
break;
}
// Try to normalize the provided certAttrName
{
configAcceptable = false;
break;
}
if (userAttrType == null)
{
configAcceptable = false;
break;
}
{
{
configAcceptable = false;
break mapLoop;
}
}
}
return configAcceptable;
}
/**
* {@inheritDoc}
*/
{
// Get and validate the subject attribute to user attribute mappings.
{
if (colonPos <= 0)
{
break;
}
{
break;
}
// Try to normalize the provided certAttrName
{
break;
}
if (userAttrType == null)
{
break;
}
{
{
break mapLoop;
}
}
}
// Make sure that all the user attributes are configured with equality
// indexes in all appropriate backends.
{
}
{
{
{
}
}
}
{
}
return ccr;
}
/**
* Tries to normalize the given attribute name; if normalization is not
* possible the original String value is returned.
*
* @param attrName The attribute name which should be normalized.
*
* @return The normalized attribute name.
*/
{
{
if (attrNameNormalized != null)
{
}
}
return attrName;
}
}