Add test cases for the following:
- The EXTERNAL SASL mechanism handler
- The StartTLS extended operation
- The file-based key manager provider
- The file-based trust manager provider
- The core password policy
| New file |
| | |
| | | /* |
| | | * CDDL HEADER START |
| | | * |
| | | * The contents of this file are subject to the terms of the |
| | | * Common Development and Distribution License, Version 1.0 only |
| | | * (the "License"). You may not use this file except in compliance |
| | | * with the License. |
| | | * |
| | | * You can obtain a copy of the license at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE |
| | | * or https://OpenDS.dev.java.net/OpenDS.LICENSE. |
| | | * See the License for the specific language governing permissions |
| | | * and limitations under the License. |
| | | * |
| | | * When distributing Covered Code, include this CDDL HEADER in each |
| | | * file and include the License file at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, |
| | | * add the following below this CDDL HEADER, with the fields enclosed |
| | | * by brackets "[]" replaced with your own identifying * information: |
| | | * Portions Copyright [yyyy] [name of copyright owner] |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.net.Socket; |
| | | import java.security.KeyStore; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.config.ConfigEntry; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.InitializationException; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.protocols.asn1.ASN1Reader; |
| | | import org.opends.server.protocols.asn1.ASN1Writer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.ldap.BindRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.ModificationType; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.util.Base64; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of test cases for the EXTERNAL SASL mechanism handler. |
| | | */ |
| | | public class ExternalSASLMechanismHandlerTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass() |
| | | public void startServer() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a set of invalid configurations that cannot be used to |
| | | * initialize the EXTERNAL SASL mechanism handler. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @DataProvider(name = "invalidConfigs") |
| | | public Object[][] getInvalidConfigurations() |
| | | throws Exception |
| | | { |
| | | List<Entry> entries = TestCaseUtils.makeEntries( |
| | | "dn: cn=EXTERNAL,cn=SASL Mechanisms,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-sasl-mechanism-handler", |
| | | "objectClass: ds-cfg-external-sasl-mechanism-handler", |
| | | "cn: EXTERNAL", |
| | | "ds-cfg-sasl-mechanism-handler-class: org.opends.server.extensions." + |
| | | "ExternalSASLMechanismHandler", |
| | | "ds-cfg-sasl-mechanism-handler-enabled: true", |
| | | "ds-cfg-client-certificate-validation-policy: invalid", |
| | | "ds-cfg-certificate-attribute: userCertificate", |
| | | "", |
| | | "dn: cn=EXTERNAL,cn=SASL Mechanisms,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-sasl-mechanism-handler", |
| | | "objectClass: ds-cfg-external-sasl-mechanism-handler", |
| | | "cn: EXTERNAL", |
| | | "ds-cfg-sasl-mechanism-handler-class: org.opends.server.extensions." + |
| | | "ExternalSASLMechanismHandler", |
| | | "ds-cfg-sasl-mechanism-handler-enabled: true", |
| | | "ds-cfg-client-certificate-validation-policy: ifpresent", |
| | | "ds-cfg-certificate-attribute: invalid"); |
| | | |
| | | |
| | | Object[][] configEntries = new Object[entries.size()][1]; |
| | | for (int i=0; i < configEntries.length; i++) |
| | | { |
| | | configEntries[i] = new Object[] { entries.get(i) }; |
| | | } |
| | | |
| | | return configEntries; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests initialization with an invalid configuration. |
| | | * |
| | | * @param e The configuration entry to use to initialize the identity |
| | | * mapper. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "invalidConfigs", |
| | | expectedExceptions = { ConfigException.class, |
| | | InitializationException.class }) |
| | | public void testInvalidConfigs(Entry e) |
| | | throws Exception |
| | | { |
| | | DN parentDN = DN.decode("cn=SASL Mechanisms,cn=config"); |
| | | ConfigEntry parentEntry = DirectoryServer.getConfigEntry(parentDN); |
| | | ConfigEntry configEntry = new ConfigEntry(e, parentEntry); |
| | | |
| | | ExternalSASLMechanismHandler handler = new ExternalSASLMechanismHandler(); |
| | | handler.initializeSASLMechanismHandler(configEntry); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the <CODE>isPasswordBased</CODE> method. |
| | | */ |
| | | @Test() |
| | | public void testIsPasswordBased() |
| | | { |
| | | ExternalSASLMechanismHandler handler = |
| | | (ExternalSASLMechanismHandler) |
| | | DirectoryServer.getSASLMechanismHandler("EXTERNAL"); |
| | | assertNotNull(handler); |
| | | assertFalse(handler.isPasswordBased("EXTERNAL")); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the <CODE>isSecure</CODE> method. |
| | | */ |
| | | @Test() |
| | | public void testIsSecure() |
| | | { |
| | | ExternalSASLMechanismHandler handler = |
| | | (ExternalSASLMechanismHandler) |
| | | DirectoryServer.getSASLMechanismHandler("EXTERNAL"); |
| | | assertNotNull(handler); |
| | | assertTrue(handler.isSecure("EXTERNAL")); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be trusted using a client trust store. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testEXTERNALTrustStore() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | String trustStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.truststore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-P", trustStorePath, |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be blindly trusted. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testEXTERNALTrustAll() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes a non-SSL-based connection to the server and verifies that |
| | | * EXTERNAL authentication fails over that connection. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testFailEXTERNALInsecureConnection() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Socket s = new Socket("127.0.0.1", (int) TestCaseUtils.getServerLdapPort()); |
| | | ASN1Reader reader = new ASN1Reader(s); |
| | | ASN1Writer writer = new ASN1Writer(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(new ASN1OctetString(), "EXTERNAL", null); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeElement(message.encode()); |
| | | |
| | | message = LDAPMessage.decode(reader.readElement().decodeAsSequence()); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertFalse(bindResponse.getResultCode() == 0); |
| | | |
| | | s.close(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be blindly trusted. The server will not be able to map |
| | | * the client certificate to a user entry. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testFailEXTERNALTrustAllNoSuchUser() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be blindly trusted. The server user entry will not have |
| | | * the required certificate attribute. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testFailEXTERNALTrustAllNoRequiredCert() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String dnStr = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String attrName = "ds-cfg-client-certificate-validation-policy"; |
| | | ArrayList<Modification> mods = new ArrayList<Modification>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | new Attribute(attrName, "always"))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.decode(dnStr), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0); |
| | | |
| | | |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | new Attribute(attrName, "ifpresent"))); |
| | | modifyOperation = conn.processModify(DN.decode(dnStr), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be blindly trusted. The server user entry will have the |
| | | * optional certificate attribute and it will be valid. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testEXTERNALTrustAllValidOptionalCert() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | KeyStore ks = KeyStore.getInstance("JKS"); |
| | | FileInputStream inputStream = new FileInputStream(keyStorePath); |
| | | ks.load(inputStream, "password".toCharArray()); |
| | | inputStream.close(); |
| | | byte[] certBytes = ks.getCertificate("client-cert").getEncoded(); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User", |
| | | "userCertificate;binary:: " + Base64.encode(certBytes)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be blindly trusted. The server user entry will have the |
| | | * optional certificate attribute but it will not have a valid value. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testFailEXTERNALTrustAllInvalidOptionalCert() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User", |
| | | "userCertificate;binary: invalid"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be blindly trusted. The server user entry will have the |
| | | * required certificate attribute and it will be valid. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testEXTERNALTrustAllValidRequiredCert() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | KeyStore ks = KeyStore.getInstance("JKS"); |
| | | FileInputStream inputStream = new FileInputStream(keyStorePath); |
| | | ks.load(inputStream, "password".toCharArray()); |
| | | inputStream.close(); |
| | | byte[] certBytes = ks.getCertificate("client-cert").getEncoded(); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User", |
| | | "userCertificate;binary:: " + Base64.encode(certBytes)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String dnStr = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String attrName = "ds-cfg-client-certificate-validation-policy"; |
| | | ArrayList<Modification> mods = new ArrayList<Modification>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | new Attribute(attrName, "always"))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.decode(dnStr), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | |
| | | |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | new Attribute(attrName, "ifpresent"))); |
| | | modifyOperation = conn.processModify(DN.decode(dnStr), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Establishes an SSL-based connection to the server, provides a client |
| | | * certificate, and uses it to authenticate to the server. The server |
| | | * certificate will be blindly trusted. The server user entry will have the |
| | | * required certificate attribute but it will not have a valid value. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testFailEXTERNALTrustAllInvalidRequiredCert() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User", |
| | | "userCertificate;binary: invalid"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String dnStr = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String attrName = "ds-cfg-client-certificate-validation-policy"; |
| | | ArrayList<Modification> mods = new ArrayList<Modification>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | new Attribute(attrName, "always"))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.decode(dnStr), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapsPort()), |
| | | "-Z", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0); |
| | | |
| | | |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | new Attribute(attrName, "ifpresent"))); |
| | | modifyOperation = conn.processModify(DN.decode(dnStr), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | | |
| New file |
| | |
| | | /* |
| | | * CDDL HEADER START |
| | | * |
| | | * The contents of this file are subject to the terms of the |
| | | * Common Development and Distribution License, Version 1.0 only |
| | | * (the "License"). You may not use this file except in compliance |
| | | * with the License. |
| | | * |
| | | * You can obtain a copy of the license at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE |
| | | * or https://OpenDS.dev.java.net/OpenDS.LICENSE. |
| | | * See the License for the specific language governing permissions |
| | | * and limitations under the License. |
| | | * |
| | | * When distributing Covered Code, include this CDDL HEADER in each |
| | | * file and include the License file at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, |
| | | * add the following below this CDDL HEADER, with the fields enclosed |
| | | * by brackets "[]" replaced with your own identifying * information: |
| | | * Portions Copyright [yyyy] [name of copyright owner] |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.util.List; |
| | | import javax.net.ssl.KeyManager; |
| | | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.config.ConfigEntry; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.InitializationException; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of test cases for the file-based key manager provider. |
| | | */ |
| | | public class FileBasedKeyManagerProviderTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass() |
| | | public void startServer() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | |
| | | FileWriter writer = new FileWriter(DirectoryServer.getServerRoot() + |
| | | File.separator + "config" + |
| | | File.separator + "server.pin"); |
| | | writer.write("password" + EOL); |
| | | writer.close(); |
| | | |
| | | writer = new FileWriter(DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "empty"); |
| | | writer.close(); |
| | | |
| | | System.setProperty("org.opends.server.KeyStorePIN", "password"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a set of valid configurations that can be used to |
| | | * initialize the file-based key manager provider. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @DataProvider(name = "validConfigs") |
| | | public Object[][] getValidConfigurations() |
| | | throws Exception |
| | | { |
| | | List<Entry> entries = TestCaseUtils.makeEntries( |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin: password", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin-file: config/server.pin", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin-property: org.opends.server.KeyStorePIN", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin: password", |
| | | "ds-cfg-key-store-type: JKS", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server-cert.p12", |
| | | "ds-cfg-key-store-pin: password", |
| | | "ds-cfg-key-store-type: PKCS12"); |
| | | |
| | | |
| | | Object[][] configEntries = new Object[entries.size()][1]; |
| | | for (int i=0; i < configEntries.length; i++) |
| | | { |
| | | configEntries[i] = new Object[] { entries.get(i) }; |
| | | } |
| | | |
| | | return configEntries; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests initialization with an valid configurations. |
| | | * |
| | | * @param e The configuration entry to use to initialize the identity |
| | | * mapper. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "validConfigs") |
| | | public void testVvalidConfigs(Entry e) |
| | | throws Exception |
| | | { |
| | | DN parentDN = DN.decode("cn=SSL,cn=config"); |
| | | ConfigEntry parentEntry = DirectoryServer.getConfigEntry(parentDN); |
| | | ConfigEntry configEntry = new ConfigEntry(e, parentEntry); |
| | | |
| | | FileBasedKeyManagerProvider provider = new FileBasedKeyManagerProvider(); |
| | | provider.initializeKeyManagerProvider(configEntry); |
| | | provider.finalizeKeyManagerProvider(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a set of invalid configurations that cannot be used to |
| | | * initialize the file-based key manager provider. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @DataProvider(name = "invalidConfigs") |
| | | public Object[][] getInvalidConfigurations() |
| | | throws Exception |
| | | { |
| | | List<Entry> entries = TestCaseUtils.makeEntries( |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-pin: password", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/nosuchfile", |
| | | "ds-cfg-key-store-pin: password", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin-file: config/nosuchfile", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin-file: config/empty", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin-property: nosuchproperty", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin-environment-variable: nosuchenv", |
| | | "", |
| | | "dn: cn=Key Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-key-manager-provider", |
| | | "objectClass: ds-cfg-file-based-key-manager-provider", |
| | | "cn: Key Manager Provider", |
| | | "ds-cfg-key-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedKeyManagerProvider", |
| | | "ds-cfg-key-manager-provider-enabled: true", |
| | | "ds-cfg-key-store-file: config/server.keystore", |
| | | "ds-cfg-key-store-pin: password", |
| | | "ds-cfg-key-store-type: invalid"); |
| | | |
| | | |
| | | Object[][] configEntries = new Object[entries.size()][1]; |
| | | for (int i=0; i < configEntries.length; i++) |
| | | { |
| | | configEntries[i] = new Object[] { entries.get(i) }; |
| | | } |
| | | |
| | | return configEntries; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests initialization with an invalid configuration. |
| | | * |
| | | * @param e The configuration entry to use to initialize the identity |
| | | * mapper. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "invalidConfigs", |
| | | expectedExceptions = { ConfigException.class, |
| | | InitializationException.class }) |
| | | public void testInvalidConfigs(Entry e) |
| | | throws Exception |
| | | { |
| | | DN parentDN = DN.decode("cn=SSL,cn=config"); |
| | | ConfigEntry parentEntry = DirectoryServer.getConfigEntry(parentDN); |
| | | ConfigEntry configEntry = new ConfigEntry(e, parentEntry); |
| | | |
| | | FileBasedKeyManagerProvider provider = new FileBasedKeyManagerProvider(); |
| | | provider.initializeKeyManagerProvider(configEntry); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the <CODE>getKeyManagers</CODE> method. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGetKeyManagers() |
| | | throws Exception |
| | | { |
| | | FileBasedKeyManagerProvider provider = |
| | | (FileBasedKeyManagerProvider) DirectoryServer.getKeyManagerProvider(); |
| | | assertNotNull(provider); |
| | | |
| | | KeyManager[] keyManagers = provider.getKeyManagers(); |
| | | assertNotNull(keyManagers); |
| | | assertFalse(keyManagers.length == 0); |
| | | } |
| | | } |
| | | |
| New file |
| | |
| | | /* |
| | | * CDDL HEADER START |
| | | * |
| | | * The contents of this file are subject to the terms of the |
| | | * Common Development and Distribution License, Version 1.0 only |
| | | * (the "License"). You may not use this file except in compliance |
| | | * with the License. |
| | | * |
| | | * You can obtain a copy of the license at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE |
| | | * or https://OpenDS.dev.java.net/OpenDS.LICENSE. |
| | | * See the License for the specific language governing permissions |
| | | * and limitations under the License. |
| | | * |
| | | * When distributing Covered Code, include this CDDL HEADER in each |
| | | * file and include the License file at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, |
| | | * add the following below this CDDL HEADER, with the fields enclosed |
| | | * by brackets "[]" replaced with your own identifying * information: |
| | | * Portions Copyright [yyyy] [name of copyright owner] |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.util.List; |
| | | import javax.net.ssl.TrustManager; |
| | | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.config.ConfigEntry; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.InitializationException; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of test cases for the file-based trust manager provider. |
| | | */ |
| | | public class FileBasedTrustManagerProviderTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass() |
| | | public void startServer() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | |
| | | FileWriter writer = new FileWriter(DirectoryServer.getServerRoot() + |
| | | File.separator + "config" + |
| | | File.separator + "server.pin"); |
| | | writer.write("password" + EOL); |
| | | writer.close(); |
| | | |
| | | writer = new FileWriter(DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "empty"); |
| | | writer.close(); |
| | | |
| | | System.setProperty("org.opends.server.trustStorePIN", "password"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a set of valid configurations that can be used to |
| | | * initialize the file-based trust manager provider. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @DataProvider(name = "validConfigs") |
| | | public Object[][] getValidConfigurations() |
| | | throws Exception |
| | | { |
| | | List<Entry> entries = TestCaseUtils.makeEntries( |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin: password", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin-file: config/server.pin", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin-property: org.opends.server.trustStorePIN", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin: password", |
| | | "ds-cfg-trust-store-type: JKS"); |
| | | |
| | | |
| | | Object[][] configEntries = new Object[entries.size()][1]; |
| | | for (int i=0; i < configEntries.length; i++) |
| | | { |
| | | configEntries[i] = new Object[] { entries.get(i) }; |
| | | } |
| | | |
| | | return configEntries; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests initialization with an valid configurations. |
| | | * |
| | | * @param e The configuration entry to use to initialize the identity |
| | | * mapper. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "validConfigs") |
| | | public void testVvalidConfigs(Entry e) |
| | | throws Exception |
| | | { |
| | | DN parentDN = DN.decode("cn=SSL,cn=config"); |
| | | ConfigEntry parentEntry = DirectoryServer.getConfigEntry(parentDN); |
| | | ConfigEntry configEntry = new ConfigEntry(e, parentEntry); |
| | | |
| | | FileBasedTrustManagerProvider provider = new FileBasedTrustManagerProvider(); |
| | | provider.initializeTrustManagerProvider(configEntry); |
| | | provider.finalizeTrustManagerProvider(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a set of invalid configurations that cannot be used to |
| | | * initialize the file-based trust manager provider. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @DataProvider(name = "invalidConfigs") |
| | | public Object[][] getInvalidConfigurations() |
| | | throws Exception |
| | | { |
| | | List<Entry> entries = TestCaseUtils.makeEntries( |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-pin: password", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/nosuchfile", |
| | | "ds-cfg-trust-store-pin: password", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin-file: config/nosuchfile", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin-file: config/empty", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin-property: nosuchproperty", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin-environment-variable: nosuchenv", |
| | | "", |
| | | "dn: cn=Trust Manager Provider,cn=SSL,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-trust-manager-provider", |
| | | "objectClass: ds-cfg-file-based-trust-manager-provider", |
| | | "cn: Trust Manager Provider", |
| | | "ds-cfg-trust-manager-provider-class: org.opends.server.extensions." + |
| | | "FileBasedTrustManagerProvider", |
| | | "ds-cfg-trust-manager-provider-enabled: true", |
| | | "ds-cfg-trust-store-file: config/server.truststore", |
| | | "ds-cfg-trust-store-pin: password", |
| | | "ds-cfg-trust-store-type: invalid"); |
| | | |
| | | |
| | | Object[][] configEntries = new Object[entries.size()][1]; |
| | | for (int i=0; i < configEntries.length; i++) |
| | | { |
| | | configEntries[i] = new Object[] { entries.get(i) }; |
| | | } |
| | | |
| | | return configEntries; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests initialization with an invalid configuration. |
| | | * |
| | | * @param e The configuration entry to use to initialize the identity |
| | | * mapper. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "invalidConfigs", |
| | | expectedExceptions = { ConfigException.class, |
| | | InitializationException.class }) |
| | | public void testInvalidConfigs(Entry e) |
| | | throws Exception |
| | | { |
| | | DN parentDN = DN.decode("cn=SSL,cn=config"); |
| | | ConfigEntry parentEntry = DirectoryServer.getConfigEntry(parentDN); |
| | | ConfigEntry configEntry = new ConfigEntry(e, parentEntry); |
| | | |
| | | FileBasedTrustManagerProvider provider = |
| | | new FileBasedTrustManagerProvider(); |
| | | provider.initializeTrustManagerProvider(configEntry); |
| | | for (StringBuilder sb : e.toLDIF()) |
| | | { |
| | | System.err.println(sb.toString()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the <CODE>getTrustManagers</CODE> method. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGetTrustManagers() |
| | | throws Exception |
| | | { |
| | | FileBasedTrustManagerProvider provider = |
| | | (FileBasedTrustManagerProvider) |
| | | DirectoryServer.getTrustManagerProvider(); |
| | | assertNotNull(provider); |
| | | |
| | | TrustManager[] trustManagers = provider.getTrustManagers(); |
| | | assertNotNull(trustManagers); |
| | | assertFalse(trustManagers.length == 0); |
| | | } |
| | | } |
| | | |
| New file |
| | |
| | | /* |
| | | * CDDL HEADER START |
| | | * |
| | | * The contents of this file are subject to the terms of the |
| | | * Common Development and Distribution License, Version 1.0 only |
| | | * (the "License"). You may not use this file except in compliance |
| | | * with the License. |
| | | * |
| | | * You can obtain a copy of the license at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE |
| | | * or https://OpenDS.dev.java.net/OpenDS.LICENSE. |
| | | * See the License for the specific language governing permissions |
| | | * and limitations under the License. |
| | | * |
| | | * When distributing Covered Code, include this CDDL HEADER in each |
| | | * file and include the License file at |
| | | * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, |
| | | * add the following below this CDDL HEADER, with the fields enclosed |
| | | * by brackets "[]" replaced with your own identifying * information: |
| | | * Portions Copyright [yyyy] [name of copyright owner] |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | |
| | | |
| | | import java.io.File; |
| | | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.ResultCode; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of test cases for the StartTLS extended operation handler. |
| | | */ |
| | | public class StartTLSExtendedOperationTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass() |
| | | public void startServer() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the use of the StartTLS extended operation to communicate with the |
| | | * server in conjunction with no authentication and using a client trust store |
| | | * to validate the server certificate. |
| | | */ |
| | | @Test() |
| | | public void testStartTLSNoAuthTrustStore() |
| | | { |
| | | String trustStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.truststore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-q", |
| | | "-P", trustStorePath, |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the use of the StartTLS extended operation to communicate with the |
| | | * server in conjunction with no authentication and using blind trust. |
| | | */ |
| | | @Test() |
| | | public void testStartTLSNoAuthTrustAll() |
| | | { |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-q", |
| | | "-X", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the use of the StartTLS extended operation to communicate with the |
| | | * server in conjunction with simple authentication and using a client trust |
| | | * store to validate the server certificate. |
| | | */ |
| | | @Test() |
| | | public void testStartTLSSimpleAuthTrustStore() |
| | | { |
| | | String trustStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.truststore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-q", |
| | | "-P", trustStorePath, |
| | | "-D", "cn=Directory Manager", |
| | | "-w", "password", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the use of the StartTLS extended operation to communicate with the |
| | | * server in conjunction with simple authentication and using blind trust. |
| | | */ |
| | | @Test() |
| | | public void testStartTLSSimpleAuthTrustAll() |
| | | { |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-q", |
| | | "-X", |
| | | "-D", "cn=Directory Manager", |
| | | "-w", "password", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the use of the StartTLS extended operation to communicate with the |
| | | * server in conjunction with SASL EXTERNAL authentication and using a client |
| | | * trust store to validate the server certificate. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testStartTLSExternalAuthTrustStore() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | String trustStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.truststore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-q", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-P", trustStorePath, |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the use of the StartTLS extended operation to communicate with the |
| | | * server in conjunction with SASL EXTERNAL authentication and using blind |
| | | * trust. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testStartTLSExternalAuthTrustAll() |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Entry e = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test User,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "cn: Test User", |
| | | "givenName: Test", |
| | | "sn: User"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOperation = |
| | | conn.processAdd(e.getDN(), e.getObjectClasses(), e.getUserAttributes(), |
| | | e.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | | String keyStorePath = DirectoryServer.getServerRoot() + File.separator + |
| | | "config" + File.separator + "client.keystore"; |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-q", |
| | | "-K", keyStorePath, |
| | | "-W", "password", |
| | | "-X", |
| | | "-r", |
| | | "-b", "", |
| | | "-s", "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | } |
| | | |