⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldapextsampler.java

📁 测试工具
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter.protocol.ldap.sampler;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchResult;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.protocol.ldap.config.gui.LDAPArgument;
import org.apache.jmeter.protocol.ldap.config.gui.LDAPArguments;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.testelement.property.PropertyIterator;
import org.apache.jmeter.testelement.property.StringProperty;
import org.apache.jmeter.testelement.property.TestElementProperty;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.XMLBuffer;
import org.apache.log.Logger;

/*******************************************************************************
 * Ldap Sampler class is main class for the LDAP test. This will control all the
 * test available in the LDAP Test.
 ******************************************************************************/

public class LDAPExtSampler extends AbstractSampler implements TestListener {

	private static final Logger log = LoggingManager.getLoggerForClass();

	/*
	 * The following strings are used in the test plan, and the values must not be changed
	 * if test plans are to be upwardly compatible. 
	 */
	public final static String SERVERNAME = "servername"; // $NON-NLS-1$

	public final static String PORT = "port"; // $NON-NLS-1$
	
	public final static String SECURE = "secure"; // $NON-NLS-1$

	public final static String ROOTDN = "rootdn"; // $NON-NLS-1$

	public final static String TEST = "test"; // $NON-NLS-1$

	// These are values for the TEST attribute above
	public final static String ADD = "add"; // $NON-NLS-1$

	public final static String MODIFY = "modify"; // $NON-NLS-1$

	public final static String BIND = "bind"; // $NON-NLS-1$

	public final static String UNBIND = "unbind"; // $NON-NLS-1$

	public final static String DELETE = "delete"; // $NON-NLS-1$

	public final static String SEARCH = "search"; // $NON-NLS-1$
    // end of TEST values
	
	public final static String SEARCHBASE = "search"; // $NON-NLS-1$

	public final static String SEARCHFILTER = "searchfilter"; // $NON-NLS-1$

	public final static String ARGUMENTS = "arguments"; // $NON-NLS-1$

	public final static String LDAPARGUMENTS = "ldaparguments"; // $NON-NLS-1$

	public final static String BASE_ENTRY_DN = "base_entry_dn"; // $NON-NLS-1$

	public final static String SCOPE = "scope"; // $NON-NLS-1$

	public final static String COUNTLIM = "countlimit"; // $NON-NLS-1$

	public final static String TIMELIM = "timelimit"; // $NON-NLS-1$

	public final static String ATTRIBS = "attributes"; // $NON-NLS-1$

	public final static String RETOBJ = "return_object"; // $NON-NLS-1$

	public final static String DEREF = "deref_aliases"; // $NON-NLS-1$

	public final static String USERDN = "user_dn"; // $NON-NLS-1$

	public final static String USERPW = "user_pw"; // $NON-NLS-1$

	public final static String SBIND = "sbind"; // $NON-NLS-1$

	public final static String COMPARE = "compare"; // $NON-NLS-1$
	
	public final static String CONNTO = "connection_timeout"; // $NON-NLS-1$

	public final static String COMPAREDN = "comparedn"; // $NON-NLS-1$

	public final static String COMPAREFILT = "comparefilt"; // $NON-NLS-1$

	public final static String PARSEFLAG = "parseflag"; // $NON-NLS-1$

	public final static String RENAME = "rename"; // $NON-NLS-1$

	public final static String MODDDN = "modddn"; // $NON-NLS-1$

	public final static String NEWDN = "newdn"; // $NON-NLS-1$

    private static final String SEMI_COLON = ";"; // $NON-NLS-1$


    private static Hashtable ldapConnections = new Hashtable();

	private static Hashtable ldapContexts = new Hashtable();

	private static final int MAX_SORTED_RESULTS = 
		JMeterUtils.getPropDefault("ldapsampler.max_sorted_results", 1000); // $NON-NLS-1$
	
	/***************************************************************************
	 * !ToDo (Constructor description)
	 **************************************************************************/
	public LDAPExtSampler() {
	}

    public void setConnTimeOut(String connto) {
        setProperty(new StringProperty(CONNTO, connto));
    }

    public String getConnTimeOut() {
        return getPropertyAsString(CONNTO);
    }
    
    public void setSecure(String sec) {
        setProperty(new StringProperty(SECURE, sec));
    }

    public boolean isSecure() {
        return getPropertyAsBoolean(SECURE);
    }


    public boolean isParseFlag() {
        return getPropertyAsBoolean(PARSEFLAG);
    }

    public void setParseFlag(String parseFlag) {
        setProperty(new StringProperty(PARSEFLAG, parseFlag));
    }

