If it is an entry, then you won't find it in the attributes list. You need to look up the entry explicitly. Here is an integration test that succeeds if there is a subnode "cn=pwdReset", and fails if there is none:
Code:
@Autowired
private LdapTemplate tested;
...
@Test
public void testLookupPwdResetAsSubNode() {
Object result = null;
try {
result = tested.lookup("cn=pwdReset,cn=Some Person,ou=company1,c=Sweden");
}
catch (NameNotFoundException e) {
// do nothing, which should leave result as null
}
assertNotNull("null result means cn=pwdReset was not found", result);
}
If there are attributes in this subnode that you need to examine, you can either do that directly in the ContextMapper or add the attributes to a Map and do it afterwards, like here:
Code:
@Test
public void testLookupPwdResetAsSubNodeAndExamineAttributes() {
SimpleLdapTemplate simpleLdapTemplate = new SimpleLdapTemplate(tested);
ParameterizedContextMapper<Map<String, String>> mapper = new ParameterizedContextMapper<Map<String, String>>() {
public Map<String, String> mapFromContext(Object ctx) {
DirContextAdapter adapter = (DirContextAdapter) ctx;
HashMap<String, String> map = new HashMap<String, String>();
map.put("description", adapter.getStringAttribute("description"));
map.put("l", adapter.getStringAttribute("l"));
return map;
}
};
Map<String, String> result = null;
try {
result = simpleLdapTemplate.lookup("cn=pwdReset,cn=Some Person,ou=company1,c=Sweden",
mapper);
}
catch (NameNotFoundException e) {
// do nothing, which should leave result as null
}
assertNotNull("null result means cn=pwdReset was not found", result);
assertEquals("This user has successfully reset his/her password", result.get("description"));
assertEquals("Whad did the 'l' attribute mean again?", result.get("l"));
}
You can also search for all pwdReset subnodes, in order to find all users that have reset their password:
Code:
@Test
public void testSearchForAllPwdResetSubNodes() {
List list = tested.search("", "(cn=pwdReset)", new AbstractContextMapper() {
@Override
protected Object doMapFromContext(DirContextOperations ctx) {
return ctx.getDn();
}
});
assertEquals(1, list.size());
DistinguishedName dn = (DistinguishedName) list.get(0);
dn.removeLast();
assertEquals("cn=Some Person,ou=company1,c=Sweden", dn.toString());
}
Note that you need to remove the leaf from the DN in order to get the user's DN. I simply assert the DN is correct. You might want to perform another lookup on the user DN to get the user attributes.
This subnode business seems a bit odd, though. Isn't there already a password policy in Active Directory, implemented as operational attributes?