Le 12/17/12 11:18 PM, Anthony Dahanne a écrit :
> Hello all,
> Using ApacheDS for tests, I would like to simulate a scenario where the
> user of our software authenticates/authorizes against a directory using the
> NIS schema.
> I'm using Apache DS 1.5.7 annotations, such as :
>
> @RunWith(value = FrameworkRunner.class)
> @CreateDS( allowAnonAccess=true, name="AddIT-class",
> partitions =
> {
> @CreatePartition(
> name = "mycompany",
> suffix = "dc=mycompany,dc=com",
> contextEntry = @ContextEntry(
> entryLdif =
> "dn: dc=mycompany,dc=com\n" +
> "dc: mycompany\n" +
> "objectClass: top\n" +
> "objectClass: domain\n\n" ),
> indexes =
> {
> @CreateIndex( attribute = "objectClass" ),
> @CreateIndex( attribute = "dc" ),
> @CreateIndex( attribute = "ou" )
> } )
> })
> @CreateLdapServer(
> transports =
> {
> @CreateTransport( protocol = "LDAP" )
> })
> @ApplyLdifs( {
> // the users organizationalUnit
> "dn: ou=users,dc=mycompany,dc=com",
> "objectClass: organizationalUnit",
> "objectClass: top",
> "ou: users",
> "description: Users",
>
> // the groups organizationalUnit
> "dn: ou=groups,dc=mycompany,dc=com",
> "objectClass: organizationalUnit",
> "objectClass: top",
> "ou: groups",
> "description: Groups",
>
>
> // operators group
> "dn: cn=operators,ou=groups,dc=mycompany,dc=com",
> "objectClass: groupOfNames",
> "objectClass: top",
> "cn: operators",
> "gidNumber: 43",
> "description: Operators Group",
>
>
> // admins group
> "dn: cn=admins,ou=groups,dc=mycompany,dc=com",
> "objectClass: groupOfNames",
> "objectClass: top",
> "cn: admins",
> "gidNumber: 42",
> "description: Operators Group",
> etc....
>
>
> See those latest groups, with gidNumber:xxx ?
> well , apache ds refuses to create them with the error :
>
> org.apache.directory.shared.ldap.exception.LdapSchemaViolationException:
> ERR_279 Required attributes [2.5.4.31] not found within entry
> cn=operators,ou=groups,dc=mycompany,dc=com
>
> which is normal because by default the NIS schema is not loaded
> I know that I need to set “m-disabled” attribute of the NIS schema to
> FALSE; I already did using Apache Directory Studio once.
> But how can I , using the annotations configuration, set this property to
> false ?
Sadly, you can't. But you are not necessarily in a dead end here.
You can still inject the @ApplyLdif on a method, instead of inject it at
the class level. That let you enable the NS partition in a @BeforeClass
method.
Something like :
@RunWith(value = FrameworkRunner.class)
@CreateDS( allowAnonAccess=true, name="AddIT-class",
partitions =
{
@CreatePartition(
name = "mycompany",
suffix = "dc=mycompany,dc=com",
contextEntry = @ContextEntry(
entryLdif =
"dn: dc=mycompany,dc=com\n" +
"dc: mycompany\n" +
"objectClass: top\n" +
"objectClass: domain\n\n" ),
indexes =
{
@CreateIndex( attribute = "objectClass" ),
@CreateIndex( attribute = "dc" ),
@CreateIndex( attribute = "ou" )
} )
})
@CreateLdapServer(
transports =
{
@CreateTransport( protocol = "LDAP" )
})
public class MyTest
{
@BeforeClass
static public void enableNis() throws Exception
{
connection = IntegrationUtils.getAdminConnection(
getService() );
Entry nisEntry = connection.lookup( "cn=nis,ou=schema" );
boolean isNisDisabled = nisEntry.contains( "m-disabled",
"TRUE" );
// if nis is disabled then enable it
if ( isNisDisabled )
{
connection.modify( "cn=nis,ou=schema", new
DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
"m-disabled", "TRUE" ) );
}
}
@ApplyLdifs( {
// the users organizationalUnit
"dn: ou=users,dc=mycompany,dc=com",
"objectClass: organizationalUnit",
"objectClass: top",
"ou: users",
"description: Users",
// the groups organizationalUnit
"dn: ou=groups,dc=mycompany,dc=com",
"objectClass: organizationalUnit",
"objectClass: top",
"ou: groups",
"description: Groups" })
@Test
public void myTest()
{
blah...
That should work.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com