	/***************************************************************************
	 * Gets the username attribute of the LDAP object
	 * 
	 * @return The username
	 **************************************************************************/

	public String getUserDN() {
		return getPropertyAsString(USERDN);
	}

	/***************************************************************************
	 * Sets the username attribute of the LDAP object
	 * 
	 **************************************************************************/

	public void setUserDN(String newUserDN) {
		setProperty(new StringProperty(USERDN, newUserDN));
	}

	/***************************************************************************
	 * Gets the password attribute of the LDAP object
	 * 
	 * @return The password
	 **************************************************************************/

	public String getUserPw() {
		return getPropertyAsString(USERPW);
	}

	/***************************************************************************
	 * Sets the password attribute of the LDAP object
	 * 
	 **************************************************************************/

	public void setUserPw(String newUserPw) {
		setProperty(new StringProperty(USERPW, newUserPw));
	}

	/***************************************************************************
	 * Sets the Servername attribute of the ServerConfig object
	 * 
	 * @param servername
	 *            The new servername value
	 **************************************************************************/
	public void setServername(String servername) {
		setProperty(new StringProperty(SERVERNAME, servername));
	}

	/***************************************************************************
	 * Sets the Port attribute of the ServerConfig object
	 * 
	 * @param port
	 *            The new Port value
	 **************************************************************************/
	public void setPort(String port) {
		setProperty(new StringProperty(PORT, port));
	}

	/***************************************************************************
	 * Gets the servername attribute of the LDAPSampler object
	 * 
	 * @return The Servername value
	 **************************************************************************/

	public String getServername() {
		return getPropertyAsString(SERVERNAME);
	}

	/***************************************************************************
	 * Gets the Port attribute of the LDAPSampler object
	 * 
	 * @return The Port value
	 **************************************************************************/

	public String getPort() {
		return getPropertyAsString(PORT);
	}

	/***************************************************************************
	 * Sets the Rootdn attribute of the LDAPSampler object
	 * 
	 * @param newRootdn 
	 *            The new rootdn value
	 **************************************************************************/
	public void setRootdn(String newRootdn) {
		this.setProperty(ROOTDN, newRootdn);
	}

	/***************************************************************************
	 * Gets the Rootdn attribute of the LDAPSampler object
	 * 
	 * @return The Rootdn value
	 **************************************************************************/
	public String getRootdn() {
		return getPropertyAsString(ROOTDN);
	}

	/***************************************************************************
	 * Gets the search scope attribute of the LDAPSampler object
	 * 
	 * @return The scope value
	 **************************************************************************/
	public String getScope() {
		return getPropertyAsString(SCOPE);
	}

	public int getScopeAsInt() {
		return getPropertyAsInt(SCOPE);
	}

	/***************************************************************************
	 * Sets the search scope attribute of the LDAPSampler object
	 * 
	 * @param newScope
	 *            The new scope value
	 **************************************************************************/
	public void setScope(String newScope) {
		this.setProperty(SCOPE, newScope);
	}

	/***************************************************************************
	 * Gets the size limit attribute of the LDAPSampler object
	 * 
	 * @return The size limit
	 **************************************************************************/
	public String getCountlim() {
		return getPropertyAsString(COUNTLIM);
	}

	public long getCountlimAsLong() {
		return getPropertyAsLong(COUNTLIM);
	}

	/***************************************************************************
	 * Sets the size limit attribute of the LDAPSampler object
	 * 
	 * @param newClim
	 *            The new size limit value
	 **************************************************************************/
	public void setCountlim(String newClim) {
		this.setProperty(COUNTLIM, newClim);
	}

	/***************************************************************************
	 * Gets the time limit attribute of the LDAPSampler object
	 * 
	 * @return The time limit
	 **************************************************************************/
	public String getTimelim() {
		return getPropertyAsString(TIMELIM);
	}

	public int getTimelimAsInt() {
		return getPropertyAsInt(TIMELIM);
	}

	/***************************************************************************
	 * Sets the time limit attribute of the LDAPSampler object
	 * 
	 * @param newTlim
	 *            The new time limit value
	 **************************************************************************/
	public void setTimelim(String newTlim) {
		this.setProperty(TIMELIM, newTlim);
	}

	/***************************************************************************
	 * Gets the return objects attribute of the LDAPSampler object
	 * 
	 * @return if the object(s) are to be returned
	 **************************************************************************/
	public boolean isRetobj() {
		return getPropertyAsBoolean(RETOBJ);
	}

	/***************************************************************************
	 * Sets the return objects attribute of the LDAPSampler object
	 * 
	 **************************************************************************/
	public void setRetobj(String newRobj) {
		this.setProperty(RETOBJ, newRobj);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -