306N/A/*
306N/A * CDDL HEADER START
306N/A *
306N/A * The contents of this file are subject to the terms of the
306N/A * Common Development and Distribution License, Version 1.0 only
306N/A * (the "License"). You may not use this file except in compliance
306N/A * with the License.
306N/A *
6982N/A * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
6982N/A * or http://forgerock.org/license/CDDLv1.0.html.
306N/A * See the License for the specific language governing permissions
306N/A * and limitations under the License.
306N/A *
306N/A * When distributing Covered Code, include this CDDL HEADER in each
6982N/A * file and include the License file at legal-notices/CDDLv1_0.txt.
6982N/A * If applicable, add the following below this CDDL HEADER, with the
6982N/A * fields enclosed by brackets "[]" replaced with your own identifying
6982N/A * information:
306N/A * Portions Copyright [yyyy] [name of copyright owner]
306N/A *
306N/A * CDDL HEADER END
306N/A *
306N/A *
4495N/A * Copyright 2006-2009 Sun Microsystems, Inc.
6442N/A * Portions copyright 2012-2013 ForgeRock AS.
306N/A */
306N/Apackage org.opends.server.protocols.ldap;
306N/A
3853N/Aimport static org.opends.server.config.ConfigConstants.*;
3853N/Aimport static org.testng.Assert.*;
3853N/A
3853N/Aimport java.util.Collection;
306N/Aimport java.util.LinkedList;
6442N/Aimport java.util.List;
6442N/Aimport java.util.Map;
306N/A
3853N/Aimport org.opends.messages.Message;
3853N/Aimport org.opends.server.TestCaseUtils;
1008N/Aimport org.opends.server.admin.std.server.LDAPConnectionHandlerCfg;
306N/Aimport org.opends.server.api.ClientConnection;
1008N/Aimport org.opends.server.config.ConfigException;
306N/Aimport org.opends.server.core.DirectoryServer;
306N/Aimport org.opends.server.types.Attribute;
3853N/Aimport org.opends.server.types.AttributeType;
3853N/Aimport org.opends.server.types.Attributes;
3853N/Aimport org.opends.server.types.DN;
306N/Aimport org.opends.server.types.Entry;
3853N/Aimport org.opends.server.types.SSLClientAuthPolicy;
306N/Aimport org.testng.annotations.BeforeClass;
306N/Aimport org.testng.annotations.Test;
306N/A
6442N/A@SuppressWarnings("javadoc")
306N/Apublic class TestLDAPConnectionHandler extends LdapTestCase {
306N/A
2086N/A private static Message reasonMsg= Message.raw("Don't need a reason.");
306N/A
1031N/A /**
1031N/A * Once-only initialization.
1031N/A *
1031N/A * @throws Exception
1031N/A * If an unexpected error occurred.
1031N/A */
1031N/A @BeforeClass
1031N/A public void setUp() throws Exception {
1031N/A // This test suite depends on having the schema available, so we'll
1031N/A // start the server.
1031N/A TestCaseUtils.startServer();
1031N/A }
306N/A
1031N/A /**
1031N/A * Creates two handlers, one which is SSL type. Then change some values via the setter
1031N/A * methods.
1031N/A *
1031N/A * @throws Exception if the handler cannot be instantiated.
1031N/A */
6442N/A @Test()
1031N/A public void testLDAPConnectionHandler() throws Exception {
1031N/A Entry LDAPHandlerEntry=null;
306N/A
1031N/A LDAPHandlerEntry=TestCaseUtils.makeEntry(
1031N/A "dn: cn=LDAP Connection Handler,cn=Connection Handlers,cn=config",
1031N/A "objectClass: top",
1031N/A "objectClass: ds-cfg-connection-handler",
1031N/A "objectClass: ds-cfg-ldap-connection-handler",
1031N/A "cn: LDAP Connection Handler",
2624N/A "ds-cfg-java-class: org.opends.server.protocols.ldap.LDAPConnectionHandler",
2624N/A "ds-cfg-enabled: true",
1031N/A "ds-cfg-listen-address: 0.0.0.0",
1031N/A "ds-cfg-accept-backlog: 128",
2624N/A "ds-cfg-allow-ldap-v2: false",
1031N/A "ds-cfg-keep-stats: false",
2624N/A "ds-cfg-use-tcp-keep-alive: true",
2624N/A "ds-cfg-use-tcp-no-delay: true",
1031N/A "ds-cfg-allow-tcp-reuse-address: true",
1031N/A "ds-cfg-send-rejection-notice: true",
1031N/A "ds-cfg-max-request-size: 5 megabytes",
1031N/A "ds-cfg-num-request-handlers: 2",
1031N/A "ds-cfg-allow-start-tls: false",
1031N/A "ds-cfg-use-ssl: false",
1031N/A "ds-cfg-ssl-client-auth-policy: optional",
1031N/A "ds-cfg-ssl-cert-nickname: server-cert",
2624N/A "ds-cfg-key-manager-provider: cn=JKS,cn=Key Manager Providers,cn=config",
2624N/A "ds-cfg-trust-manager-provider: cn=JKS,cn=Trust Manager Providers,cn=config");
1031N/A LDAPConnectionHandler LDAPConnHandler=getLDAPHandlerInstance(LDAPHandlerEntry);
1031N/A LDAPConnHandler.allowLDAPv2();
1031N/A LDAPConnHandler.allowStartTLS();
1031N/A LDAPConnHandler.keepStats();
1031N/A LDAPConnHandler.toString(new StringBuilder());
1031N/A LDAPConnHandler.toString();
1031N/A LDAPStatistics tracker=LDAPConnHandler.getStatTracker();
6442N/A Map<String,String> alerts = LDAPConnHandler.getAlerts();
1031N/A String c=LDAPConnHandler.getClassName();
1031N/A DN dn = LDAPConnHandler.getComponentEntryDN();
6000N/A Collection<String> cips = LDAPConnHandler.getEnabledSSLCipherSuites();
6000N/A Collection<String> protos = LDAPConnHandler.getEnabledSSLProtocols();
1031N/A int maxReqSize = LDAPConnHandler.getMaxRequestSize();
1031N/A String shutListName=LDAPConnHandler.getShutdownListenerName();
1031N/A SSLClientAuthPolicy policy = LDAPConnHandler.getSSLClientAuthPolicy();
1031N/A Collection<ClientConnection> cons=LDAPConnHandler.getClientConnections();
1031N/A LDAPConnHandler.processServerShutdown(reasonMsg);
1031N/A //Reset some things for the SSL handler
3853N/A Attribute useSSL=Attributes.create(ATTR_USE_SSL, String.valueOf(false));
3853N/A Attribute startTls=Attributes.create(ATTR_ALLOW_STARTTLS, String.valueOf(false));
1031N/A AttributeType attrType=DirectoryServer.getAttributeType(ATTR_LISTEN_PORT, true);
3853N/A Attribute a=Attributes.empty(attrType);
1031N/A LDAPHandlerEntry.removeAttribute(a, null);
1031N/A LDAPHandlerEntry.removeAttribute(useSSL, null);
1031N/A LDAPHandlerEntry.removeAttribute(startTls, null);
3853N/A Attribute useSSL1=Attributes.create(ATTR_USE_SSL, String.valueOf(true));
3853N/A Attribute startTls1=Attributes.create(ATTR_ALLOW_STARTTLS, String.valueOf(false));
1031N/A LDAPHandlerEntry.addAttribute(useSSL1,null);
1031N/A LDAPHandlerEntry.addAttribute(startTls1,null);
1031N/A LDAPConnectionHandler LDAPSConnHandler = getLDAPHandlerInstance(LDAPHandlerEntry);
4495N/A LDAPSConnHandler.finalizeConnectionHandler(reasonMsg);
1031N/A LDAPConnHandler.processServerShutdown(reasonMsg);
1031N/A }
1031N/A
1031N/A /**
1031N/A * Start a handler an then give its hasAcceptableConfiguration a ConfigEntry with
1031N/A * numerous invalid cases and single-valued attrs with duplicate values.
1031N/A *
1031N/A * @throws Exception if handler cannot be instantiated or the configuration is
1031N/A * accepted.
1031N/A */
6442N/A @Test(expectedExceptions = ConfigException.class)
1031N/A public void testBadLDAPConnectionHandlerConfiguration() throws Exception
1031N/A {
1031N/A Entry BadHandlerEntry=TestCaseUtils.makeEntry(
1031N/A "dn: cn=LDAP Connection Handler,cn=Connection Handlers,cn=config",
1031N/A "objectClass: top",
1031N/A "objectClass: ds-cfg-connection-handler",
1031N/A "objectClass: ds-cfg-ldap-connection-handler",
1031N/A "cn: LDAP Connection Handler",
2624N/A "ds-cfg-java-class: org.opends.server.protocols.ldap.LDAPConnectionHandler",
2624N/A "ds-cfg-enabled: true",
1031N/A "ds-cfg-listen-address: 0.0.0.0",
1031N/A "ds-cfg-accept-backlog: 128",
2624N/A "ds-cfg-allow-ldap-v2: false",
1031N/A "ds-cfg-keep-stats: false",
2624N/A "ds-cfg-use-tcp-keep-alive: true",
2624N/A "ds-cfg-use-tcp-no-delay: true",
1031N/A "ds-cfg-allow-tcp-reuse-address: true",
1031N/A "ds-cfg-send-rejection-notice: true",
1031N/A "ds-cfg-max-request-size: 5 megabytes",
1031N/A "ds-cfg-num-request-handlers: 2",
1031N/A "ds-cfg-allow-start-tls: false",
1031N/A "ds-cfg-use-ssl: false",
1031N/A "ds-cfg-ssl-client-auth-policy: optional",
1031N/A "ds-cfg-ssl-cert-nickname: server-cert",
2624N/A "ds-cfg-key-manager-provider: cn=JKS,cn=Key Manager Providers,cn=config",
2624N/A "ds-cfg-trust-manager-provider: cn=JKS,cn=Trust Manager Providers,cn=config");
306N/A
1031N/A // Add some invalid attrs and some duplicate attrs
3853N/A Attribute a2=Attributes.create(ATTR_LISTEN_PORT, String.valueOf(389));
3853N/A Attribute a2a=Attributes.create(ATTR_LISTEN_PORT, String.valueOf(70000));
3853N/A Attribute a3=Attributes.create(ATTR_LISTEN_ADDRESS, "localhost");
3853N/A Attribute a3a=Attributes.create(ATTR_LISTEN_ADDRESS, "FAFASFSDFSADFASDFSDFSDAFAS");
3853N/A Attribute a4=Attributes.create(ATTR_ACCEPT_BACKLOG, String.valueOf(Long.MAX_VALUE));
3853N/A Attribute a5=Attributes.create(ATTR_ALLOWED_CLIENT, "129.800.990.45");
3853N/A Attribute a6=Attributes.create(ATTR_DENIED_CLIENT, "129.");
3853N/A Attribute a7=Attributes.create(ATTR_ALLOW_LDAPV2, "45");
3853N/A Attribute a8=Attributes.create(ATTR_KEEP_LDAP_STATS, "45");
3853N/A Attribute a9=Attributes.create(ATTR_SEND_REJECTION_NOTICE, "45");
3853N/A Attribute a10=Attributes.create(ATTR_USE_TCP_KEEPALIVE, "45");
3853N/A Attribute a11=Attributes.create(ATTR_USE_TCP_NODELAY, "45");
3853N/A Attribute a12=Attributes.create(ATTR_ALLOW_REUSE_ADDRESS, "45");
3853N/A Attribute a13=Attributes.create(ATTR_MAX_REQUEST_SIZE, "45 FLUBBERBYTES");
3853N/A Attribute a14=Attributes.create(ATTR_USE_SSL, "45");
3853N/A Attribute a15=Attributes.create(ATTR_ALLOW_STARTTLS, "45");
1031N/A BadHandlerEntry.addAttribute(a2, null);
1031N/A BadHandlerEntry.addAttribute(a3, null);
1031N/A BadHandlerEntry.addAttribute(a2a, null);
1031N/A BadHandlerEntry.addAttribute(a3a, null);
1031N/A BadHandlerEntry.addAttribute(a4, null);
1031N/A BadHandlerEntry.addAttribute(a5, null);
1031N/A BadHandlerEntry.addAttribute(a6, null);
1031N/A BadHandlerEntry.addAttribute(a7, null);
1031N/A BadHandlerEntry.addAttribute(a8, null);
1031N/A BadHandlerEntry.addAttribute(a9, null);
1031N/A BadHandlerEntry.addAttribute(a10, null);
1031N/A BadHandlerEntry.addAttribute(a11, null);
1031N/A BadHandlerEntry.addAttribute(a12, null);
1031N/A BadHandlerEntry.addAttribute(a13, null);
1031N/A BadHandlerEntry.addAttribute(a14, null);
1031N/A BadHandlerEntry.addAttribute(a15, null);
1031N/A
1031N/A LdapTestCase.getConfiguration(BadHandlerEntry);
1031N/A }
306N/A
1031N/A /**
1031N/A * Create handler and then change most of its values and see if
1031N/A * it is acceptable and applied.
1031N/A * @throws Exception if handler cannot be instantiated.
1031N/A */
1031N/A @Test()
1031N/A public void testGoodLDAPConnectionHandlerConfiguration() throws Exception
1031N/A {
1031N/A Entry GoodHandlerEntry=TestCaseUtils.makeEntry(
1031N/A "dn: cn=LDAP Connection Handler,cn=Connection Handlers,cn=config",
1031N/A "objectClass: top",
1031N/A "objectClass: ds-cfg-connection-handler",
1031N/A "objectClass: ds-cfg-ldap-connection-handler",
1031N/A "cn: LDAP Connection Handler",
2624N/A "ds-cfg-java-class: org.opends.server.protocols.ldap.LDAPConnectionHandler",
2624N/A "ds-cfg-enabled: true",
1031N/A "ds-cfg-listen-address: 0.0.0.0",
1031N/A "ds-cfg-accept-backlog: 128",
2624N/A "ds-cfg-allow-ldap-v2: false",
1031N/A "ds-cfg-keep-stats: false",
2624N/A "ds-cfg-use-tcp-keep-alive: true",
2624N/A "ds-cfg-use-tcp-no-delay: true",
1031N/A "ds-cfg-allow-tcp-reuse-address: true",
1031N/A "ds-cfg-send-rejection-notice: true",
1031N/A "ds-cfg-max-request-size: 5 megabytes",
1031N/A "ds-cfg-num-request-handlers: 2",
1031N/A "ds-cfg-allow-start-tls: false",
1031N/A "ds-cfg-use-ssl: true",
1031N/A "ds-cfg-ssl-client-auth-policy: optional",
1031N/A "ds-cfg-ssl-cert-nickname: server-cert",
2624N/A "ds-cfg-key-manager-provider: cn=JKS,cn=Key Manager Providers,cn=config",
2624N/A "ds-cfg-trust-manager-provider: cn=JKS,cn=Trust Manager Providers,cn=config");
1031N/A LDAPConnectionHandler LDAPConnHandler=getLDAPHandlerInstance(GoodHandlerEntry);
1031N/A //Make attrTypes to remove
1031N/A AttributeType at0=DirectoryServer.getAttributeType(ATTR_LISTEN_PORT, true);
1031N/A// AttributeType at1=DirectoryServer.getAttributeType(ATTR_LISTEN_ADDRESS, true);
1031N/A// Attribute rAttr1=new Attribute(at1);
1031N/A// GoodHandlerEntry.removeAttribute(rAttr1, null);
1031N/A AttributeType at2=DirectoryServer.getAttributeType(ATTR_ALLOW_LDAPV2, true);
1031N/A AttributeType at3=DirectoryServer.getAttributeType(ATTR_ALLOW_LDAPV2, true);
1031N/A AttributeType at4=DirectoryServer.getAttributeType(ATTR_KEEP_LDAP_STATS, true);
1031N/A AttributeType at5=DirectoryServer.getAttributeType(ATTR_SEND_REJECTION_NOTICE,true);
1031N/A AttributeType at6=DirectoryServer.getAttributeType(ATTR_USE_TCP_KEEPALIVE,true);
1031N/A AttributeType at7=DirectoryServer.getAttributeType(ATTR_USE_TCP_NODELAY,true);
1031N/A AttributeType at8=DirectoryServer.getAttributeType(ATTR_ALLOW_REUSE_ADDRESS,true);
1031N/A AttributeType at9=DirectoryServer.getAttributeType(ATTR_USE_SSL,true);
1031N/A AttributeType at10=DirectoryServer.getAttributeType(ATTR_ALLOW_STARTTLS,true);
1031N/A AttributeType at11=DirectoryServer.getAttributeType(ATTR_MAX_REQUEST_SIZE,true);
1031N/A AttributeType at12=DirectoryServer.getAttributeType(ATTR_ACCEPT_BACKLOG,true);
1031N/A //Remove them
3853N/A Attribute rAttr0=Attributes.empty(at0);
1031N/A GoodHandlerEntry.removeAttribute(rAttr0, null);
308N/A
3853N/A Attribute rAttr2=Attributes.empty(at2);
1031N/A GoodHandlerEntry.removeAttribute(rAttr2, null);
3853N/A Attribute rAttr3=Attributes.empty(at3);
1031N/A GoodHandlerEntry.removeAttribute(rAttr3, null);
3853N/A Attribute rAttr4=Attributes.empty(at4);
1031N/A GoodHandlerEntry.removeAttribute(rAttr4, null);
3853N/A Attribute rAttr5=Attributes.empty(at5);
1031N/A GoodHandlerEntry.removeAttribute(rAttr5, null);
3853N/A Attribute rAttr6=Attributes.empty(at6);
1031N/A GoodHandlerEntry.removeAttribute(rAttr6, null);
3853N/A Attribute rAttr7=Attributes.empty(at7);
1031N/A GoodHandlerEntry.removeAttribute(rAttr7, null);
3853N/A Attribute rAttr8=Attributes.empty(at8);
3853N/A Attribute rAttr9=Attributes.empty(at9);
3853N/A Attribute rAttr10=Attributes.empty(at10);
3853N/A Attribute rAttr11=Attributes.empty(at11);
3853N/A Attribute rAttr12=Attributes.empty(at12);
1031N/A GoodHandlerEntry.removeAttribute(rAttr8, null);
1031N/A GoodHandlerEntry.removeAttribute(rAttr9, null);
1031N/A GoodHandlerEntry.removeAttribute(rAttr10, null);
1031N/A GoodHandlerEntry.removeAttribute(rAttr11, null);
1031N/A GoodHandlerEntry.removeAttribute(rAttr12, null);
1031N/A //Make new AttrTypes with different values
6596N/A long newPort = TestCaseUtils.findFreePort();
3853N/A Attribute a2=Attributes.create(ATTR_LISTEN_PORT, String.valueOf(newPort));
1031N/A //uncomment if want to test listen address
1031N/A// Attribute a3=new Attribute(ATTR_LISTEN_ADDRESS, "localhost");
3853N/A Attribute a4=Attributes.create(ATTR_ACCEPT_BACKLOG, String.valueOf(25));
3853N/A Attribute a5=Attributes.create(ATTR_ALLOWED_CLIENT, "129.56.56.45");
3853N/A Attribute a6=Attributes.create(ATTR_DENIED_CLIENT, "129.*.*.90");
3853N/A Attribute a7=Attributes.create(ATTR_ALLOW_LDAPV2, "true");
3853N/A Attribute a8=Attributes.create(ATTR_KEEP_LDAP_STATS, "true");
3853N/A Attribute a9=Attributes.create(ATTR_SEND_REJECTION_NOTICE, "false");
3853N/A Attribute a10=Attributes.create(ATTR_USE_TCP_KEEPALIVE, "false");
3853N/A Attribute a11=Attributes.create(ATTR_USE_TCP_NODELAY, "false");
3853N/A Attribute a12=Attributes.create(ATTR_ALLOW_REUSE_ADDRESS, "false");
3853N/A Attribute a13=Attributes.create(ATTR_MAX_REQUEST_SIZE, "45 kb");
3853N/A Attribute a14=Attributes.create(ATTR_USE_SSL, "false");
3853N/A Attribute a15=Attributes.create(ATTR_ALLOW_STARTTLS, "true");
1031N/A //Add them
1031N/A GoodHandlerEntry.addAttribute(a2, null);
1031N/A// GoodHandlerEntry.addAttribute(a3, null);
1031N/A GoodHandlerEntry.addAttribute(a4, null);
1031N/A GoodHandlerEntry.addAttribute(a5, null);
1031N/A GoodHandlerEntry.addAttribute(a6, null);
1031N/A GoodHandlerEntry.addAttribute(a7, null);
1031N/A GoodHandlerEntry.addAttribute(a8, null);
1031N/A GoodHandlerEntry.addAttribute(a9, null);
1031N/A GoodHandlerEntry.addAttribute(a10, null);
1031N/A GoodHandlerEntry.addAttribute(a11, null);
1031N/A GoodHandlerEntry.addAttribute(a12, null);
1031N/A GoodHandlerEntry.addAttribute(a13, null);
1031N/A GoodHandlerEntry.addAttribute(a14, null);
1031N/A GoodHandlerEntry.addAttribute(a15, null);
6442N/A List<Message> reasons = new LinkedList<Message>();
1008N/A LDAPConnectionHandlerCfg config = LdapTestCase.getConfiguration(GoodHandlerEntry);
1031N/A //see if we're ok
1031N/A boolean ret=LDAPConnHandler.isConfigurationChangeAcceptable(config, reasons);
1031N/A assertTrue(ret);
1031N/A //apply it
1031N/A LDAPConnHandler.applyConfigurationChange(config);
4495N/A LDAPConnHandler.finalizeConnectionHandler(reasonMsg);
1031N/A }
306N/A}