jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1854570 - in /jmeter/trunk: src/core/org/apache/jmeter/resources/ src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/ src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/ xdocs/ xdocs/usermanual/
Date Fri, 01 Mar 2019 10:03:02 GMT
Author: pmouawad
Date: Fri Mar  1 10:03:02 2019
New Revision: 1854570

URL: http://svn.apache.org/viewvc?rev=1854570&view=rev
Log:
Bug 63185 - Add option to implicitly trust SSL/TLS connections/Disable hostname verification

Based on contribution by Brian Wolfe
Changes:

- Fixed existing NPE if log level is DEBUG if attr is null 
- Fixed some SONAR warning
- Simplified code
- Modified TrustAllSocketFactory (renamed and fixed static attribute sf affectation from Constructor)


This closes #443
Bugzilla Id: 63185

Added:
    jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/TrustAllSocketFactory.java
  (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties
    jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java
    jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
    jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/build-ldapext-test-plan.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Fri Mar  1 10:03:02
2019
@@ -625,6 +625,7 @@ ldap_search_baseobject=Perform baseobjec
 ldap_search_onelevel=Perform onelevel search
 ldap_search_subtree=Perform subtree search
 ldap_secure=Use Secure LDAP Protocol ?
+ldap_trust_all=Trust All Certificates ?
 ldap_testing_title=LDAP Request
 ldapext_sample_title=LDAP Extended Request Defaults
 ldapext_testing_title=LDAP Extended Request

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties Fri Mar  1 10:03:02
2019
@@ -406,7 +406,8 @@ ldap_sample_title=Valores por defecto Pe
 ldap_search_baseobject=Realizar la búsqueda 'baseobject'
 ldap_search_onelevel=Realizar la búsqueda 'onelevel'
 ldap_search_subtree=Realizar la búsqueda 'subtree'
-ldap_secure=¿Usar el Protocolo LDAP Seguro?
+ldap_secure=Usar el Protocolo LDAP Seguro?
+ldap_trust_all=Confíe en todos los certificados?
 ldap_testing_title=Petición LDAP
 ldapext_sample_title=Valores por defecto Petición Extendidad LDAP
 ldapext_testing_title=Petición Extendida LDAP

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Fri Mar  1 10:03:02
2019
@@ -614,6 +614,7 @@ ldap_search_baseobject=Effectuer une rec
 ldap_search_onelevel=Effectuer une recherche 'onelevel'
 ldap_search_subtree=Effectuer une recherche 'subtree'
 ldap_secure=Utiliser le protocole LDAP sécurisé (ldaps) ?
+ldap_trust_all=Faire confiance à tous les certificats ?
 ldap_testing_title=Requête LDAP
 ldapext_sample_title=Requête LDAP étendue par défaut
 ldapext_testing_title=Requête LDAP étendue

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties Fri Mar  1
10:03:02 2019
@@ -384,6 +384,7 @@ ldap_search_baseobject=Realizar busca b�
 ldap_search_onelevel=Realizar busca de um nível
 ldap_search_subtree=Realizar busca em sub-árvore
 ldap_secure=Utilizar Protocolo LDAP Seguro?
+ldap_trust_all=Trust Todos os Certificados ?
 ldap_testing_title=Requisição LDAP
 ldapext_sample_title=Padrões de Requisição LDAP Estendidas
 ldapext_testing_title=Requisição LDAP Estendida

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties Fri Mar  1 10:03:02
2019
@@ -365,6 +365,7 @@ ldap_search_baseobject=Temel-nesne arama
 ldap_search_onelevel=Tek-seviye araması gerçekleştir
 ldap_search_subtree=Alt-ağaç araması gerçekleştir
 ldap_secure=Güvenli LDAP Protokulu kullan ?
+ldap_trust_all=Tüm Sertifikalara Güven?
 ldap_testing_title=LDAP İsteği
 ldapext_sample_title=LDAP Gelişmiş İsteği Öntanımlı Değerleri
 ldapext_testing_title=LDAP Gelişmiş İsteği

Modified: jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java
(original)
+++ jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java
Fri Mar  1 10:03:02 2019
@@ -132,6 +132,8 @@ public class LdapExtConfigGui extends Ab
     private JCheckBox parseflag = new JCheckBox(JMeterUtils.getResString("ldap_parse_results"));
// $NON-NLS-1$
 
     private JCheckBox secure = new JCheckBox(JMeterUtils.getResString("ldap_secure")); //
$NON-NLS-1$
+    
+    private JCheckBox trustAll = new JCheckBox(JMeterUtils.getResString("ldap_trust_all"));
// $NON-NLS-1$
 
     private JRadioButton addTest = new JRadioButton(JMeterUtils.getResString("addtest"));
// $NON-NLS-1$
 
@@ -208,6 +210,7 @@ public class LdapExtConfigGui extends Ab
         connto.setText(element.getPropertyAsString(LDAPExtSampler.CONNTO));
         parseflag.setSelected(element.getPropertyAsBoolean(LDAPExtSampler.PARSEFLAG));
         secure.setSelected(element.getPropertyAsBoolean(LDAPExtSampler.SECURE));
+        trustAll.setSelected(element.getPropertyAsBoolean(LDAPExtSampler.TRUSTALL));
         userpw.setText(element.getPropertyAsString(LDAPExtSampler.USERPW));
         userdn.setText(element.getPropertyAsString(LDAPExtSampler.USERDN));
         comparedn.setText(element.getPropertyAsString(LDAPExtSampler.COMPAREDN));
@@ -274,15 +277,16 @@ public class LdapExtConfigGui extends Ab
         element.setProperty(LDAPExtSampler.SERVERNAME, servername.getText());
         element.setProperty(LDAPExtSampler.PORT, port.getText());
         element.setProperty(LDAPExtSampler.ROOTDN, rootdn.getText());
-        element.setProperty(LDAPExtSampler.SCOPE,String.valueOf(scope.getSelectedIndex()));
+        element.setProperty(LDAPExtSampler.SCOPE, String.valueOf(scope.getSelectedIndex()));
         element.setProperty(LDAPExtSampler.COUNTLIM, countlim.getText());
         element.setProperty(LDAPExtSampler.TIMELIM, timelim.getText());
         element.setProperty(LDAPExtSampler.ATTRIBS, attribs.getText());
-        element.setProperty(LDAPExtSampler.RETOBJ,Boolean.toString(retobj.isSelected()));
-        element.setProperty(LDAPExtSampler.DEREF,Boolean.toString(deref.isSelected()));
+        element.setProperty(LDAPExtSampler.RETOBJ, Boolean.toString(retobj.isSelected()));
+        element.setProperty(LDAPExtSampler.DEREF, Boolean.toString(deref.isSelected()));
         element.setProperty(LDAPExtSampler.CONNTO, connto.getText());
-        element.setProperty(LDAPExtSampler.PARSEFLAG,Boolean.toString(parseflag.isSelected()));
-        element.setProperty(LDAPExtSampler.SECURE,Boolean.toString(secure.isSelected()));
+        element.setProperty(LDAPExtSampler.PARSEFLAG, Boolean.toString(parseflag.isSelected()));
+        element.setProperty(LDAPExtSampler.SECURE, Boolean.toString(secure.isSelected()));
+        element.setProperty(LDAPExtSampler.TRUSTALL, Boolean.toString(trustAll.isSelected()));
         element.setProperty(LDAPExtSampler.USERDN, userdn.getText());
         element.setProperty(LDAPExtSampler.USERPW, userpw.getText());
         element.setProperty(LDAPExtSampler.COMPAREDN, comparedn.getText());
@@ -357,6 +361,7 @@ public class LdapExtConfigGui extends Ab
         deref.setSelected(false);
         parseflag.setSelected(false);
         secure.setSelected(false);
+        trustAll.setSelected(false);
         addTest.setSelected(false);
         modifyTest.setSelected(false);
         deleteTest.setSelected(false);
@@ -413,6 +418,7 @@ public class LdapExtConfigGui extends Ab
         bindPanel.add(createLabelPanel("ldap_connto", connto));
 
         bindPanel.add(secure);
+        bindPanel.add(trustAll);
         return bindPanel;
     }
 

