/** * {@link Person} object stored inside LDAP. * * @author Mark Paluch */ @Entry(base = "ou=people,dc=springframework,dc=org", objectClasses = "inetOrgPerson") @Data public class Person { private @Id Name id; private @DnAttribute(value = "uid", index = 3) String uid; private @Attribute(name = "cn") String fullName; private @Attribute(name = "sn") String lastname; private String userPassword; }
@Override public Name getCalculatedId(Object entry) { Assert.notNull(entry, "Entry must not be null"); EntityData entityData = getEntityData(entry.getClass()); if(entityData.metaData.canCalculateDn()) { Set<AttributeMetaData> dnAttributes = entityData.metaData.getDnAttributes(); LdapNameBuilder ldapNameBuilder = LdapNameBuilder.newInstance(entityData.metaData.getBase()); for (AttributeMetaData dnAttribute : dnAttributes) { Object dnFieldValue = ReflectionUtils.getField(dnAttribute.getField(), entry); if(dnFieldValue == null) { throw new IllegalStateException( String.format("DnAttribute for field %s on class %s is null; cannot build DN", dnAttribute.getField().getName(), entry.getClass().getName())); } ldapNameBuilder.add(dnAttribute.getDnAttribute().value(), dnFieldValue.toString()); } return ldapNameBuilder.build(); } return null; }
@Override public Name getCalculatedId(Object entry) { Assert.notNull(entry, "Entry must not be null"); EntityData entityData = getEntityData(entry.getClass()); if(entityData.metaData.canCalculateDn()) { Set<AttributeMetaData> dnAttributes = entityData.metaData.getDnAttributes(); LdapNameBuilder ldapNameBuilder = LdapNameBuilder.newInstance(entityData.metaData.getBase()); for (AttributeMetaData dnAttribute : dnAttributes) { Object dnFieldValue = ReflectionUtils.getField(dnAttribute.getField(), entry); if(dnFieldValue == null) { throw new IllegalStateException( String.format("DnAttribute for field %s on class %s is null; cannot build DN", dnAttribute.getField().getName(), entry.getClass().getName())); } ldapNameBuilder.add(dnAttribute.getDnAttribute().value(), dnFieldValue.toString()); } return ldapNameBuilder.build(); } return null; }
@Override public Name getCalculatedId(Object entry) { Assert.notNull(entry, "Entry must not be null"); EntityData entityData = getEntityData(entry.getClass()); if(entityData.metaData.canCalculateDn()) { Set<AttributeMetaData> dnAttributes = entityData.metaData.getDnAttributes(); LdapNameBuilder ldapNameBuilder = LdapNameBuilder.newInstance(entityData.metaData.getBase()); for (AttributeMetaData dnAttribute : dnAttributes) { Object dnFieldValue = ReflectionUtils.getField(dnAttribute.getField(), entry); if(dnFieldValue == null) { throw new IllegalStateException( String.format("DnAttribute for field %s on class %s is null; cannot build DN", dnAttribute.getField().getName(), entry.getClass().getName())); } ldapNameBuilder.add(dnAttribute.getDnAttribute().value(), dnFieldValue.toString()); } return ldapNameBuilder.build(); } return null; }
/** * @author Mattias Hellborg Arthursson */ @Entry(objectClasses = {"inetOrgPerson", "organizationalPerson", "person", "top"}) public class UnitTestPersonWithIndexedDnAttributes { @Id private Name dn; @DnAttribute(value = "cn", index=2) private String fullName; @DnAttribute(value = "ou", index=1) private String company; @DnAttribute(value= "c", index=0) private String country; public void setFullName(String fullName) { this.fullName = fullName; } public void setCompany(String company) { this.company = company; } public void setCountry(String country) { this.country = country; } }
@Override public Name getCalculatedId(Object entry) { Assert.notNull(entry, "Entry must not be null"); EntityData entityData = getEntityData(entry.getClass()); if(entityData.metaData.canCalculateDn()) { Set<AttributeMetaData> dnAttributes = entityData.metaData.getDnAttributes(); LdapNameBuilder ldapNameBuilder = LdapNameBuilder.newInstance(entityData.metaData.getBase()); for (AttributeMetaData dnAttribute : dnAttributes) { Object dnFieldValue = ReflectionUtils.getField(dnAttribute.getField(), entry); if(dnFieldValue == null) { throw new IllegalStateException( String.format("DnAttribute for field %s on class %s is null; cannot build DN", dnAttribute.getField().getName(), entry.getClass().getName())); } ldapNameBuilder.add(dnAttribute.getDnAttribute().value(), dnFieldValue.toString()); } return ldapNameBuilder.build(); } return null; }
private Name dn; @DnAttribute(value = "cn", index=2) private String fullName; @DnAttribute(value = "ou") private String company; @DnAttribute(value= "c", index=0) private String country;
assertThat(attribute.getDnAttribute().value()).isEqualTo(expectedDnAttributeName); } else { assertThat(attribute.isDnAttribute()).isFalse();
private void postProcessDnAttributes(Class<?> clazz) { boolean hasIndexed = false; boolean hasNonIndexed = false; for (AttributeMetaData dnAttribute : dnAttributes) { int declaredIndex = dnAttribute.getDnAttribute().index(); if(declaredIndex != -1) { hasIndexed = true; } if(declaredIndex == -1) { hasNonIndexed = true; } } if(hasIndexed && hasNonIndexed) { throw new MetaDataException(String.format("At least one DnAttribute declared on class %s is indexed, " + "which means that all DnAttributes must be indexed", clazz.toString())); } indexedDnAttributes = hasIndexed; }
@DnAttribute("cn") private String name;
private void postProcessDnAttributes(Class<?> clazz) { boolean hasIndexed = false; boolean hasNonIndexed = false; for (AttributeMetaData dnAttribute : dnAttributes) { int declaredIndex = dnAttribute.getDnAttribute().index(); if(declaredIndex != -1) { hasIndexed = true; } if(declaredIndex == -1) { hasNonIndexed = true; } } if(hasIndexed && hasNonIndexed) { throw new MetaDataException(String.format("At least one DnAttribute declared on class %s is indexed, " + "which means that all DnAttributes must be indexed", clazz.toString())); } indexedDnAttributes = hasIndexed; }
@DnAttribute(value="cn", index=2) private String commonName; private String telephoneNumber; @DnAttribute(value="ou", index=1) @Transient private String company; @DnAttribute(value="ou", index=0) @Transient private String country;