All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.rolemapper.LdapRoleMapper Maven / Gradle / Ivy

/**
 * Copyright (C) 2006  Bull S. A. S.
 * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation
 * version 2.1 of the License.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA  02110-1301, USA.
 **/
package org.ow2.bonita.rolemapper;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.ow2.bonita.connector.impl.ldap.LdapAttribute;
import org.ow2.bonita.connector.impl.ldap.LdapConnector;
import org.ow2.bonita.definition.RoleMapper;
import org.ow2.bonita.facade.QueryAPIAccessor;
import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;

public class LdapRoleMapper implements RoleMapper {
  
  private String host;
  private Long port;
  private String protocol;
  private String userName;
  private String password;
  //private String certificatePath;
  private String baseObject;
  private String scope;
  private String filter;
  private String derefAliases = "ALWAYS";
  private Long sizeLimit = 0L;
  private Long timeLimit = 0L;
  private String referralHandling = "ignore";

  public void setHost(String host) {
    this.host = host;
  }

  public void setPort(Long port) {
    this.port = port;
  }

  public void setProtocol(String protocol) {
    this.protocol = protocol;
  }

  public void setUserName(String userName) {
    this.userName = userName;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  /*public void setCertificatePath(String certificatePath) {
    this.certificatePath = certificatePath;
  }*/

  public void setBaseObject(String baseObject) {
    this.baseObject = baseObject;
  }

  public void setScope(String scope) {
    this.scope = scope;
  }

  public void setFilter(String filter) {
    this.filter = filter;
  }

  public void setDerefAliases(String derefAliases) {
    this.derefAliases = derefAliases;
  }

  public void setSizeLimit(Long sizeLimit) {
    this.sizeLimit = sizeLimit;
  }

  public void setTimeLimit(Long timeLimit) {
    this.timeLimit = timeLimit;
  }

  public void setReferralHandling(String referralHandling) {
    this.referralHandling = referralHandling;
  }

  public Set searchMembers(QueryAPIAccessor accessor,
      ProcessInstanceUUID instanceUUID, String roleId) throws Exception {

    LdapConnector ldap = new LdapConnector();
    ldap.setAttributes("uniqueMember");
    ldap.setBaseObject(baseObject);
    //ldap.setCertificatePath(certificatePath);
    ldap.setDerefAliases(derefAliases);
    ldap.setFilter(filter);
    ldap.setHost(host);
    ldap.setPassword(password);
    ldap.setPort(port);
    ldap.setProtocol(protocol);
    ldap.setReferralHandling(referralHandling);
    ldap.setScope(scope);
    ldap.setSizeLimit(sizeLimit);
    ldap.setTimeLimit(timeLimit);
    ldap.setUserName(userName);

    ldap.execute();

    Set returns = new HashSet();
    List> list = ldap.getListResult();
    if (!list.isEmpty()) {
      List members = list.get(0);
      StringBuilder builder = new StringBuilder();
      if (members.size() > 1) {
        builder.append("(|");
      }
      for (LdapAttribute member : members) {
        builder.append("(");
        String value = member.getValue();
        int index = value.indexOf(",");
        builder.append(value.substring(0, index));
        builder.append(")");
      }
      if (members.size() > 1) {
        builder.append(")");
      }
      ldap.setBaseObject("");
      ldap.setFilter(builder.toString());
      ldap.setAttributes("uid");
      ldap.execute();
      list = ldap.getListResult();
      for (List uids : list) {
        returns.add(uids.get(0).getValue());
      }
    }
    return returns;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy