Skip to content

Commit

Permalink
Merge pull request #38 from sameeragunarathne/master
Browse files Browse the repository at this point in the history
Fix  configuring connection pool parameters
  • Loading branch information
keerthu authored Jun 13, 2019
2 parents e1596f6 + a9be126 commit a14249d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/wso2/carbon/connector/ldap/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,16 @@ public void connect(MessageContext messageContext) throws ConnectException {
String securityPrincipal = (String) getParameter(messageContext, LDAPConstants.SECURITY_PRINCIPAL);
String securityCredentials = (String) getParameter(messageContext, LDAPConstants.SECURITY_CREDENTIALS);
LDAPUtils.storeAdminLoginDatails(messageContext, providerUrl, securityPrincipal, securityCredentials);
//connection pooling parameters
String connectionPoolingEnabled = (String) getParameter(messageContext,
LDAPConstants.CONNECTION_POOLING_ENABLED);
String connectionPoolingProtocol = (String) getParameter(messageContext,
LDAPConstants.CONNECTION_POOLING_PROTOCOL);
String connectionPoolingInitSize = (String) getParameter(messageContext,
LDAPConstants.CONNECTION_POOLING_INIT_SIZE);
String connectionPoolingMaxSize = (String) getParameter(messageContext,
LDAPConstants.CONNECTION_POOLING_MAX_SIZE);
LDAPUtils.setConnectionPoolingParameters(messageContext, connectionPoolingEnabled, connectionPoolingProtocol,
connectionPoolingInitSize, connectionPoolingMaxSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public class LDAPConstants {
"org.wso2.carbon.connector.security.MySSLSocketFactory";
public static final String JAVA_NAMING_LDAP_ATTRIBUTE_BINARY =
"java.naming.ldap.attributes.binary";
public static final String COM_SUN_JNDI_LDAP_CONNECT_POOL = "com.sun.jndi.ldap.connect.pool";
public static final String COM_SUN_JNDI_LDAP_CONNECT_POOL_PROTOCOL = "com.sun.jndi.ldap.connect.pool.protocol";
public static final String COM_SUN_JNDI_LDAP_CONNECT_POOL_INITSIZE = "com.sun.jndi.ldap.connect.pool.initsize";
public static final String COM_SUN_JNDI_LDAP_CONNECT_POOL_MAXSIZE = "com.sun.jndi.ldap.connect.pool.maxsize";
public static final String CONNECTION_POOLING_ENABLED = "connectionPoolingEnabled";
public static final String CONNECTION_POOLING_PROTOCOL = "connectionPoolingProtocol";
public static final String CONNECTION_POOLING_INIT_SIZE = "connectionPoolingInitSize";
public static final String CONNECTION_POOLING_MAX_SIZE = "connectionPoolingMaxSize";
public static final String COM_JAVA_JNDI_LDAP_READ_TIMEOUT = "com.sun.jndi.ldap.read.timeout";
public static final String TIMEOUT = "timeout";

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/wso2/carbon/connector/ldap/LDAPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ protected static DirContext getDirectoryContext(MessageContext messageContext)
boolean disableSSLCertificateChecking = Boolean.valueOf(LDAPUtils.lookupContextParams(
messageContext, LDAPConstants.DISABLE_SSL_CERT_CHECKING));
String timeout = LDAPUtils.lookupContextParams(messageContext, LDAPConstants.TIMEOUT);
boolean connectionPoolingEnabled = Boolean
.valueOf(LDAPUtils.lookupContextParams(messageContext, LDAPConstants.CONNECTION_POOLING_ENABLED));
String connectionPoolingProtocol = LDAPUtils
.lookupContextParams(messageContext, LDAPConstants.CONNECTION_POOLING_PROTOCOL);
String connectionPoolingInitSize = LDAPUtils
.lookupContextParams(messageContext, LDAPConstants.CONNECTION_POOLING_INIT_SIZE);
String connectionPoolingMaxSize = LDAPUtils
.lookupContextParams(messageContext, LDAPConstants.CONNECTION_POOLING_MAX_SIZE);

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, LDAPConstants.COM_SUN_JNDI_LDAP_LDAPCTXFACTORY);
Expand All @@ -72,6 +80,18 @@ protected static DirContext getDirectoryContext(MessageContext messageContext)
env.put(LDAPConstants.JAVA_NAMING_LDAP_FACTORY_SOCKET,
LDAPConstants.ORG_WSO2_CARBON_CONNECTOR_SECURITY_MYSSLSOCKETFACTORY);
}
env.put(LDAPConstants.COM_SUN_JNDI_LDAP_CONNECT_POOL, String.valueOf(connectionPoolingEnabled));
if (connectionPoolingEnabled) {
if (StringUtils.isNotEmpty(connectionPoolingProtocol)) {
env.put(LDAPConstants.COM_SUN_JNDI_LDAP_CONNECT_POOL_PROTOCOL, connectionPoolingProtocol);
}
if (StringUtils.isNotEmpty(connectionPoolingInitSize)) {
env.put(LDAPConstants.COM_SUN_JNDI_LDAP_CONNECT_POOL_INITSIZE, connectionPoolingInitSize);
}
if (StringUtils.isNotEmpty(connectionPoolingMaxSize)) {
env.put(LDAPConstants.COM_SUN_JNDI_LDAP_CONNECT_POOL_MAXSIZE, connectionPoolingMaxSize);
}
}

DirContext ctx = null;
ctx = new InitialDirContext(env);
Expand All @@ -89,6 +109,14 @@ public static void storeAdminLoginDatails(MessageContext ctxt, String url, Strin
ctxt.setProperty(LDAPConstants.SECURITY_CREDENTIALS, password);
}

public static void setConnectionPoolingParameters(MessageContext ctxt, String poolingEnabled, String protocol,
String initSize, String maxSize) {
ctxt.setProperty(LDAPConstants.CONNECTION_POOLING_ENABLED, poolingEnabled);
ctxt.setProperty(LDAPConstants.CONNECTION_POOLING_PROTOCOL, protocol);
ctxt.setProperty(LDAPConstants.CONNECTION_POOLING_INIT_SIZE, initSize);
ctxt.setProperty(LDAPConstants.CONNECTION_POOLING_MAX_SIZE, maxSize);
}

public static void preparePayload(MessageContext messageContext, OMElement element) {
SOAPBody soapBody = messageContext.getEnvelope().getBody();
for (Iterator itr = soapBody.getChildElements(); itr.hasNext(); ) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/ldap_config/init.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<parameter name="securityCredentials"
description="Password of the user used to log in to LDAP."/>
<parameter name="timeout" description="Timeout duration of the LDAP request."/>
<parameter name="connectionPoolingEnabled" description="Property to enable/disable connection pooling."/>
<parameter name="connectionPoolingProtocol"
description="A list of space-separated protocol types of connections that may be pooled. Valid types are 'plain' and 'ssl'"/>
<parameter name="connectionPoolingInitSize"
description="The string representation of an integer that represents the number of connections per connection identity to create when initially creating a connection for the identity."/>
<parameter name="connectionPoolingMaxSize"
description="The string representation of an integer that represents the maximum number of connections per connection identity that can be maintained concurrently."/>

<sequence>
<property expression="$func:secureConnection" name="secureConnection" scope="default"
Expand All @@ -41,6 +48,18 @@
expression="$func:securityCredentials" name="securityCredentials"
scope="default" type="STRING"/>
<property name="timeout" expression="$func:timeout"/>
<property
expression="$func:connectionPoolingEnabled" name="connectionPoolingEnabled"
scope="default" type="STRING"/>
<property
expression="$func:connectionPoolingProtocol" name="connectionPoolingProtocol"
scope="default" type="STRING"/>
<property
expression="$func:connectionPoolingInitSize" name="connectionPoolingInitSize"
scope="default" type="STRING"/>
<property
expression="$func:connectionPoolingMaxSize" name="connectionPoolingMaxSize"
scope="default" type="STRING"/>
<class name="org.wso2.carbon.connector.ldap.Init"/>
</sequence>
</template>

0 comments on commit a14249d

Please sign in to comment.