Вот пример использования для всех, кому интересно.Он автоматически загружает пользовательские данные из ldap при чтении organizationalRole
.
UserRole
класса:
@LDAPObject(structuralClass="organizationalRole", defaultParentDN="dc=Roles,dc=example,dc=com")
public class UserRole extends LDAPModel implements models.deadbolt.Role {
@LDAPField(attribute="cn",inRDN=true,filterUsage=FilterUsage.ALWAYS_ALLOWED)
public String name;
private List<User> members;
public List<User> getMembers() {
return members;
}
/**
* Called when creating a Java object from an LDAP entry.
*/
@LDAPSetter(attribute="roleOccupant")
void initMembers(String[] occupants) throws LDAPException {
members = new ArrayList<User>();
if (occupants == null || occupants.length == 0)
return;
for (String dn : occupants)
members.add(User.findByDN(dn));
}
/**
* Called when turning a Java object into an LDAP entry.
*/
@LDAPGetter(attribute="roleOccupant")
String[] storeMembers() {
if (members == null)
return null;
String[] member_strings = new String[members.size()];
for (int i = 0; i < members.size(); i++)
member_strings[i] = members.get(i).getDN();
return member_strings;
}
}
User
класса:
@LDAPObject(structuralClass="inetOrgPerson",
auxiliaryClass={"mozillaOrgPerson","posixAccount","sambaSamAccount","shadowAccount"},
defaultParentDN="dc=People,dc=example,dc=com")
public class User extends LDAPModel implements RoleHolder {
...
@LDAPField(attribute="givenName",filterUsage=FilterUsage.ALWAYS_ALLOWED)
public String fname;
@LDAPField(attribute="sn",filterUsage=FilterUsage.ALWAYS_ALLOWED)
public String lname;
public static User findByDN(String dn) throws LDAPException {
LDAPConnection conn = ...
LDAPPersister<User> persister = LDAPPersister.getInstance(User.class);
return persister.get(dn, conn);
}