Bug 222 : ENHANCEMENT - Add LDAP support ... find, insert, update delete
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.4.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
22/02/2010
Updated 
22/02/2010
Type 
Bug
 
Attachments 
No attachments

Add some basic LDAP support.

Using an ORM type approach to annotation a Bean and provide query, insert, update delete functionality.

 
Rob 22 Feb 09:58
typical bean mapping
...

@LdapDomain(
    baseDn = "ou=avajepeople,o=avajecustomers,dc=avaje,dc=net,dc=nz", 
    objectclass = "top,organizationalperson,avajeperson,inetadmin,inetorgperson,person,inetuser")
@Entity
public class LDPerson {

    public enum Status {
        @EnumValue(value = "Active")
        ACTIVE,

        @EnumValue(value = "Inactive")
        INACTIVE
    }

    @Id
    @Column(name = "uid")
    private String userId;

    @Column(name = "inetUserStatus")
    private Status status;

    private String cn;
    
    private String sn;

    private String givenName;

    private String userPassword;

    @Basic(fetch=FetchType.LAZY)
    private LocalDateTime modifiedTime;

    @Basic(fetch=FetchType.LAZY)
    @LdapAttribute(adapter=SimpleLdapSetAdapater.class)
    private Set<Long> accounts;
    
    public String toString() {
        return userId + " " + status;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public String getCn() {
        return cn;
    }

    public void setCn(String cn) {
        this.cn = cn;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getGivenName() {
        return givenName;
    }

    public void setGivenName(String givenName) {
        this.givenName = givenName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public LocalDateTime getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(LocalDateTime modifiedTime) {
        this.modifiedTime = modifiedTime;
    }

    public Set<Long> getAccounts() {
        return accounts;
    }

    public void setAccounts(Set<Long> accounts) {
        this.accounts = accounts;
    }
    
    public void addAccount(long accountNumber){
        if (accounts == null){
            accounts = new HashSet<Long>();
        }
        accounts.add(accountNumber);
    }

Using the LdapDomain annotation we can define a baseDn and list of object classes.

We can use normal @Id @Column etc to mark the ID property and map the bean property name to the ldap attribute name.

We can use use @LdapAttribute and a LdapAttributeAdapter to handle more interesting logical bean to ldap attribute value conversion.

Rob 22 Feb 10:03
Configure the server .. and use Query and save as per normal
ServerConfig config = new ServerConfig();
  ...
  // specify the Ldap configuration for a server
  LdapConfig ldapConfig = new LdapConfig();
  ldapConfig.setContextFactory(contextFactory);
  config.setLdapConfig(ldapConfig);

  
  EbeanServer server = EbeanServerFactory.create(config);

  // use the Ebean API as per normal
  LDPerson pRob = server.find(LDPerson.class)
    .select("userId, cn")
    .setId("rbygraveTest01")
    .findUnique();

  List<LDPerson> list = server.find(LDPerson.class)
    .select("userId,status")
    .where().like("userId","lz*").eq("status", LDPerson.Status.ACTIVE)
    .findList();


  LDPerson p = new LDPerson();
  p.setUserId("rbygraveTest01");
  p.setStatus(Status.ACTIVE);
  p.setCn("Test01");
  p.setSn("Testing123");
  p.setGivenName("Ban Dana");
  p.setUserPassword("qwerty");

  server.save(p);

Rob 22 Feb 10:03
That's it

Added to HEAD.

Rob 22 Feb 10:06
Note: One server ... handling both Ldap and DB entities

Note that the expected normal configuration will be a single EbeanServer instance that handles both DB entities and LDAP entities.

The EbeanServer knows which ones are LDAP based on the LdapDomain annotation and will handle the find and save etc with ldap specific handlers.

Note that LDAP does not support transactions normally... and there is no extra support in Ebean (to reverse LDAP changes when a rollback occurs etc).

woResponse

Upload a file