svn commit: r1738421 - in /ofbiz/branches/release15.12: ./ framework/base/src/org/ofbiz/base/util/ specialpurpose/passport/ specialpurpose/passport/lib/ specialpurpose/passport/src/org/ofbiz/passport/event/ specialpurpose/passport/src/org/ofbiz/passpor...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1738421 - in /ofbiz/branches/release15.12: ./ framework/base/src/org/ofbiz/base/util/ specialpurpose/passport/ specialpurpose/passport/lib/ specialpurpose/passport/src/org/ofbiz/passport/event/ specialpurpose/passport/src/org/ofbiz/passpor...

jleroux@apache.org
Author: jleroux
Date: Sun Apr 10 11:42:38 2016
New Revision: 1738421

URL: http://svn.apache.org/viewvc?rev=1738421&view=rev
Log:
"Applied fix from trunk for revision: "


Removed:
    ofbiz/branches/release15.12/specialpurpose/passport/lib/
Modified:
    ofbiz/branches/release15.12/   (props changed)
    ofbiz/branches/release15.12/framework/base/src/org/ofbiz/base/util/UtilHttp.java
    ofbiz/branches/release15.12/specialpurpose/passport/build.xml
    ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/GitHubEvents.java
    ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/LinkedInEvents.java
    ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/GitHubAuthenticator.java
    ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/LinkedInAuthenticator.java
    ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/util/PassportUtil.java
    ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java

Propchange: ofbiz/branches/release15.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Apr 10 11:42:38 2016
@@ -9,4 +9,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/trunk:1722712,1723007,1723248,1724402,1724411,1724566,1724689,1724763,1724916,1724918,1724925,1724930,1724940,1724943,1724946,1724951,1724957,1724975,1724978,1725006,1725217,1725257,1725561,1725574,1726388,1726486,1726493,1726828,1728398,1728411,1729005,1729078,1729609,1729809,1730035,1730456,1730735-1730736,1730747,1730758,1730882,1730889,1731382,1731396,1732454,1732570,1732721,1733951,1733956,1734246,1734269,1734276,1734912,1734918,1735244,1735385,1735398,1735569,1735731,1735734,1735750,1735753,1735756,1735759,1735773,1736083,1736087,1736272,1736434,1736628,1736851,1736854,1737156,1737440,1738235,1738303
+/ofbiz/trunk:1722712,1723007,1723248,1724402,1724411,1724566,1724689,1724763,1724916,1724918,1724925,1724930,1724940,1724943,1724946,1724951,1724957,1724975,1724978,1725006,1725217,1725257,1725561,1725574,1726388,1726486,1726493,1726828,1728398,1728411,1729005,1729078,1729609,1729809,1730035,1730456,1730735-1730736,1730747,1730758,1730882,1730889,1731382,1731396,1732454,1732570,1732721,1733951,1733956,1734246,1734269,1734276,1734912,1734918,1735021,1735244,1735385,1735398,1735569,1735731,1735734,1735750,1735753,1735756,1735759,1735773,1736083,1736087,1736272,1736434,1736628,1736851,1736854,1737156,1737440,1738235,1738303

Modified: ofbiz/branches/release15.12/framework/base/src/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/framework/base/src/org/ofbiz/base/util/UtilHttp.java?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/framework/base/src/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/branches/release15.12/framework/base/src/org/ofbiz/base/util/UtilHttp.java Sun Apr 10 11:42:38 2016
@@ -43,12 +43,19 @@ import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.TimeZone;
 
+import javax.net.ssl.SSLContext;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
 import org.apache.commons.lang.RandomStringUtils;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContexts;
 import org.apache.oro.text.regex.MalformedPatternException;
 import org.apache.oro.text.regex.Pattern;
 import org.apache.oro.text.regex.PatternMatcher;
@@ -1439,4 +1446,28 @@ public class UtilHttp {
         response.setHeader("Content-Disposition", String.format("%s; filename=\"%s\"", dispositionType, filename));
     }
 
+    public static CloseableHttpClient getAllowAllHttpClient() {
+        return getAllowAllHttpClient("component://base/config/ofbizssl.jks", "changeit");
+    }
+
+    public static CloseableHttpClient getAllowAllHttpClient(String jksStoreFileName, String jksStorePassword) {
+        try {
+            // Trust own CA and all self-signed certs
+            SSLContext sslContext = SSLContexts.custom()
+                    .loadTrustMaterial(FileUtil.getFile(jksStoreFileName), jksStorePassword.toCharArray(),
+                            new TrustSelfSignedStrategy())
+                    .build();
+            // No host name verifier
+            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
+                    sslContext,
+                    NoopHostnameVerifier.INSTANCE);
+            CloseableHttpClient httpClient = HttpClients.custom()
+                    .setSSLSocketFactory(sslsf)
+                    .build();
+            return httpClient;
+        } catch (Exception e) {
+            return HttpClients.createDefault();
+        }
+    }
+
 }

Modified: ofbiz/branches/release15.12/specialpurpose/passport/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/passport/build.xml?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/passport/build.xml (original)
+++ ofbiz/branches/release15.12/specialpurpose/passport/build.xml Sun Apr 10 11:42:38 2016
@@ -30,9 +30,9 @@ under the License.
     <property name="ofbiz.home.dir" value="../.."/>
 
     <path id="local.class.path">
-        <fileset dir="${lib.dir}" includes="*.jar"/>
         <fileset dir="../../framework/base/lib" includes="*.jar"/>
         <fileset dir="../../framework/base/lib/j2eespecs" includes="*.jar"/>
+        <fileset dir="../../framework/base/lib/commons" includes="*.jar"/>
         <fileset dir="../../framework/base/build/lib" includes="*.jar"/>
         <fileset dir="../../framework/entity/lib" includes="*.jar"/>
         <fileset dir="../../framework/entity/build/lib" includes="*.jar"/>

Modified: ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/GitHubEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/GitHubEvents.java?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/GitHubEvents.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/GitHubEvents.java Sun Apr 10 11:42:38 2016
@@ -20,6 +20,8 @@ package org.ofbiz.passport.event;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.util.Map;
@@ -28,13 +30,15 @@ import java.util.Random;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.ofbiz.passport.user.GitHubAuthenticator;
 import org.ofbiz.passport.util.PassportUtil;
 import org.ofbiz.base.conversion.ConversionException;
@@ -52,6 +56,7 @@ import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityUtilProperties;
 import org.ofbiz.product.store.ProductStoreWorker;
 import org.ofbiz.service.LocalDispatcher;
 
@@ -164,25 +169,27 @@ public class GitHubEvents {
         String accessToken = null;
         String tokenType = null;
         
-        HttpClient jsonClient = new HttpClient();
-        PostMethod postMethod = new PostMethod(TokenEndpoint + TokenServiceUri);
         try {
-            HttpMethodParams params = new HttpMethodParams();
-            String queryString = "client_id=" + clientId
-                    + "&client_secret=" + secret
-                    + "&code=" + authorizationCode
-                    + "&redirect_uri=" + URLEncoder.encode(returnURI, "UTF-8");
-            // Debug.logInfo("GitHub get access token query string: " + queryString, module);
-            postMethod.setQueryString(queryString);
-            params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
-            postMethod.setParams(params);
-            postMethod.setRequestHeader(PassportUtil.ACCEPT_HEADER, "application/json");
-            jsonClient.executeMethod(postMethod);
-            // Debug.logInfo("GitHub get access token response code: " + postMethod.getStatusCode(), module);
-            // Debug.logInfo("GitHub get access token response content: " + postMethod.getResponseBodyAsString(1024), module);
-            if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
-                // Debug.logInfo("Json Response from GitHub: " + postMethod.getResponseBodyAsString(1024), module);
-                JSON jsonObject = JSON.from(postMethod.getResponseBodyAsString(1024));
+            URI uri = new URIBuilder()
+                    .setHost(TokenEndpoint)
+                    .setPath(TokenServiceUri)
+                    .setParameter("client_id", clientId)
+                    .setParameter("client_secret", secret)
+                    .setParameter("code", authorizationCode)
+                    .setParameter("redirect_uri", URLEncoder.encode(returnURI, "UTF-8"))
+                    .build();
+            HttpPost postMethod = new HttpPost(uri);
+            CloseableHttpClient jsonClient = HttpClients.custom().build();
+            // Debug.logInfo("GitHub get access token query string: " + postMethod.getURI(), module);
+            postMethod.setConfig(PassportUtil.StandardRequestConfig);
+            postMethod.setHeader(PassportUtil.ACCEPT_HEADER, "application/json");
+            CloseableHttpResponse postResponse = jsonClient.execute(postMethod);
+            String responseString = new BasicResponseHandler().handleResponse(postResponse);
+            // Debug.logInfo("GitHub get access token response code: " + postResponse.getStatusLine().getStatusCode(), module);
+            // Debug.logInfo("GitHub get access token response content: " + responseString, module);
+            if (postResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                // Debug.logInfo("Json Response from GitHub: " + responseString, module);
+                JSON jsonObject = JSON.from(responseString);
                 JSONToMap jsonMap = new JSONToMap();
                 Map<String, Object> userMap = jsonMap.convert(jsonObject);
                 accessToken = (String) userMap.get("access_token");
@@ -190,37 +197,29 @@ public class GitHubEvents {
                 // Debug.logInfo("Generated Access Token : " + accessToken, module);
                 // Debug.logInfo("Token Type: " + tokenType, module);
             } else {
-                String errMsg = UtilProperties.getMessage(resource, "GetOAuth2GitHubAccessTokenError", UtilMisc.toMap("error", postMethod.getResponseBodyAsString()), UtilHttp.getLocale(request));
+                String errMsg = UtilProperties.getMessage(resource, "GetOAuth2GitHubAccessTokenError", UtilMisc.toMap("error", responseString), UtilHttp.getLocale(request));
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
                 return "error";
             }
         } catch (UnsupportedEncodingException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
-        } catch (HttpException e) {
-            request.setAttribute("_ERROR_MESSAGE_", e.toString());
-            return "error";
         } catch (IOException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
         } catch (ConversionException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
-        } finally {
-            postMethod.releaseConnection();
-        }
+        } catch (URISyntaxException e) {
+            request.setAttribute("_ERROR_MESSAGE_", e.toString());
+            return "error";
+ }
         
         // Get User Profile
-        GetMethod getMethod = new GetMethod(ApiEndpoint + UserApiUri);
+        HttpGet getMethod = new HttpGet(ApiEndpoint + UserApiUri);
         Map<String, Object> userInfo = null;
         try {
             userInfo = GitHubAuthenticator.getUserInfo(getMethod, accessToken, tokenType, UtilHttp.getLocale(request));
-        } catch (HttpException e) {
-            request.setAttribute("_ERROR_MESSAGE_", e.toString());
-            return "error";
-        } catch (IOException e) {
-            request.setAttribute("_ERROR_MESSAGE_", e.toString());
-            return "error";
         } catch (AuthenticatorException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
@@ -285,12 +284,12 @@ public class GitHubEvents {
                 String userLoginId = authn.createUser(userInfo);
                 userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false);
             }
-            String password = PassportUtil.randomString();
+            String autoPassword = RandomStringUtils.randomAlphanumeric(Integer.parseInt(EntityUtilProperties.getPropertyValue("security", "password.length.min", "5", delegator)));
             boolean useEncryption = "true".equals(UtilProperties.getPropertyValue("security", "password.encrypt"));
-            userLogin.set("currentPassword", useEncryption ? HashCrypt.digestHash(LoginServices.getHashType(), null, password) : password);
+            userLogin.set("currentPassword", useEncryption ? HashCrypt.digestHash(LoginServices.getHashType(), null, autoPassword) : autoPassword);
             userLogin.store();
             request.setAttribute("USERNAME", userLogin.getString("userLoginId"));
-            request.setAttribute("PASSWORD", password);
+            request.setAttribute("PASSWORD", autoPassword);
         } catch (GenericEntityException e) {
             Debug.logError(e.getMessage(), module);
             request.setAttribute("_ERROR_MESSAGE_", e.toString());

Modified: ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/LinkedInEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/LinkedInEvents.java?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/LinkedInEvents.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/event/LinkedInEvents.java Sun Apr 10 11:42:38 2016
@@ -20,6 +20,8 @@ package org.ofbiz.passport.event;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.util.Map;
@@ -29,13 +31,15 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.ofbiz.passport.user.LinkedInAuthenticator;
 import org.ofbiz.passport.util.PassportUtil;
 import org.ofbiz.base.conversion.ConversionException;
@@ -53,6 +57,7 @@ import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityUtilProperties;
 import org.ofbiz.product.store.ProductStoreWorker;
 import org.ofbiz.service.LocalDispatcher;
 import org.w3c.dom.Document;
@@ -164,58 +169,55 @@ public class LinkedInEvents {
         // Use the authorization code to obtain an access token
         String accessToken = null;
         
-        HttpClient jsonClient = new HttpClient();
-        PostMethod postMethod = new PostMethod(TokenEndpoint + TokenServiceUri);
         try {
-            HttpMethodParams params = new HttpMethodParams();
-            String queryString = "client_id=" + clientId
-                    + "&client_secret=" + secret
-                    + "&grant_type=authorization_code"
-                    + "&code=" + authorizationCode
-                    + "&redirect_uri=" + URLEncoder.encode(returnURI, "UTF-8");
-            // Debug.logInfo("LinkedIn get access token query string: " + queryString, module);
-            postMethod.setQueryString(queryString);
-            params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
-            postMethod.setParams(params);
-            jsonClient.executeMethod(postMethod);
-            // Debug.logInfo("LinkedIn get access token response code: " + postMethod.getStatusCode(), module);
-            // Debug.logInfo("LinkedIn get access token response content: " + postMethod.getResponseBodyAsString(1024), module);
-            if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
-                // Debug.logInfo("Json Response from LinkedIn: " + postMethod.getResponseBodyAsString(1024), module);
-                JSON jsonObject = JSON.from(postMethod.getResponseBodyAsString(1024));
+            URI uri = new URIBuilder()
+                    .setHost(TokenEndpoint)
+                    .setPath(TokenServiceUri)
+                    .setParameter("client_id", clientId)
+                    .setParameter("client_secret", secret)
+                    .setParameter("grant_type", "authorization_code")
+                    .setParameter("code", authorizationCode)
+                    .setParameter("redirect_uri", URLEncoder.encode(returnURI, "UTF-8"))
+                    .build();
+            HttpPost postMethod = new HttpPost(uri);
+            CloseableHttpClient jsonClient = HttpClients.custom().build();
+            // Debug.logInfo("LinkedIn get access token query string: " + postMethod.getURI(), module);
+            postMethod.setConfig(PassportUtil.StandardRequestConfig);
+            CloseableHttpResponse postResponse = jsonClient.execute(postMethod);
+            String responseString = new BasicResponseHandler().handleResponse(postResponse);
+            // Debug.logInfo("LinkedIn get access token response code: " + postResponse.getStatusLine().getStatusCode(), module);
+            // Debug.logInfo("LinkedIn get access token response content: " + responseString, module);
+            if (postResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                // Debug.logInfo("Json Response from LinkedIn: " + responseString, module);
+                JSON jsonObject = JSON.from(responseString);
                 JSONToMap jsonMap = new JSONToMap();
                 Map<String, Object> userMap = jsonMap.convert(jsonObject);
                 accessToken = (String) userMap.get("access_token");
                 // Debug.logInfo("Generated Access Token : " + accessToken, module);
             } else {
-                String errMsg = UtilProperties.getMessage(resource, "GetOAuth2LinkedInAccessTokenError", UtilMisc.toMap("error", postMethod.getResponseBodyAsString()), UtilHttp.getLocale(request));
+                String errMsg = UtilProperties.getMessage(resource, "GetOAuth2LinkedInAccessTokenError", UtilMisc.toMap("error", responseString), UtilHttp.getLocale(request));
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
                 return "error";
             }
         } catch (UnsupportedEncodingException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
-        } catch (HttpException e) {
-            request.setAttribute("_ERROR_MESSAGE_", e.toString());
-            return "error";
         } catch (IOException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
         } catch (ConversionException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
-        } finally {
-            postMethod.releaseConnection();
-        }
+        } catch (URISyntaxException e) {
+            request.setAttribute("_ERROR_MESSAGE_", e.toString());
+            return "error";
+ }
         
         // Get User Profile
-        GetMethod getMethod = new GetMethod(TokenEndpoint + UserApiUri + "?oauth2_access_token=" + accessToken);
+        HttpGet getMethod = new HttpGet(TokenEndpoint + UserApiUri + "?oauth2_access_token=" + accessToken);
         Document userInfo = null;
         try {
             userInfo = LinkedInAuthenticator.getUserInfo(getMethod, UtilHttp.getLocale(request));
-        } catch (HttpException e) {
-            request.setAttribute("_ERROR_MESSAGE_", e.toString());
-            return "error";
         } catch (IOException e) {
             request.setAttribute("_ERROR_MESSAGE_", e.toString());
             return "error";
@@ -289,12 +291,12 @@ public class LinkedInEvents {
                 String userLoginId = authn.createUser(userInfo);
                 userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false);
             }
-            String password = PassportUtil.randomString();
+            String autoPassword = RandomStringUtils.randomAlphanumeric(Integer.parseInt(EntityUtilProperties.getPropertyValue("security", "password.length.min", "5", delegator)));
             boolean useEncryption = "true".equals(UtilProperties.getPropertyValue("security", "password.encrypt"));
-            userLogin.set("currentPassword", useEncryption ? HashCrypt.digestHash(LoginServices.getHashType(), null, password) : password);
+            userLogin.set("currentPassword", useEncryption ? HashCrypt.digestHash(LoginServices.getHashType(), null, autoPassword) : autoPassword);
             userLogin.store();
             request.setAttribute("USERNAME", userLogin.getString("userLoginId"));
-            request.setAttribute("PASSWORD", password);
+            request.setAttribute("PASSWORD", autoPassword);
         } catch (GenericEntityException e) {
             Debug.logError(e.getMessage(), module);
             request.setAttribute("_ERROR_MESSAGE_", e.toString());

Modified: ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/GitHubAuthenticator.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/GitHubAuthenticator.java?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/GitHubAuthenticator.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/GitHubAuthenticator.java Sun Apr 10 11:42:38 2016
@@ -27,12 +27,6 @@ import java.sql.Timestamp;
 
 import javax.transaction.Transaction;
 
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.ofbiz.passport.event.GitHubEvents;
 import org.ofbiz.passport.user.GitHubUserGroupMapper;
 import org.ofbiz.passport.util.PassportUtil;
@@ -47,6 +41,13 @@ import org.ofbiz.entity.GenericEntityExc
 import org.ofbiz.entity.transaction.TransactionUtil;
 import org.ofbiz.entity.transaction.GenericTransactionException;
 import org.ofbiz.entity.util.EntityUtil;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.ofbiz.base.conversion.ConversionException;
 import org.ofbiz.base.conversion.JSONConverters.JSONToMap;
 import org.ofbiz.base.lang.JSON;
@@ -98,7 +99,7 @@ public class GitHubAuthenticator impleme
      */
     public boolean authenticate(String userLoginId, String password, boolean isServiceAuth) throws AuthenticatorException {
         Map<String, Object> user = null;
-        GetMethod getMethod = null;
+        HttpGet getMethod = null;
         try {
             GenericValue userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false);
             String externalAuthId = userLogin.getString("externalAuthId");
@@ -107,16 +108,12 @@ public class GitHubAuthenticator impleme
                 String accessToken = gitHubUser.getString("accessToken");
                 String tokenType = gitHubUser.getString("tokenType");
                 if (UtilValidate.isNotEmpty(accessToken)) {
-                    getMethod = new GetMethod(GitHubEvents.ApiEndpoint + GitHubEvents.UserApiUri);
+                    getMethod = new HttpGet(GitHubEvents.ApiEndpoint + GitHubEvents.UserApiUri);
                     user = GitHubAuthenticator.getUserInfo(getMethod, accessToken, tokenType, Locale.getDefault());
                 }
             }
         } catch (GenericEntityException e) {
             throw new AuthenticatorException(e.getMessage(), e);
-        } catch (HttpException e) {
-            throw new AuthenticatorException(e.getMessage(), e);
-        } catch (IOException e) {
-            throw new AuthenticatorException(e.getMessage(), e);
         } catch (AuthenticatorException e) {
             throw new AuthenticatorException(e.getMessage(), e);
         } finally {
@@ -208,7 +205,7 @@ public class GitHubAuthenticator impleme
 
     private Map<String, Object> getGitHubUserinfo(String userLoginId) throws AuthenticatorException {
         Map<String, Object> user = null;
-        GetMethod getMethod = null;
+        HttpGet getMethod = null;
         try {
             GenericValue userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false);
             String externalAuthId = userLogin.getString("externalAuthId");
@@ -217,22 +214,14 @@ public class GitHubAuthenticator impleme
                 String accessToken = gitHubUser.getString("accessToken");
                 String tokenType = gitHubUser.getString("tokenType");
                 if (UtilValidate.isNotEmpty(accessToken)) {
-                    getMethod = new GetMethod(GitHubEvents.ApiEndpoint + GitHubEvents.UserApiUri);
+                    getMethod = new HttpGet(GitHubEvents.ApiEndpoint + GitHubEvents.UserApiUri);
                     user = getUserInfo(getMethod, accessToken, tokenType, Locale.getDefault());
                 }
             }
         } catch (GenericEntityException e) {
             throw new AuthenticatorException(e.getMessage(), e);
-        } catch (HttpException e) {
-            throw new AuthenticatorException(e.getMessage(), e);
-        } catch (IOException e) {
-            throw new AuthenticatorException(e.getMessage(), e);
         } catch (AuthenticatorException e) {
             throw new AuthenticatorException(e.getMessage(), e);
-        } finally {
-            if (getMethod != null) {
-                getMethod.releaseConnection();
-            }
         }
         return user;
     }
@@ -387,22 +376,36 @@ public class GitHubAuthenticator impleme
         return "true".equalsIgnoreCase(UtilProperties.getPropertyValue(props, "github.authenticator.enabled", "true"));
     }
 
-    public static Map<String, Object> getUserInfo(GetMethod getMethod, String accessToken, String tokenType, Locale locale) throws HttpException, IOException, AuthenticatorException {
+    public static Map<String, Object> getUserInfo(HttpGet httpGet, String accessToken, String tokenType, Locale locale) throws AuthenticatorException {
         JSON userInfo = null;
-        HttpClient jsonClient = new HttpClient();
-        HttpMethodParams params = new HttpMethodParams();
-        params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
-        getMethod.setParams(params);
-        getMethod.setRequestHeader(PassportUtil.AUTHORIZATION_HEADER, tokenType + " " + accessToken);
-        getMethod.setRequestHeader(PassportUtil.ACCEPT_HEADER, "application/json");
-        jsonClient.executeMethod(getMethod);
-        if (getMethod.getStatusCode() == HttpStatus.SC_OK) {
-            Debug.logInfo("Json Response from GitHub: " + getMethod.getResponseBodyAsString(), module);
-            userInfo = JSON.from(getMethod.getResponseBodyAsString());
-        } else {
-            String errMsg = UtilProperties.getMessage(resource, "GetOAuth2AccessTokenError", UtilMisc.toMap("error", getMethod.getResponseBodyAsString()), locale);
-            throw new AuthenticatorException(errMsg);
-        }
+        httpGet.setConfig(PassportUtil.StandardRequestConfig);
+        CloseableHttpClient jsonClient = HttpClients.custom().build();
+        httpGet.setHeader(PassportUtil.AUTHORIZATION_HEADER, tokenType + " " + accessToken);
+        httpGet.setHeader(PassportUtil.ACCEPT_HEADER, "application/json");
+        CloseableHttpResponse getResponse = null;
+ try {
+ getResponse = jsonClient.execute(httpGet);
+            String responseString = new BasicResponseHandler().handleResponse(getResponse);
+        if (getResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+            // Debug.logInfo("Json Response from GitHub: " + responseString, module);
+            userInfo = JSON.from(responseString);
+        } else {
+            String errMsg = UtilProperties.getMessage(resource, "GetOAuth2AccessTokenError", UtilMisc.toMap("error", responseString), locale);
+            throw new AuthenticatorException(errMsg);
+        }
+ } catch (ClientProtocolException e) {
+            throw new AuthenticatorException(e.getMessage());
+ } catch (IOException e) {
+            throw new AuthenticatorException(e.getMessage());
+ } finally {
+ if (getResponse != null) {
+            try {
+ getResponse.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
         JSONToMap jsonMap = new JSONToMap();
         Map<String, Object> userMap;
         try {

Modified: ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/LinkedInAuthenticator.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/LinkedInAuthenticator.java?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/LinkedInAuthenticator.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/user/LinkedInAuthenticator.java Sun Apr 10 11:42:38 2016
@@ -28,13 +28,14 @@ import java.sql.Timestamp;
 import javax.transaction.Transaction;
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.ofbiz.passport.event.LinkedInEvents;
+import org.ofbiz.passport.util.PassportUtil;
 import org.ofbiz.common.authentication.api.Authenticator;
 import org.ofbiz.common.authentication.api.AuthenticatorException;
 import org.ofbiz.service.LocalDispatcher;
@@ -99,7 +100,7 @@ public class LinkedInAuthenticator imple
      */
     public boolean authenticate(String userLoginId, String password, boolean isServiceAuth) throws AuthenticatorException {
         Document user = null;
-        GetMethod getMethod = null;
+        HttpGet getMethod = null;
         try {
             GenericValue userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false);
             String externalAuthId = userLogin.getString("externalAuthId");
@@ -107,14 +108,12 @@ public class LinkedInAuthenticator imple
             if (UtilValidate.isNotEmpty(linkedInUser)) {
                 String accessToken = linkedInUser.getString("accessToken");
                 if (UtilValidate.isNotEmpty(accessToken)) {
-                    getMethod = new GetMethod(LinkedInEvents.TokenEndpoint + LinkedInEvents.UserApiUri  + "?oauth2_access_token=" + accessToken);
+                    getMethod = new HttpGet(LinkedInEvents.TokenEndpoint + LinkedInEvents.UserApiUri  + "?oauth2_access_token=" + accessToken);
                     user = LinkedInAuthenticator.getUserInfo(getMethod, Locale.getDefault());
                 }
             }
         } catch (GenericEntityException e) {
             throw new AuthenticatorException(e.getMessage(), e);
-        } catch (HttpException e) {
-            throw new AuthenticatorException(e.getMessage(), e);
         } catch (IOException e) {
             throw new AuthenticatorException(e.getMessage(), e);
         } catch (AuthenticatorException e) {
@@ -213,7 +212,7 @@ public class LinkedInAuthenticator imple
 
     private Document getLinkedInUserinfo(String userLoginId) throws AuthenticatorException {
         Document user = null;
-        GetMethod getMethod = null;
+        HttpGet getMethod = null;
         try {
             GenericValue userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", userLoginId), false);
             String externalAuthId = userLogin.getString("externalAuthId");
@@ -221,14 +220,12 @@ public class LinkedInAuthenticator imple
             if (UtilValidate.isNotEmpty(linkedInUser)) {
                 String accessToken = linkedInUser.getString("accessToken");
                 if (UtilValidate.isNotEmpty(accessToken)) {
-                    getMethod = new GetMethod(LinkedInEvents.TokenEndpoint + LinkedInEvents.UserApiUri + "?oauth2_access_token=" + accessToken);
+                    getMethod = new HttpGet(LinkedInEvents.TokenEndpoint + LinkedInEvents.UserApiUri + "?oauth2_access_token=" + accessToken);
                     user = getUserInfo(getMethod, Locale.getDefault());
                 }
             }
         } catch (GenericEntityException e) {
             throw new AuthenticatorException(e.getMessage(), e);
-        } catch (HttpException e) {
-            throw new AuthenticatorException(e.getMessage(), e);
         } catch (IOException e) {
             throw new AuthenticatorException(e.getMessage(), e);
         } catch (AuthenticatorException e) {
@@ -399,18 +396,17 @@ public class LinkedInAuthenticator imple
         return "true".equalsIgnoreCase(UtilProperties.getPropertyValue(props, "linked.authenticator.enabled", "true"));
     }
 
-    public static Document getUserInfo(GetMethod getMethod, Locale locale) throws HttpException, IOException, AuthenticatorException, SAXException, ParserConfigurationException {
+    public static Document getUserInfo(HttpGet httpGet, Locale locale) throws IOException, AuthenticatorException, SAXException, ParserConfigurationException {
         Document userInfo = null;
-        HttpClient jsonClient = new HttpClient();
-        HttpMethodParams params = new HttpMethodParams();
-        params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
-        getMethod.setParams(params);
-        jsonClient.executeMethod(getMethod);
-        if (getMethod.getStatusCode() == HttpStatus.SC_OK) {
-            Debug.logInfo("Json Response from LinkedIn: " + getMethod.getResponseBodyAsString(), module);
-            userInfo = UtilXml.readXmlDocument(getMethod.getResponseBodyAsString());
+        httpGet.setConfig(PassportUtil.StandardRequestConfig);
+        CloseableHttpClient jsonClient = HttpClients.custom().build();
+        CloseableHttpResponse getResponse = jsonClient.execute(httpGet);
+        String responseString = new BasicResponseHandler().handleResponse(getResponse);
+        if (getResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+            // Debug.logInfo("Json Response from LinkedIn: " + responseString, module);
+            userInfo = UtilXml.readXmlDocument(responseString);
         } else {
-            String errMsg = UtilProperties.getMessage(resource, "GetOAuth2AccessTokenError", UtilMisc.toMap("error", getMethod.getResponseBodyAsString()), locale);
+            String errMsg = UtilProperties.getMessage(resource, "GetOAuth2AccessTokenError", UtilMisc.toMap("error", responseString), locale);
             throw new AuthenticatorException(errMsg);
         }
         return userInfo;

Modified: ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/util/PassportUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/util/PassportUtil.java?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/util/PassportUtil.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/passport/src/org/ofbiz/passport/util/PassportUtil.java Sun Apr 10 11:42:38 2016
@@ -18,27 +18,12 @@
  *******************************************************************************/
 package org.ofbiz.passport.util;
 
-import java.io.IOException;
 import java.net.InetAddress;
-import java.net.Socket;
 import java.net.UnknownHostException;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.SSLContextBuilder;
-import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
 import org.ofbiz.base.util.Debug;
 
 public class PassportUtil {
@@ -105,6 +90,10 @@ public class PassportUtil {
 
     public static final String COMMON_APP_SECRET = "AppSecret";
     
+    public static final RequestConfig StandardRequestConfig = RequestConfig.custom()
+                                                                           .setCookieSpec(CookieSpecs.STANDARD)
+                                                                           .build();
+    
     protected PassportUtil() {
         // empty constructor
     }
@@ -128,69 +117,4 @@ public class PassportUtil {
         }
         return prefix;
     }
-
-    private static String randomString(int lo, int hi) {
-        int n = rand(lo, hi);
-        byte b[] = new byte[n];
-        for (int i = 0; i < n; i++) {
-            b[i] = (byte)rand('a', 'z');
-        }
-        return new String(b);
-    }
-
-    private static int rand(int lo, int hi) {
-        java.util.Random rn = new java.util.Random();
-        int n = hi - lo + 1;
-        int i = rn.nextInt() % n;
-        if (i < 0)
-                i = -i;
-        return lo + i;
-    }
-
-    public static String randomString() {
-        return randomString(8, 15);
-    }
-
-    public CloseableHttpClient getAllowAllHttpClient() {
-        try {
-            SSLContextBuilder builder = new SSLContextBuilder();
-            builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
-            SSLConnectionSocketFactory sf = new AllowAllSSLSocketFactory(builder.build());
-            CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sf).build();
-            return httpclient;
-        } catch (Exception e) {
-            return HttpClients.createDefault();
-        }
-    }
-
-    public class AllowAllSSLSocketFactory extends SSLConnectionSocketFactory {
-        SSLContext sslContext = SSLContext.getInstance("TLS");
-
-        public AllowAllSSLSocketFactory(SSLContext sslContext) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
-            super(sslContext);
-
-            TrustManager tm = new X509TrustManager() {
-                public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-                }
-
-                public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-                }
-
-                public X509Certificate[] getAcceptedIssuers() {
-                    return null;
-                }
-            };
-
-            sslContext.init(null, new TrustManager[] { tm }, null);
-        }
-
-        public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
-            return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
-        }
-
-        public Socket createSocket() throws IOException {
-            return sslContext.getSocketFactory().createSocket();
-        }
-    }
-
 }
\ No newline at end of file

Modified: ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java?rev=1738421&r1=1738420&r2=1738421&view=diff
==============================================================================
--- ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java (original)
+++ ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java Sun Apr 10 11:42:38 2016
@@ -18,12 +18,20 @@
  *******************************************************************************/
 package org.ofbiz.solr;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrRequest.METHOD;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
@@ -34,6 +42,7 @@ import org.ofbiz.base.component.Componen
 import org.ofbiz.base.component.ComponentException;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericEntityException;
@@ -41,7 +50,7 @@ import org.ofbiz.entity.GenericEntityExc
 /**
  * Solr utility class.
  */
-public abstract class SolrUtil {
+public final class SolrUtil {
     
     public static final String module = SolrUtil.class.getName();
     private static String[] solrProdAttribute = { "productId", "internalName", "manu", "size", "smallImage", "mediumImage", "largeImage", "listPrice", "defaultPrice", "inStock", "isVirtual" };
@@ -49,6 +58,22 @@ public abstract class SolrUtil {
     public static final String solrConfigName = "solrconfig.properties";
     public static final String solrUrl = makeSolrWebappUrl();
     
+    protected static final String socketTimeoutString = UtilProperties.getPropertyValue(solrConfigName, "solr.client.socket.timeout");
+    
+    protected static final String connectionTimeoutString = UtilProperties.getPropertyValue(solrConfigName, "solr.client.connection.timeout");
+    
+    protected static final String clientUsername = UtilProperties.getPropertyValue(solrConfigName, "solr.client.username");
+    
+    protected static final String clientPassword = UtilProperties.getPropertyValue(solrConfigName, "solr.client.password");
+
+    protected static final Integer socketTimeout = getSocketTimeout();
+    
+    protected static final Integer connectionTimeout = getConnectionTimeout();
+    
+    protected static final String trustSelfSignedCertString = UtilProperties.getPropertyValue(solrConfigName, "solr.client.trust.selfsigned.cert", "false");
+    
+    protected static final boolean trustSelfSignedCert = getTrustSelfSignedCert();
+    
     public static String makeSolrWebappUrl() {
         final String solrWebappProtocol = UtilProperties.getPropertyValue(solrConfigName, "solr.webapp.protocol");
         final String solrWebappDomainName = UtilProperties.getPropertyValue(solrConfigName, "solr.webapp.domainName");
@@ -58,14 +83,42 @@ public abstract class SolrUtil {
         String solrPort;
         if (UtilValidate.isNotEmpty(solrWebappPortOverride)) {
             solrPort = solrWebappPortOverride;
-        }
-        else {
+        } else {
             solrPort = UtilProperties.getPropertyValue("url", ("https".equals(solrWebappProtocol) ? "port.https" : "port.http"));
         }
         
         return solrWebappProtocol + "://" + solrWebappDomainName + ":" + solrPort + solrWebappPath;
     }
     
+    private static Integer getSocketTimeout() {
+        if (UtilValidate.isNotEmpty(socketTimeoutString)) {
+            try {
+                return Integer.parseInt(socketTimeoutString);
+            } catch (Exception e) {
+                return null;
+            }
+        }
+        return null;
+    }
+
+    private static Integer getConnectionTimeout() {
+        if (UtilValidate.isNotEmpty(connectionTimeoutString)) {
+            try {
+                return Integer.parseInt(connectionTimeoutString);
+            } catch (Exception e) {
+                return null;
+            }
+        }
+        return null;
+    }
+
+    private static boolean getTrustSelfSignedCert() {
+        if ("true".equals(trustSelfSignedCertString)) {
+            return true;
+        }
+        return false;
+    }
+
     public static boolean isSolrEcaEnabled() {
         Boolean ecaEnabled = null;
         String sysProp = System.getProperty("ofbiz.solr.eca.enabled");
@@ -181,18 +234,18 @@ public abstract class SolrUtil {
         return doc1;
     }
     
-    public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, boolean displayproducts, int viewIndex, int viewSize) {
-        return categoriesAvailable(catalogId,categoryId,productId,null,displayproducts,viewIndex,viewSize);
+    public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, boolean displayproducts, int viewIndex, int viewSize, String solrIndexName) {
+        return categoriesAvailable(catalogId, categoryId, productId, null, displayproducts, viewIndex, viewSize, solrIndexName);
     }
 
-    public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, String facetPrefix, boolean displayproducts, int viewIndex, int viewSize) {
+    public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, String facetPrefix, boolean displayproducts, int viewIndex, int viewSize, String solrIndexName) {
         // create the data model
         Map<String, Object> result = new HashMap<String, Object>();
         HttpSolrClient client = null;
         QueryResponse returnMap = new QueryResponse();
         try {
             // do the basic query
-            client = new HttpSolrClient(solrUrl);
+            client = getHttpSolrClient(solrIndexName);
             // create Query Object
             String query = "inStock[1 TO *]";
             if (categoryId != null)
@@ -235,4 +288,48 @@ public abstract class SolrUtil {
         return result;
     }
 
+    public static SolrUtil getInstance() {
+        return new SolrUtil();
+    }
+
+    public static HttpSolrClient getHttpSolrClient(String solrIndexName) throws ClientProtocolException, IOException {
+        HttpClientContext httpContext = HttpClientContext.create();
+        
+        CloseableHttpClient httpClient = null;
+        if (trustSelfSignedCert) {
+            httpClient = UtilHttp.getAllowAllHttpClient();
+        } else {
+            httpClient = HttpClients.createDefault();
+        }
+        
+        RequestConfig requestConfig = null;
+        if (UtilValidate.isNotEmpty(socketTimeout) && UtilValidate.isNotEmpty(connectionTimeout)) {
+            requestConfig = RequestConfig.custom()
+                  .setSocketTimeout(socketTimeout)
+                  .setConnectTimeout(connectionTimeout)
+                  .setRedirectsEnabled(true)
+                  .build();
+        } else if (UtilValidate.isNotEmpty(socketTimeout)) {
+            requestConfig = RequestConfig.custom()
+                    .setSocketTimeout(socketTimeout)
+                    .setRedirectsEnabled(true)
+                    .build();
+        } else if (UtilValidate.isNotEmpty(connectionTimeout)) {
+            requestConfig = RequestConfig.custom()
+                    .setConnectTimeout(connectionTimeout)
+                    .setRedirectsEnabled(true)
+                    .build();
+        } else {
+            requestConfig = RequestConfig.custom()
+                    .setRedirectsEnabled(true)
+                    .build();
+        }
+
+        HttpGet httpLogin = new HttpGet(solrUrl + "/control/login?USERNAME=" + clientUsername + "&PASSWORD=" + clientPassword);
+        httpLogin.setConfig(requestConfig);
+        CloseableHttpResponse loginResponse = httpClient.execute(httpLogin, httpContext);
+        loginResponse.close();
+        return new HttpSolrClient(solrUrl + "/" + solrIndexName, httpClient);
+    }
+
 }