public void test11InvalidateCredentialCache() throws Exception
{
apply( service, getUserAddLdif() );
String userDn = "uid=akarasulu,ou=users,ou=system";
LdapContext ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
assertNotNull( ctx );
Attributes attrs = ctx.getAttributes( "" );
Attribute ou = attrs.get( "ou" );
assertTrue( ou.contains( "Engineering" ) );
assertTrue( ou.contains( "People" ) );
Attribute objectClass = attrs.get( "objectClass" );
assertTrue( objectClass.contains( "top" ) );
assertTrue( objectClass.contains( "person" ) );
assertTrue( objectClass.contains( "organizationalPerson" ) );
assertTrue( objectClass.contains( "inetOrgPerson" ) );
assertTrue( attrs.get( "telephonenumber" ).contains( "+1 408 555 4798" ) );
assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
assertTrue( attrs.get( "givenname" ).contains( "Alex" ) );
assertTrue( attrs.get( "mail" ).contains( "akarasulu@apache.org" ) );
assertTrue( attrs.get( "l" ).contains( "Bogusville" ) );
assertTrue( attrs.get( "sn" ).contains( "Karasulu" ) );
assertTrue( attrs.get( "cn" ).contains( "Alex Karasulu" ) );
assertTrue( attrs.get( "facsimiletelephonenumber" ).contains( "+1 408 555 9751" ) );
assertTrue( attrs.get( "roomnumber" ).contains( "4612" ) );
// now modify the password for akarasulu
Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "newpwd" );
ctx.modifyAttributes( "", new ModificationItem[] {
new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
// close and try with old password (should fail)
ctx.close();
try
{
new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "test".getBytes() ), new LdapDN( userDn ) );
fail( "Authentication with old password should fail" );
}
catch ( NamingException e )
{
// we should fail
}
// close and try again now with new password (should fail)
ctx.close();
ctx = new ServerLdapContext( service,
service.getSession( new LdapDN( userDn ), "newpwd".getBytes() ), new LdapDN( userDn ) );
attrs = ctx.getAttributes( "" );
ou = attrs.get( "ou" );
assertTrue( ou.contains( "Engineering" ) );
assertTrue( ou.contains( "People" ) );
objectClass = attrs.get( "objectClass" );