Modified: jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
(original)
+++ jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
Fri Mar  1 10:03:02 2019
@@ -39,6 +39,7 @@ import javax.naming.directory.DirContext
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchResult;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
 import org.apache.jmeter.config.Argument;
 import org.apache.jmeter.config.Arguments;
@@ -85,6 +86,8 @@ public class LDAPExtSampler extends Abst
     public static final String PORT = "port"; // $NON-NLS-1$
 
     public static final String SECURE = "secure"; // $NON-NLS-1$
+    
+    public static final String TRUSTALL = "trustall";
 
     public static final String ROOTDN = "rootdn"; // $NON-NLS-1$
 
@@ -157,10 +160,8 @@ public class LDAPExtSampler extends Abst
     private static final int MAX_SORTED_RESULTS =
         JMeterUtils.getPropDefault("ldapsampler.max_sorted_results", 1000); // $NON-NLS-1$
 
-    /***************************************************************************
-     * !ToDo (Constructor description)
-     **************************************************************************/
     public LDAPExtSampler() {
+        super();
     }
 
     public void setConnTimeOut(String connto) {
@@ -178,6 +179,14 @@ public class LDAPExtSampler extends Abst
     public boolean isSecure() {
         return getPropertyAsBoolean(SECURE);
     }
+    
+    public void setTrustAll(String trust){
+        setProperty(new StringProperty(TRUSTALL, trust));
+    }
+    
+    public boolean isTrustAll() {
+        return getPropertyAsBoolean(TRUSTALL);
+    }
 
 
     public boolean isParseFlag() {
@@ -541,25 +550,25 @@ public class LDAPExtSampler extends Abst
             } else if("replace".equals(opcode)) { // $NON-NLS-1$
                     mods[count++] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
             } else {
-                    log.warn("Invalid opCode: "+opcode);
+                    log.warn("Invalid opCode: {}", opcode);
             }
         }
         return mods;
     }
 
