SubjectDNToUserAttributeCertificateMapperTestCase.java revision d25372dc8e65a9ed019a88fdf659ca61313f1b31
/*
* 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
*
*
* Copyright 2008 Sun Microsystems, Inc.
*/
/**
* A set of test cases for the Subject DN to User Attribute certificate mapper.
*/
public class SubjectDNToUserAttributeCertificateMapperTestCase
extends ExtensionsTestCase
{
/**
* Ensures that the Directory Server is running.
*
* @throws Exception If an unexpected problem occurs.
*/
@BeforeClass()
public void startServer()
throws Exception
{
}
/**
* Retrieves a set of invalid configurations that cannot be used to
* initialize the certificate mapper.
*
* @throws Exception If an unexpected problem occurs.
*/
public Object[][] getInvalidConfigurations()
throws Exception
{
"dn: cn=No Subject Attr,cn=Certificate Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-certificate-mapper",
"objectClass: ds-cfg-subject-dn-to-user-attribute-certificate-mapper",
"cn: No Subject Attr",
"ds-cfg-java-class: org.opends.server.extensions." +
"SubjectDNToUserAttributeCertificateMapper",
"ds-cfg-enabled: true",
"",
"dn: cn=Undefined Subject Attr,cn=Certificate Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-certificate-mapper",
"objectClass: ds-cfg-subject-dn-to-user-attribute-certificate-mapper",
"cn: Undefined Subject Attr",
"ds-cfg-java-class: org.opends.server.extensions." +
"SubjectDNToUserAttributeCertificateMapper",
"ds-cfg-enabled: true",
"ds-cfg-subject-attribute: undefined",
"",
"dn: cn=Invalid Base DN,cn=Certificate Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-certificate-mapper",
"objectClass: ds-cfg-subject-dn-to-user-attribute-certificate-mapper",
"cn: Invalid Base DN",
"ds-cfg-java-class: org.opends.server.extensions." +
"SubjectDNToUserAttributeCertificateMapper",
"ds-cfg-enabled: true",
"ds-cfg-subject-attribute: ds-certificate-subject-dn",
"ds-cfg-user-base-dn: invalid");
{
}
return configEntries;
}
/**
* Tests initialization with an invalid configuration.
*
* @param e The configuration entry to use to initialize the certificate
* mapper.
*
* @throws Exception If an unexpected problem occurs.
*/
expectedExceptions = { ConfigException.class,
InitializationException.class })
public void testInvalidConfigs(Entry e)
throws Exception
{
getInstance(), e);
}
/**
* Tests a successful mapping using the default configuration.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSuccessfulMappingDefaultConfig()
throws Exception
{
enableMapper();
try
{
"dn: uid=test.user,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"objectClass: ds-certificate-user",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"ds-certificate-subject-dn: CN=Test User, O=Test");
{
"--noPropertiesFile",
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"-r",
"-b", "",
"-s", "base",
"(objectClass=*)"
};
}
finally
{
}
}
/**
* Tests a successful mapping using a configuration with a different subject
* attribute.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSuccessfulMappingAlternateSubjectAttribute()
throws Exception
{
enableMapper();
try
{
setSubjectAttribute("manager");
"dn: uid=test.user,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"objectClass: ds-certificate-user",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"manager: CN=Test User, O=Test");
{
"--noPropertiesFile",
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"-r",
"-b", "",
"-s", "base",
"(objectClass=*)"
};
}
finally
{
setSubjectAttribute("ds-certificate-subject-dn");
}
}
/**
* Tests a successful mapping using a configuration with a different set of
* base DNs.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSuccessfulMappingAlternateBaseDNs()
throws Exception
{
enableMapper();
try
{
"dn: uid=test.user,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"objectClass: ds-certificate-user",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"ds-certificate-subject-dn: CN=Test User, O=Test");
{
"--noPropertiesFile",
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"-r",
"-b", "",
"-s", "base",
"(objectClass=*)"
};
}
finally
{
setSubjectAttribute("ds-certificate-subject-dn");
}
}
/**
* Tests a failed mapping when there are no users that should match.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFailedMappingNoUsers()
throws Exception
{
enableMapper();
try
{
"dn: cn=Test User,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"objectClass: ds-certificate-user",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User");
{
"--noPropertiesFile",
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"-r",
"-b", "",
"-s", "base",
"(objectClass=*)"
};
}
finally
{
}
}
/**
* Tests a failed mapping when there are multiple users that match the
* critieria.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFailedMappingMultipleUsers()
throws Exception
{
enableMapper();
try
{
"dn: uid=test.user1,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"objectClass: ds-certificate-user",
"uid: test.user1",
"givenName: Test",
"sn: User",
"cn: Test User 1",
"ds-certificate-subject-dn: CN=Test User, O=Test",
"",
"dn: uid=test.user2,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"objectClass: ds-certificate-user",
"uid: test.user2",
"givenName: Test",
"sn: User",
"cn: Test User 2",
"ds-certificate-subject-dn: CN=Test User, O=Test");
{
"--noPropertiesFile",
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"-r",
"-b", "",
"-s", "base",
"(objectClass=*)"
};
}
finally
{
}
}
/**
* Tests a failed mapping when there are no users below the configured base
* DNs that match the criteria.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFailedMappingNoUserBelowBaseDNs()
throws Exception
{
enableMapper();
try
{
"dn: uid=test.user,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"objectClass: ds-certificate-user",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"ds-certificate-subject-dn: CN=Test User, O=Test");
{
"--noPropertiesFile",
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"-r",
"-b", "",
"-s", "base",
"(objectClass=*)"
};
}
finally
{
}
}
/**
* Tests to ensure that an attmept to remove the subject attribute will fail.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testRemoveSubjectAttribute()
throws Exception
{
"cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config";
Attribute a =
"ds-cfg-subject-attribute"));
}
/**
* Tests to ensure that an attmept to set an undefined subject attribute will
* fail.
*
* @throws Exception If an unexpected problem occurs.
*/
public void testSetUndefinedSubjectAttribute()
throws Exception
{
setSubjectAttribute("undefined");
}
/**
* Tests to ensure that an attmept to set an invalid base DN will fail.
*
* @throws Exception If an unexpected problem occurs.
*/
public void testSetInvalidBaseDN()
throws Exception
{
}
/**
* Alters the configuration of the SASL EXTERNAL mechanism handler so that it
* uses the Subject DN to User Attribute certificate mapper.
*
* @throws Exception If an unexpected problem occurs.
*/
private void enableMapper()
throws Exception
{
"cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config";
mapperDN)));
}
/**
* Alters the configuration of the SASL EXTERNAL mechanism handler so that it
* uses the Subject Equals DN certificate mapper.
*
* @throws Exception If an unexpected problem occurs.
*/
private void disableMapper()
throws Exception
{
mapperDN)));
}
/**
* Alters the configuration of the Subject DN to User Attribute certificate
* mapper so that it will look for the subject DN in the specified attribute.
*
* @param attrName The name of the attribute in which to look for the
* certificate subject.
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
"cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config";
attrName)));
}
/**
* Alters the configuration of the Subject DN to User Attribute certificate
* mapper so that it will look for the subject DN below the specified set of
* base DNs.
*
* @param baseDNs The set of base DNs to use when mapping certificates to
* users.
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
"cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config";
{
{
}
}
builder.toAttribute()));
}
}