-    /***************************************************************************
+    /**
      * Collect all the value from the table (Arguments), using this create the
      * Attributes This will create the Basic Attributes for the User defined
      * TestCase for search test
      *
-     * @return The BasicAttributes
-     **************************************************************************/
+     * @return The BasicAttributes (null means all)
+     **/
     private String[] getRequestAttributes(String reqAttr) {
         int index;
         String[] mods;
         int count = 0;
         if (reqAttr.length() == 0) {
-            return null;
+            return null; // NOSONAR null means all , empty array means nothing
         }
         if (!reqAttr.endsWith(SEMI_COLON)) {
             reqAttr = reqAttr + SEMI_COLON;
@@ -660,7 +669,8 @@ public class LDAPExtSampler extends Abst
         }
         try {
             res.sampleStart();
-            ctx = LdapExtClient.connect(getServername(), getPort(), getRootdn(), getUserDN(),
getUserPw(),getConnTimeOut(),isSecure());
+            ctx = LdapExtClient.connect(getServername(), getPort(), getRootdn(), getUserDN(),
+                    getUserPw(),getConnTimeOut(),isSecure(), isTrustAll());
         } finally {
             res.sampleEnd();
         }
@@ -674,7 +684,8 @@ public class LDAPExtSampler extends Abst
     private void singleBindOp(SampleResult res) throws NamingException {
         try {
             res.sampleStart();
-            DirContext ctx = LdapExtClient.connect(getServername(), getPort(), getRootdn(),
getUserDN(), getUserPw(),getConnTimeOut(),isSecure());
+            DirContext ctx = LdapExtClient.connect(getServername(), getPort(), getRootdn(),

+                    getUserDN(), getUserPw(),getConnTimeOut(),isSecure(), isTrustAll());
             LdapExtClient.disconnect(ctx);
         } finally {
             res.sampleEnd();
@@ -727,7 +738,7 @@ public class LDAPExtSampler extends Abst
             xmlBuffer.openTag("operation"); // $NON-NLS-1$
             final String testType = getTest();
             xmlBuffer.tag("opertype", testType); // $NON-NLS-1$
-            log.debug("performing test: " + testType);
+            log.debug("performing test: {}", testType);
             if (testType.equals(UNBIND)) {
                 res.setSamplerData("Unbind");
                 xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$
@@ -836,8 +847,11 @@ public class LDAPExtSampler extends Abst
             String returnData = ex.toString();
             final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code");
             if (indexOfLDAPErrCode >= 0) {
+                // FIXME What is 21 ?
                 res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData
                         .indexOf(']'))); // $NON-NLS-1$
+                // 17 is "LDAP: error code".length
+                // Code is on 2 characters ?
                 res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode
+ 19));
             } else {
                 res.setResponseMessage(returnData);
@@ -901,7 +915,7 @@ public class LDAPExtSampler extends Abst
     {
         final Attributes attrs = sr.getAttributes();
         final int size = attrs.size();
-        final ArrayList<Attribute> sortedAttrs = new ArrayList<>(size);
+        final List<Attribute> sortedAttrs = new ArrayList<>(size);
 
         xmlb.openTag("searchresult"); // $NON-NLS-1$
         xmlb.tag("dn", sr.getName()); // $NON-NLS-1$
@@ -909,8 +923,7 @@ public class LDAPExtSampler extends Abst
         xmlb.openTag("attributes"); // $NON-NLS-1$
 
         try {
-            for (NamingEnumeration<? extends Attribute> en = attrs.getAll(); en.hasMore();)
-            {
+            for (NamingEnumeration<? extends Attribute> en = attrs.getAll(); en.hasMore();)
{
                 final Attribute attr = en.next();
                 sortedAttrs.add(attr);
             }
@@ -921,25 +934,13 @@ public class LDAPExtSampler extends Abst
                     sb.append(getWriteValue(attr.get()));
                 } else {
                     final ArrayList<String> sortedVals = new ArrayList<>(attr.size());
-                    boolean first = true;
 
-                    for (NamingEnumeration<?> ven = attr.getAll(); ven.hasMore();)
-                    {
+                    for (NamingEnumeration<?> ven = attr.getAll(); ven.hasMore();)
{
                         final Object value = getWriteValue(ven.next());
                         sortedVals.add(value.toString());
                     }
-
                     Collections.sort(sortedVals);
-
-                    for (final String value : sortedVals)
-                    {
-                        if (first) {
-                            first = false;
-                        } else {
-                            sb.append(", "); // $NON-NLS-1$
-                        }
-                        sb.append(value);
-                    }
+                    sb.append(StringUtils.join(sortedVals, ", "));
                 }
                 xmlb.tag(attr.getID(),sb);
             }
@@ -997,15 +998,13 @@ public class LDAPExtSampler extends Abst
     {
         String srName = sr.getName();
 
-        if (!srName.endsWith(searchBase))
-        {
+        if (!srName.endsWith(searchBase)) {
             if (srName.length() > 0) {
                 srName = srName + ',';
             }
             srName = srName + searchBase;
         }
-        if ((rootDn.length() > 0) && !srName.endsWith(rootDn))
-        {
+        if ((rootDn.length() > 0) && !srName.endsWith(rootDn)) {
             if (srName.length() > 0) {
                 srName = srName + ',';
             }
@@ -1015,8 +1014,7 @@ public class LDAPExtSampler extends Abst
         return srName;
     }
 
-    private String getWriteValue(final Object value)
-    {
+    private String getWriteValue(final Object value) {
         if (value instanceof String) {
             // assume it's sensitive data
             return StringEscapeUtils.escapeXml10((String)value);

Modified: jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
(original)
+++ jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java
Fri Mar  1 10:03:02 2019
@@ -30,21 +30,16 @@ import javax.naming.directory.Modificati
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
-import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.util.JOrphanUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/*******************************************************************************
- *
+/**
  * Ldap Client class is main class to create ,modify, search and delete all the
  * LDAP functionality available
- *
- * author Dolf Smits(Dolf.Smits@Siemens.com) created Aug 09 2003 11:00 AM
- * company Siemens Netherlands N.V..
- *
  * Based on the work of: author T.Elanjchezhiyan(chezhiyan@siptech.co.in)
  *
- ******************************************************************************/
+ */
 public class LdapExtClient {
     private static final Logger log = LoggerFactory.getLogger(LdapExtClient.class);
 
@@ -53,7 +48,8 @@ public class LdapExtClient {
     /**
      * Constructor for the LdapClient object
      */
-    public LdapExtClient() {
+    private LdapExtClient() {
+        super();
     }
 
     /**
@@ -78,14 +74,25 @@ public class LdapExtClient {
      * @exception NamingException
      *                when creating the {@link DirContext} fails
      */
-    public static DirContext connect(String host, String port, String rootdn, String username,
String password, String connTimeOut, boolean secure)
+    public static DirContext connect(String host,
+            String port, 
+            String rootdn, 
+            String username,
+            String password, 
+            String connTimeOut, 
+            boolean secure, 
+            boolean trustAll)
             throws NamingException {
         DirContext dirContext;
-        Hashtable<String, String> env = new Hashtable<>();
+        Hashtable<String, String> env = new Hashtable<>(); // NOSONAR : Env needs
to be HashTable
         env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //
$NON-NLS-1$
         StringBuilder sb = new StringBuilder(80);
         if (secure) {
             sb.append("ldaps://"); // $NON-NLS-1$
+            if (trustAll){
+                log.debug("Using secure connection with trustAll");
+                env.put("java.naming.ldap.factory.socket", TrustAllSocketFactory.class.getName());
+            }
         } else {
             sb.append("ldap://"); // $NON-NLS-1$
         }
@@ -97,7 +104,9 @@ public class LdapExtClient {
         sb.append("/"); // $NON-NLS-1$
         sb.append(rootdn);
         env.put(Context.PROVIDER_URL,sb.toString());
-        log.info("prov_url= " + env.get(Context.PROVIDER_URL)); // $NON-NLS-1$
+        if(log.isInfoEnabled()) {
+            log.info("prov_url= {}", env.get(Context.PROVIDER_URL)); // $NON-NLS-1$
+        }
         if (connTimeOut.length()> 0) {
             env.put("com.sun.jndi.ldap.connect.timeout", connTimeOut); // $NON-NLS-1$
         }
@@ -128,7 +137,7 @@ public class LdapExtClient {
         }
     }
 
-    /***************************************************************************
+    /**
      * Filter the data in the ldap directory for the given search base
      * 
      * @param dirContext
@@ -158,23 +167,24 @@ public class LdapExtClient {
      * @return result of the search
      * @throws NamingException
      *             when searching fails
-     **************************************************************************/
-    public static NamingEnumeration<SearchResult> searchTest(DirContext dirContext,
String searchBase, String searchFilter, int scope, long countlim,
-            int timelim, String[] attrs, boolean retobj, boolean deref) throws NamingException
{
+     **/
+    public static NamingEnumeration<SearchResult> searchTest(  
+            DirContext dirContext, 
+            String searchBase, 
+            String searchFilter, 
+            int scope, 
+            long countlim,
+            int timelim, 
+            String[] attrs, 
+            boolean retobj, 
+            boolean deref) throws NamingException {
         if (dirContext == null) {
             throw new NamingException(CONTEXT_IS_NULL);
         }
         if (log.isDebugEnabled()){
             log.debug(
-                    "searchBase=" + searchBase +
-                    " scope=" + scope +
-                    " countlim=" + countlim +
-                    " timelim=" + timelim +
-                    " attrs=" + JMeterUtils.unsplit(attrs,",") +
-                    " retobj=" + retobj +
-                    " deref=" + deref +
-                    " filter=" + searchFilter
-                      );
+                    "searchBase={}, scope={}, countlim={}, timelim={}, attrs={}, retobj={},
deref={}, filter={}",
+                    searchBase,scope, countlim,timelim, attrs != null ? JOrphanUtils.unsplit(attrs,","):
null,retobj,deref,searchFilter);
         }
         SearchControls searchcontrols = new SearchControls(scope, countlim,
                 timelim, attrs, retobj, deref);
@@ -216,7 +226,7 @@ public class LdapExtClient {
      *
      **************************************************************************/
     public static void moddnOp(DirContext dirContext, String ddn, String newdn) throws NamingException
{
-        log.debug("ddn and newDn= " + ddn + "@@@@" + newdn);
+        log.debug("ddn and newDn= {}@@@@{}", ddn , newdn);
         if (dirContext == null) {
             throw new NamingException(CONTEXT_IS_NULL);
         }
@@ -265,7 +275,7 @@ public class LdapExtClient {
         return dirContext.createSubcontext(string, attributes);
     }
 
-    /***************************************************************************
+    /**
      * Delete the attribute from the ldap directory
      *
      * @param dirContext
@@ -274,7 +284,7 @@ public class LdapExtClient {
      *            distinguished name of the subcontext to destroy
      * @throws NamingException
      *             when destroying the subcontext fails
-     **************************************************************************/
+     */
     public static void deleteTest(DirContext dirContext, String string) throws NamingException
{
         if (dirContext == null) {
             throw new NamingException(CONTEXT_IS_NULL);

Added: jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/TrustAllSocketFactory.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/TrustAllSocketFactory.java?rev=1854570&view=auto
==============================================================================
--- jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/TrustAllSocketFactory.java
(added)
+++ jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/TrustAllSocketFactory.java
Fri Mar  1 10:03:02 2019
@@ -0,0 +1,124 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509ExtendedTrustManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TrustAllSocketFactory extends SocketFactory {
+    private static final AtomicReference<TrustAllSocketFactory> defaultFactory = new
AtomicReference<>();
+
+    private static final Logger log = LoggerFactory.getLogger(TrustAllSocketFactory.class);
+
+    public TrustAllSocketFactory() throws NoSuchAlgorithmException, KeyManagementException
{
+        TrustManager[] trustAllCerts = new TrustManager[] {
+                new X509ExtendedTrustManager() {
+                    @Override
+                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+                        return new java.security.cert.X509Certificate[0];
+                    }
+                    @Override
+                    public void checkClientTrusted(X509Certificate[] certs, String authType)
{
+                        // NOOP
+                    }
+                    @Override
+                    public void checkServerTrusted(X509Certificate[] certs, String authType)
{
+                        // NOOP
+                    }
+                    @Override
+                    public void checkClientTrusted(X509Certificate[] arg0, String arg1, Socket
arg2)
+                        throws CertificateException {
+                        // NOOP
+                    }
+                    @Override
+                    public void checkClientTrusted(X509Certificate[] arg0, String arg1, SSLEngine
arg2)
+                        throws CertificateException {
+                        // NOOP
+                    }
+                    @Override
+                    public void checkServerTrusted(X509Certificate[] arg0, String arg1, Socket
arg2)
+                        throws CertificateException {
+                        // NOOP
+                    }
+                    @Override
+                    public void checkServerTrusted(X509Certificate[] arg0, String arg1, SSLEngine
arg2)
+                        throws CertificateException {
+                        // NOOP
+                    }
+                }
+        };
+
+        SSLContext ctx = SSLContext.getInstance("TLS");
+        ctx.init(null, trustAllCerts, new java.security.SecureRandom());
+    }
+
+    public static SocketFactory getDefault() {
+        final TrustAllSocketFactory value = defaultFactory.get();
+        if (value == null) {
+            try {
+                defaultFactory.compareAndSet(null, new TrustAllSocketFactory());
+            } catch (KeyManagementException e) {
+                log.error("KeyManagementException: {}", e.getLocalizedMessage());
+            } catch (NoSuchAlgorithmException e) {
+                log.error("NoSuchAlgorithmException: {}", e.getLocalizedMessage());
+            }
+            return defaultFactory.get();
+        }
+        return value;
+    }
+    @Override
+    public Socket createSocket() throws IOException{
+        return getDefault().createSocket();
+    }
+
+    @Override
+    public Socket createSocket(final String host, final int port) throws IOException {
+        return getDefault().createSocket(host, port);
+    }
+
+    @Override
+    public Socket createSocket(final String host, final int port, final InetAddress localHost,
final int localPort) throws IOException {
+        return getDefault().createSocket(host, port, localHost, localPort);
+    }
+
+    @Override
+    public Socket createSocket(final InetAddress localHost, final int localPort) throws IOException
{
+        return getDefault().createSocket(localHost, localPort);
+    }
+
+    @Override
+    public Socket createSocket(final InetAddress address, final int port, final InetAddress
localHost, final int localPort) 
+            throws IOException {
+        return getDefault().createSocket(address, port, localHost, localPort);
+    }
+}

Propchange: jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/TrustAllSocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/TrustAllSocketFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Fri Mar  1 10:03:02 2019
@@ -80,6 +80,7 @@ Summary
 
 <h3>Other samplers</h3>
 <ul>
+    <li><bug>63185</bug>Add option to implicitly trust SSL/TLS connections/Disable
hostname verification. Based on contribution by Brian Wolfe (wolfebrian2120 at gmail.com)</li>
 </ul>
 
 <h3>Controllers</h3>
@@ -178,6 +179,7 @@ Summary
     <li><a href="https://ubikloadpack.com">Ubik Load Pack</a></li>
     <li>Benoit Vatan (benoit.vatan at gmail.com)</li>
     <li>Graham Russell (graham at ham1.co.uk)</li>
+    <li>Brian Wolfe (wolfebrian2120 at gmail.com)</li>
 </ul>
 <p>We also thank bug reporters who helped us improve JMeter.</p>
 <ul>

Modified: jmeter/trunk/xdocs/usermanual/build-ldapext-test-plan.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/build-ldapext-test-plan.xml?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/build-ldapext-test-plan.xml (original)
+++ jmeter/trunk/xdocs/usermanual/build-ldapext-test-plan.xml Fri Mar  1 10:03:02 2019
@@ -185,6 +185,9 @@ When this field is kept empty, an anonym
 <li>
 <i>(Optional)</i> Check the box Use Secure LDAP Protocol if you access with LDAP
over SSL (ldaps)
 </li>
+<li>
+<i>(Optional)</i> Check the box TrustAll if you want the client to trust all
certificates
+</li>
 </ol>
 </p>
 <p>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1854570&r1=1854569&r2=1854570&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Fri Mar  1 10:03:02 2019
@@ -800,6 +800,9 @@ This will not have any impact on existin
           <property name="Username" required="No">Full distinguished name of the user
as which you want to bind.</property>
           <property name="Password" required="No">Password for the above user. If omitted
it will result in an anonymous bind.
             If it is incorrect, the sampler will return an error and revert to an anonymous
bind. (N.B. this is stored unencrypted in the test plan)</property>
+          <property name="Connection timeout (in milliseconds)" required="No">Timeout
for connection, if exceeded connection will be aborted</property>
+          <property name="Use Secure LDAP Protocol" required="No">Use <code>ldaps://</code>
scheme instead of <code>ldap://</code></property>
+          <property name="Trust All Certificates" required="No">Trust all certificates,
only used if <code>Use Secure LDAP Protocol</code> is checked</property>
         </properties>
       </dd>
       <dt><b>Thread unbind</b></dt>



Mime
View raw message