Code cleanup:
- Replaced use of Socket by RemoteConnection
- Replaced use of the various InternalClientConnection.processModify() methods
by InternalClientConnection.processModify(ModifyRequest)
everywhere it is not critical and perfs will be equivalent
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | * Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.adapter.server3x; |
| | | |
| | |
| | | import org.opends.server.core.DeleteOperation; |
| | | import org.opends.server.core.ExtendedOperation; |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchListener; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | |
| | | |
| | | @Override |
| | | public Result modify(final ModifyRequest request) throws LdapException { |
| | | final ModifyOperation modifyOperation = |
| | | icc.processModify(valueOfObject(request.getName()), toRawModifications(request |
| | | .getModifications()), to(request.getControls())); |
| | | return getResponseResult(modifyOperation); |
| | | return getResponseResult(icc.processModify(request)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.ServerContext; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.ldap.*; |
| | | import org.opends.server.schema.SchemaConstants; |
| | | import org.opends.server.schema.UserPasswordSyntax; |
| | |
| | | |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.ldap.LDAPConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | OP_ATTR_PTAPOLICY_CACHED_PASSWORD_TIME, |
| | | provider.getCurrentTime())); |
| | | |
| | | InternalClientConnection conn = InternalClientConnection |
| | | .getRootConnection(); |
| | | ModifyOperation internalModify = conn.processModify(userEntry |
| | | .getName().toString(), modifications); |
| | | ModifyOperation internalModify = getRootConnection().processModify( |
| | | ByteString.valueOfObject(userEntry.getName()), modifications); |
| | | |
| | | ResultCode resultCode = internalModify.getResultCode(); |
| | | if (resultCode != ResultCode.SUCCESS) |
| | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.api.ConnectionHandler; |
| | |
| | | import org.opends.server.util.ModifyChangeRecordEntry; |
| | | import org.opends.server.util.ModifyDNChangeRecordEntry; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.opends.messages.ProtocolMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | |
| | | return extendedOperation; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Processes an internal modify operation with the provided |
| | | * information. |
| | | * |
| | | * @param rawEntryDN The raw entry DN for this modify |
| | | * operation. |
| | | * @param rawModifications The set of modifications for this |
| | | * modify operation. |
| | | * |
| | | * @return A reference to the modify operation that was processed |
| | | * and contains information about the result of the |
| | | * processing. |
| | | */ |
| | | public ModifyOperation processModify(String rawEntryDN, |
| | | List<RawModification> rawModifications) |
| | | { |
| | | return processModify(ByteString.valueOfUtf8(rawEntryDN), |
| | | rawModifications, null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Processes an internal modify operation with the provided |
| | | * information. |
| | | * |
| | | * @param rawEntryDN The raw entry DN for this modify |
| | | * operation. |
| | | * @param rawModifications The set of modifications for this |
| | | * modify operation. |
| | | * @param controls The set of controls to include in the |
| | | * request. |
| | | * |
| | | * @return A reference to the modify operation that was processed |
| | | * and contains information about the result of the |
| | | * processing. |
| | | */ |
| | | public ModifyOperation processModify(String rawEntryDN, |
| | | List<RawModification> rawModifications, |
| | | List<Control> controls) |
| | | { |
| | | return processModify(ByteString.valueOfUtf8(rawEntryDN), |
| | | rawModifications, controls); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Processes an internal modify operation with the provided |
| | | * information. |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * Processes an internal modify operation with the provided |
| | | * information. |
| | | * |
| | | * @param rawEntryDN The raw entry DN for this modify |
| | | * operation. |
| | | * @param rawModifications The set of modifications for this |
| | | * modify operation. |
| | | * @param controls The set of controls to include in the |
| | | * request. |
| | | * |
| | | * @return A reference to the modify operation that was processed |
| | | * and contains information about the result of the |
| | | * processing. |
| | | */ |
| | | public ModifyOperation processModify(ByteString rawEntryDN, |
| | | private ModifyOperation processModify(ByteString rawEntryDN, |
| | | List<RawModification> rawModifications, |
| | | List<Control> controls) |
| | | { |
| | |
| | | * and contains information about the result of the |
| | | * processing. |
| | | */ |
| | | public ModifyOperation processModify( |
| | | ModifyChangeRecordEntry modifyRecord) |
| | | public ModifyOperation processModify(ModifyChangeRecordEntry modifyRecord) |
| | | { |
| | | return processModify(modifyRecord.getDN().toString(), |
| | | modifyRecord.getModifications()); |
| | | return processModify(ByteString.valueOfObject(modifyRecord.getDN()), |
| | | modifyRecord.getModifications(), null); |
| | | } |
| | | |
| | | /** |
| | | * Processes an internal modify operation with the provided information. |
| | | * |
| | | * @param modifyRequest |
| | | * The modify request with information about the changes to perform. |
| | | * @return A reference to the modify operation that was processed and contains information about |
| | | * the result of the processing. |
| | | */ |
| | | public ModifyOperation processModify(ModifyRequest modifyRequest) |
| | | { |
| | | return processModify(ByteString.valueOfObject(modifyRequest.getName()), |
| | | toRawModifications(modifyRequest.getModifications()), to(modifyRequest.getControls())); |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tasks; |
| | | |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.messages.TaskMessages; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.admin.server.ServerManagementContext; |
| | | import org.opends.server.admin.std.server.BackendCfg; |
| | | import org.opends.server.admin.std.server.RootCfg; |
| | |
| | | import org.opends.server.config.StringConfigAttribute; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.RawModification; |
| | | import org.opends.server.util.CollectionUtils; |
| | | import org.opends.server.util.ServerConstants; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.messages.TaskMessages.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | /** |
| | |
| | | e.getMessageObject(), e); |
| | | } |
| | | |
| | | LDAPAttribute a = new LDAPAttribute(ATTR_BACKEND_ENABLED, ServerConstants.TRUE_VALUE); |
| | | LDAPModification m = new LDAPModification(ModificationType.REPLACE, a); |
| | | |
| | | ArrayList<RawModification> modList = CollectionUtils.<RawModification> newArrayList(m); |
| | | |
| | | String backendDNString = configEntryDN.toString(); |
| | | ByteString rawEntryDN = ByteString.valueOfUtf8(backendDNString); |
| | | ModifyOperation internalModify = getRootConnection().processModify(rawEntryDN, modList); |
| | | ModifyRequest modifyRequest = newModifyRequest(from(configEntryDN)) |
| | | .addModification(REPLACE, ATTR_BACKEND_ENABLED, TRUE_VALUE); |
| | | ModifyOperation internalModify = getRootConnection().processModify(modifyRequest); |
| | | |
| | | ResultCode resultCode = internalModify.getResultCode(); |
| | | if (resultCode != ResultCode.SUCCESS) |
| | | { |
| | | LocalizableMessage message = |
| | | TaskMessages.ERR_TASK_CANNOT_ENABLE_BACKEND.get(backendDNString); |
| | | LocalizableMessage message = ERR_TASK_CANNOT_ENABLE_BACKEND.get(configEntryDN); |
| | | throw new DirectoryException(resultCode, message); |
| | | } |
| | | } |
| | |
| | | e.getMessageObject(), e); |
| | | } |
| | | |
| | | LDAPAttribute a = new LDAPAttribute(ATTR_BACKEND_ENABLED, ServerConstants.FALSE_VALUE); |
| | | LDAPModification m = new LDAPModification(ModificationType.REPLACE, a); |
| | | |
| | | ArrayList<RawModification> modList = CollectionUtils.<RawModification> newArrayList(m); |
| | | |
| | | String backendDNString = configEntryDN.toString(); |
| | | ByteString rawEntryDN = ByteString.valueOfUtf8(backendDNString); |
| | | ModifyOperation internalModify = getRootConnection().processModify(rawEntryDN, modList); |
| | | ModifyRequest modifyRequest = newModifyRequest(from(configEntryDN)) |
| | | .addModification(REPLACE, ATTR_BACKEND_ENABLED, FALSE_VALUE); |
| | | ModifyOperation internalModify = getRootConnection().processModify(modifyRequest); |
| | | |
| | | ResultCode resultCode = internalModify.getResultCode(); |
| | | if (resultCode != ResultCode.SUCCESS) |
| | | { |
| | | LocalizableMessage message = |
| | | TaskMessages.ERR_TASK_CANNOT_DISABLE_BACKEND.get(backendDNString); |
| | | LocalizableMessage message = ERR_TASK_CANNOT_DISABLE_BACKEND.get(configEntryDN); |
| | | throw new DirectoryException(resultCode, message); |
| | | } |
| | | } |
| | |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.extensions.TestPasswordValidator; |
| | | import org.opends.server.protocols.ldap.BindRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.opends.server.protocols.ldap.ModifyRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.ModifyResponseProtocolOp; |
| | | import org.opends.server.tools.LDAPPasswordModify; |
| | | import org.opends.server.tools.LDAPWriter; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.RawModification; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | |
| | | "ds-privilege-name: bypass-acl", |
| | | "userPassword: password"); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("uid=test.user,o=test", "password"); |
| | | conn.modify(newModifyRequest("uid=test.user,o=test") |
| | | .addModification(REPLACE, "userPassword", "newPassword")); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("uid=test.user,o=test"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | LDAPAttribute attr = new LDAPAttribute("userPassword", "newPassword"); |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, attr)); |
| | | |
| | | ModifyRequestProtocolOp modifyRequest = |
| | | new ModifyRequestProtocolOp( |
| | | ByteString.valueOfUtf8("uid=test.user,o=test"), mods); |
| | | message = new LDAPMessage(2, modifyRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | ModifyResponseProtocolOp modifyResponse = |
| | | message.getModifyResponseProtocolOp(); |
| | | assertEquals(modifyResponse.getResultCode(), 0); |
| | | |
| | | assertEquals(TestPasswordValidator.getLastNewPassword(), |
| | | ByteString.valueOfUtf8("newPassword")); |
| | | assertTrue(TestPasswordValidator.getLastCurrentPasswords().isEmpty()); |
| | | assertEquals(TestPasswordValidator.getLastNewPassword(), ByteString.valueOfUtf8("newPassword")); |
| | | assertTrue(TestPasswordValidator.getLastCurrentPasswords().isEmpty()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | * Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.backends; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.messages.ReplicationMessages.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.replication.protocol.OperationContext.*; |
| | |
| | | import org.assertj.core.api.SoftAssertions; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.admin.std.server.ExternalChangelogDomainCfg; |
| | |
| | | "telephonenumber: 131313"); |
| | | |
| | | // mod 'sn' of fiona with 'sn' configured as ecl-incl-att |
| | | final ModifyOperation modOp1 = connection.processModify(uentry1.getName(), createAttributeModif("sn", "newsn")); |
| | | final ModifyOperation modOp1 = connection.processModify( |
| | | newModifyRequest(from(uentry1.getName())) |
| | | .addModification(REPLACE, "sn", "newsn")); |
| | | waitForSearchOpResult(modOp1, ResultCode.SUCCESS); |
| | | |
| | | // mod 'telephonenumber' of robert |
| | | final ModifyOperation modOp2 = connection.processModify(uentry2.getName(), |
| | | createAttributeModif("telephonenumber", "555555")); |
| | | final ModifyOperation modOp2 = connection.processModify( |
| | | newModifyRequest(from(uentry2.getName())) |
| | | .addModification(REPLACE, "telephonenumber", "555555")); |
| | | waitForSearchOpResult(modOp2, ResultCode.SUCCESS); |
| | | |
| | | // moddn robert to robert2 |
| | |
| | | { |
| | | assertSameServerId(replicaId, csn); |
| | | DN baseDN = DN.valueOf("uid=" + testName + "3," + replicaId.getBaseDN()); |
| | | List<Modification> mods = createAttributeModif("description", "new value"); |
| | | List<Modification> mods = newArrayList(new Modification(REPLACE, Attributes.create("description", "new value"))); |
| | | return new ModifyMsg(csn, baseDN, mods, testName + "uuid3"); |
| | | } |
| | | |
| | | private List<Modification> createAttributeModif(String attributeName, String valueString) |
| | | { |
| | | Attribute attr = Attributes.create(attributeName, valueString); |
| | | return newArrayList(new Modification(ModificationType.REPLACE, attr)); |
| | | } |
| | | |
| | | private UpdateMsg generateModDNMsg(ReplicaId replicaId, CSN csn, String testName) throws Exception |
| | | { |
| | | assertSameServerId(replicaId, csn); |
| | |
| | | "userPassword: password", |
| | | "ds-privilege-name: bypass-acl"); |
| | | |
| | | try (RemoteConnection c = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPMessage bindMessage = c.bind("uid=test.user,o=test", "password", newPasswordPolicyControl()); |
| | | SimpleBindRequest bindRequest = newSimpleBindRequest("uid=test.user,o=test", "password".toCharArray()) |
| | | .addControl(newPasswordPolicyControl()); |
| | | LDAPMessage bindMessage = conn.bind(bindRequest, false); |
| | | assertTrue(passwordPolicyControlExists(bindMessage.getControls(), PasswordPolicyErrorType.CHANGE_AFTER_RESET)); |
| | | |
| | | AddRequest addRequest = newAddRequest("ou=People,o=test") |
| | | .addAttribute("objectClass", "organizationalUnit") |
| | | .addAttribute("ou", "People") |
| | | .addControl(newPasswordPolicyControl()); |
| | | LDAPMessage message = c.add(addRequest, false); |
| | | LDAPMessage message = conn.add(addRequest, false); |
| | | |
| | | AddResponseProtocolOp addResponse = message.getAddResponseProtocolOp(); |
| | | assertNotEquals(addResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.controls; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.controls.PersistentSearchChangeType.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.*; |
| | | import java.util.EnumSet; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.io.ASN1; |
| | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.opends.server.protocols.ldap.LDAPReader; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.CancelRequest; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | //Modify the configuration to allow only 1 concurrent persistent search. |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | LDAPAttribute attr = new LDAPAttribute("ds-cfg-max-psearches", "1"); |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, attr)); |
| | | |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8("cn=config"), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest("cn=config") |
| | | .addModification(ModificationType.REPLACE, "ds-cfg-max-psearches", "1"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | //Create a persistent search request. |
| | |
| | | .setTypesOnly(true) |
| | | .addAttribute("cn") |
| | | .addControl(new PersistentSearchControl(changeTypes, true, true)); |
| | | final InternalSearchOperation search = conn.processSearch(request); |
| | | final InternalSearchOperation search = getRootConnection().processSearch(request); |
| | | |
| | | Thread t = new Thread(new Runnable() { |
| | | @Override |
| | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashSet; |
| | | |
| | |
| | | import org.opends.server.protocols.ldap.ModifyResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.SearchRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.SearchResultDoneProtocolOp; |
| | | import org.opends.server.tools.LDAPWriter; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.CancelRequest; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.types.RawModification; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | { |
| | | // Establish a connection to the server. It can be unauthenticated for the |
| | | // purpose of this test. |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // Send the abandon request to the server and wait a few seconds to ensure |
| | | // it has completed before closing the connection. |
| | | conn.writeMessage(new AbandonRequestProtocolOp(1), DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | |
| | | |
| | | // Send the abandon request to the server and wait a few seconds to ensure |
| | | // it has completed before closing the connection. |
| | | AbandonRequestProtocolOp abandonRequest = new AbandonRequestProtocolOp(1); |
| | | LDAPMessage message = new LDAPMessage(2, abandonRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | w.writeMessage(message); |
| | | |
| | | Thread.sleep(3000); |
| | | |
| | | StaticUtils.close(s); |
| | | Thread.sleep(3000); |
| | | } |
| | | |
| | | // NOTE: We can't check to see if pre-parse plugins were called yet |
| | | // because there's no plugin ordering. It's possible that the |
| | |
| | | { |
| | | // Establish a connection to the server. It can be unauthenticated for the |
| | | // purpose of this test. |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // Send the abandon request to the server and wait a few seconds to ensure |
| | | // it has completed before closing the connection. |
| | | conn.writeMessage(new AbandonRequestProtocolOp(1)); |
| | | |
| | | |
| | | // Send the abandon request to the server and wait a few seconds to ensure |
| | | // it has completed before closing the connection. |
| | | AbandonRequestProtocolOp abandonRequest = new AbandonRequestProtocolOp(1); |
| | | w.writeMessage(new LDAPMessage(2, abandonRequest)); |
| | | |
| | | Thread.sleep(3000); |
| | | |
| | | s.close(); |
| | | Thread.sleep(3000); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | |
| | | assertNull(DirectoryServer.getBackend(backendID)); |
| | | assertFalse(DirectoryServer.isNamingContext(baseDN)); |
| | | |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | // Modify the backend to enable it. |
| | | ArrayList<Modification> mods = newArrayList(new Modification(REPLACE, Attributes.create("ds-cfg-enabled", "true"))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(backendEntry.getName(), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | enableBackend(backendEntry, true); |
| | | |
| | | Backend<?> backend = DirectoryServer.getBackend(backendID); |
| | | assertBackend(baseDN, backend); |
| | | createEntry(baseDN, backend); |
| | | |
| | | |
| | | // Modify the backend to disable it. |
| | | mods = newArrayList(new Modification(REPLACE, Attributes.create("ds-cfg-enabled", "false"))); |
| | | modifyOperation = conn.processModify(backendEntry.getName(), mods); |
| | | enableBackend(backendEntry, false); |
| | | assertNull(DirectoryServer.getBackend(backendID)); |
| | | assertFalse(DirectoryServer.entryExists(baseDN)); |
| | | assertFalse(DirectoryServer.isNamingContext(baseDN)); |
| | | |
| | | |
| | | // Delete the disabled backend. |
| | | DeleteOperation deleteOperation = conn.processDelete(backendEntry.getName()); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(backendEntry.getName()); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | // Now we can create the grandchild base entry. |
| | | createEntry(grandchildBaseDN, grandchildBackend); |
| | | |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | // Verify that a subtree search can see all three entries. |
| | | final SearchRequest request = newSearchRequest(parentBaseDN, SearchScope.WHOLE_SUBTREE); |
| | | assertSearchResultsSize(request, 3); |
| | | |
| | | |
| | | // Disable the intermediate (child) backend. This should be allowed. |
| | | ArrayList<Modification> mods = |
| | | newArrayList(new Modification(REPLACE, Attributes.create("ds-cfg-enabled", "false"))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(childBackendEntry.getName(), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | enableBackend(childBackendEntry, false); |
| | | |
| | | assertSearchResultsSize(request, 2); |
| | | |
| | | |
| | | // Re-enable the intermediate backend. |
| | | mods = newArrayList(new Modification(REPLACE, Attributes.create("ds-cfg-enabled", "true"))); |
| | | modifyOperation = conn.processModify(childBackendEntry.getName(), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | enableBackend(childBackendEntry, true); |
| | | |
| | | |
| | | // Update our reference to the child backend since the old one is no longer |
| | |
| | | assertNull(DirectoryServer.getBackend(parentBackendID)); |
| | | } |
| | | |
| | | private void enableBackend(Entry entry, boolean enabled) |
| | | { |
| | | ModifyRequest modifyRequest = newModifyRequest(from(entry.getName())) |
| | | .addModification(REPLACE, "ds-cfg-enabled", Boolean.toString(enabled)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | private void assertSearchResultsSize(final SearchRequest request, int expected) |
| | | { |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.plugins.DisconnectClientPlugin; |
| | | import org.opends.server.plugins.InvocationCounterPlugin; |
| | | import org.opends.server.plugins.ShortCircuitPlugin; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.ldap.*; |
| | | import org.opends.server.tools.*; |
| | | import org.opends.server.tools.LDAPReader; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.opends.server.protocols.ldap.BindRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.opends.server.tools.LDAPDelete; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.AuthenticationType; |
| | | import org.opends.server.types.CancelRequest; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.OperationType; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.ldap.LDAPConstants.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | |
| | | InternalClientConnection conn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindOperation bindOperation = |
| | | conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds); |
| | | BindOperation bindOperation = conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds()); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNotNull(bindOperation.getSASLAuthUserEntry()); |
| | | } |
| | |
| | | InternalClientConnection conn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindOperation bindOperation = |
| | | conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds); |
| | | BindOperation bindOperation = conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds()); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNotNull(bindOperation.getUserEntryDN()); |
| | | } |
| | |
| | | InternalClientConnection conn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindOperation bindOperation = |
| | | conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds); |
| | | BindOperation bindOperation = conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds()); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertTrue(bindOperation.getProcessingStartTime() > 0); |
| | | assertTrue(bindOperation.getProcessingStopTime() >= |
| | |
| | | InternalClientConnection conn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindOperation bindOperation = |
| | | conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds); |
| | | BindOperation bindOperation = conn.processSASLBind(DN.rootDN(), "PLAIN", saslCreds()); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | // assertTrue(InvocationCounterPlugin.getPreParseCount() > 0); |
| | |
| | | public void testBindDisconnectInPreParseSimpleAnonymous() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), 3, |
| | | ByteString.empty()); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage(anonymousBindRequest(), DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPreOperationSimpleAnonymous() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), 3, |
| | | ByteString.empty()); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PreOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage(anonymousBindRequest(), DisconnectClientPlugin.createDisconnectControlList("PreOperation")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPostOperationSimpleAnonymous() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), 3, |
| | | ByteString.empty()); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PostOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage(anonymousBindRequest(), DisconnectClientPlugin.createDisconnectControlList("PostOperation")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPostResponseSimpleAnonymous() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), 3, |
| | | ByteString.empty()); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PostResponse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | while (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | assertThat(message.getProtocolOpType()).isIn(OP_TYPE_BIND_RESPONSE, OP_TYPE_EXTENDED_RESPONSE); |
| | | message = r.readMessage(); |
| | | } |
| | | conn.writeMessage(anonymousBindRequest(), DisconnectClientPlugin.createDisconnectControlList("PostResponse")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | while (message != null) |
| | | { |
| | | assertThat(message.getProtocolOpType()).isIn(OP_TYPE_BIND_RESPONSE, OP_TYPE_EXTENDED_RESPONSE); |
| | | message = conn.readMessage(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPreParseSimpleAuthenticated() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage(bindRequest(), DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private BindRequestProtocolOp bindRequest() |
| | | { |
| | | String bindDn = "cn=Directory Manager"; |
| | | String bindPwd = "password"; |
| | | return new BindRequestProtocolOp(ByteString.valueOfUtf8(bindDn), 3, ByteString.valueOfUtf8(bindPwd)); |
| | | } |
| | | |
| | | private BindRequestProtocolOp anonymousBindRequest() |
| | | { |
| | | return new BindRequestProtocolOp(ByteString.empty(), 3, ByteString.empty()); |
| | | } |
| | | |
| | | private ByteString saslCreds() |
| | | { |
| | | return ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | } |
| | | |
| | | private BindRequestProtocolOp plainBindRequest() |
| | | { |
| | | return new BindRequestProtocolOp(ByteString.empty(), "PLAIN", saslCreds()); |
| | | } |
| | | |
| | | /** |
| | | * Tests an authenticated simple bind operation to ensure that it's treated |
| | |
| | | public void testBindDisconnectInPreOperationSimpleAuthenticated() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PreOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage(bindRequest(), DisconnectClientPlugin.createDisconnectControlList("PreOperation")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPostOperationSimpleAuthenticated() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PostOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage(bindRequest(), DisconnectClientPlugin.createDisconnectControlList("PostOperation")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPostResponseSimpleAuthenticated() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PostResponse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | while (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | assertThat(message.getProtocolOpType()).isIn(OP_TYPE_BIND_RESPONSE, OP_TYPE_EXTENDED_RESPONSE); |
| | | message = r.readMessage(); |
| | | } |
| | | conn.writeMessage(bindRequest(), DisconnectClientPlugin.createDisconnectControlList("PostResponse")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | while (message != null) |
| | | { |
| | | assertThat(message.getProtocolOpType()).isIn(OP_TYPE_BIND_RESPONSE, OP_TYPE_EXTENDED_RESPONSE); |
| | | message = conn.readMessage(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPreParseSASL() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), "PLAIN", saslCreds); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage(plainBindRequest(), DisconnectClientPlugin.createDisconnectControlList("PreParse")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPreOperationSASL() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), "PLAIN", saslCreds); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PreOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | conn.writeMessage( |
| | | plainBindRequest(), |
| | | DisconnectClientPlugin.createDisconnectControlList("PreOperation")); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindDisconnectInPostOperationSASL() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), "PLAIN", saslCreds); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PostOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | if (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | conn.writeMessage(plainBindRequest(), DisconnectClientPlugin.createDisconnectControlList("PostOperation")); |
| | | |
| | | LDAPMessage message = conn.readMessage(); |
| | | if (message != null) |
| | | { |
| | | // If we got an element back, then it must be a notice of disconnect |
| | | // unsolicited notification. |
| | | assertEquals(message.getProtocolOpType(), OP_TYPE_EXTENDED_RESPONSE); |
| | | } |
| | | } |
| | | |
| | | StaticUtils.close(s); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests a SASL bind operation to ensure that it's treated properly if the |
| | | * client connection is lost in post-response plugin processing. |
| | |
| | | public void testBindDisconnectInPostResponseSASL() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), "PLAIN", saslCreds); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | DisconnectClientPlugin.createDisconnectControlList( |
| | | "PostResponse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | while (message != null) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | assertThat(message.getProtocolOpType()).isIn(OP_TYPE_BIND_RESPONSE, OP_TYPE_EXTENDED_RESPONSE); |
| | | message = r.readMessage(); |
| | | conn.writeMessage(plainBindRequest(), DisconnectClientPlugin.createDisconnectControlList("PostResponse")); |
| | | |
| | | LDAPMessage message = conn.readMessage(); |
| | | while (message != null) |
| | | { |
| | | assertThat(message.getProtocolOpType()).isIn(OP_TYPE_BIND_RESPONSE, OP_TYPE_EXTENDED_RESPONSE); |
| | | message = conn.readMessage(); |
| | | } |
| | | } |
| | | |
| | | StaticUtils.close(s); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests an anonymous simple bind operation to ensure that it's treated |
| | | * properly if the operation gets short-circuited in pre-parse plugin |
| | |
| | | public void testBindShortCircuitInPreParseSimpleAnonymous() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.writeMessage(anonymousBindRequest(), ShortCircuitPlugin.createShortCircuitControlList(80, "PreParse")); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), 3, |
| | | ByteString.empty()); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | ShortCircuitPlugin.createShortCircuitControlList(80, "PreParse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindShortCircuitInPreOperationSimpleAnonymous() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.writeMessage(anonymousBindRequest(), ShortCircuitPlugin.createShortCircuitControlList(80, "PreOperation")); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), 3, |
| | | ByteString.empty()); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | ShortCircuitPlugin.createShortCircuitControlList(80, |
| | | "PreOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests an authenticated simple bind operation to ensure that it's treated |
| | | * properly if the operation gets short-circuited in pre-parse plugin |
| | |
| | | public void testBindShortCircuitInPreParseSimpleAuthenticated() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.writeMessage(bindRequest(), ShortCircuitPlugin.createShortCircuitControlList(80, "PreParse")); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | ShortCircuitPlugin.createShortCircuitControlList(80, "PreParse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindShortCircuitInPreOperationSimpleAuthenticated() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.writeMessage(bindRequest(), ShortCircuitPlugin.createShortCircuitControlList(80, "PreOperation")); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | ShortCircuitPlugin.createShortCircuitControlList(80, |
| | | "PreOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindShortCircuitInPreParseSASL() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.writeMessage(plainBindRequest(), ShortCircuitPlugin.createShortCircuitControlList(80, "PreParse")); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), "PLAIN", saslCreds); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | ShortCircuitPlugin.createShortCircuitControlList(80, "PreParse")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testBindShortCircuitInPreOperationSASL() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | TestCaseUtils.configureSocket(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.writeMessage(plainBindRequest(), ShortCircuitPlugin.createShortCircuitControlList(80, "PreOperation")); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), "PLAIN", saslCreds); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, |
| | | ShortCircuitPlugin.createShortCircuitControlList(80, |
| | | "PreOperation")); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | |
| | | StaticUtils.close(s); |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 80); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | InternalClientConnection conn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindOperation bindOperation = |
| | | conn.processSASLBind(ByteString.valueOfUtf8("invaliddn"), "PLAIN", |
| | | saslCreds); |
| | | BindOperation bindOperation = conn.processSASLBind(ByteString.valueOfUtf8("invaliddn"), "PLAIN", saslCreds()); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.INVALID_CREDENTIALS); |
| | | } |
| | | |
| | |
| | | ArrayList<Control> requestControls = new ArrayList<>(1); |
| | | requestControls.add(new LDAPControl("1.2.3.4", true)); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindOperationBasis bindOperation = |
| | | new BindOperationBasis(conn, InternalClientConnection.nextOperationID(), InternalClientConnection.nextMessageID(), |
| | | new BindOperationBasis(conn, nextOperationID(), nextMessageID(), |
| | | requestControls, "3", DN.rootDN(), "PLAIN", |
| | | saslCreds); |
| | | saslCreds()); |
| | | bindOperation.run(); |
| | | assertEquals(bindOperation.getResultCode(), |
| | | ResultCode.UNAVAILABLE_CRITICAL_EXTENSION); |
| | |
| | | ArrayList<Control> requestControls = new ArrayList<>(1); |
| | | requestControls.add(new LDAPControl("1.2.3.4", false)); |
| | | |
| | | ByteString saslCreds = |
| | | ByteString.valueOfUtf8("\u0000dn:cn=Directory Manager\u0000password"); |
| | | |
| | | BindOperationBasis bindOperation = |
| | | new BindOperationBasis(conn, InternalClientConnection.nextOperationID(), InternalClientConnection.nextMessageID(), |
| | | new BindOperationBasis(conn, nextOperationID(), nextMessageID(), |
| | | requestControls, "3", DN.rootDN(), "PLAIN", |
| | | saslCreds); |
| | | saslCreds()); |
| | | bindOperation.run(); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | bindWithDnRequiresPassword(false); |
| | | |
| | | String attr = "ds-cfg-bind-with-dn-requires-password"; |
| | | ArrayList<Modification> mods = newArrayList(new Modification(REPLACE, Attributes.create(attr, "false"))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.valueOf("cn=config"), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | BindOperation bindOperation = |
| | | conn.processSimpleBind(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | ByteString.empty()); |
| | | BindOperation bindOperation = getRootConnection().processSimpleBind("cn=Directory Manager", ""); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | mods = newArrayList(new Modification(REPLACE, Attributes.create(attr, "true"))); |
| | | modifyOperation = conn.processModify(DN.valueOf("cn=config"), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | bindWithDnRequiresPassword(true); |
| | | } |
| | | |
| | | |
| | | private void bindWithDnRequiresPassword(boolean required) |
| | | { |
| | | ModifyRequest modifyRequest = newModifyRequest("cn=config") |
| | | .addModification(REPLACE, "ds-cfg-bind-with-dn-requires-password", Boolean.toString(required)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | /** |
| | | * Tests performing a simple bind operation as a user who doesn't have a |
| | |
| | | String dnString = "uid=rebind.test,o=test"; |
| | | DN userDN = DN.valueOf(dnString); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | TestCaseUtils.configureSocket(s); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind(dnString, "password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8(dnString), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get(userDN).size(), 1); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | // We occasionally run into |
| | | // ProtocolMessages.MSGID_LDAP_CLIENT_DUPLICATE_MESSAGE_ID, so we wait |
| | | // for previous ops to complete. |
| | | TestCaseUtils.quiesceServer(); |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get(userDN).size(), |
| | | 1); |
| | | |
| | | // We occasionally run into |
| | | // ProtocolMessages.MSGID_LDAP_CLIENT_DUPLICATE_MESSAGE_ID, so we wait |
| | | // for previous ops to complete. |
| | | TestCaseUtils.quiesceServer(); |
| | | bindRequest = new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 3, |
| | | ByteString.valueOfUtf8("password")); |
| | | message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0, message.toString()); |
| | | |
| | | assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | |
| | | s.close(); |
| | | assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | String dnString = "uid=test,ou=people,dc=example,dc=com"; |
| | | DN userDN = DN.valueOf(dnString); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | TestCaseUtils.configureSocket(s); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8(dnString), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = |
| | | message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get( |
| | | userDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get( |
| | | userDN).size(), 1); |
| | | |
| | | String[] args = |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Directory Manager", |
| | | "-w", "password", |
| | | "-J", OID_SUBTREE_DELETE_CONTROL + ":true", |
| | | "--noPropertiesFile", |
| | | "ou=people,dc=example,dc=com" |
| | | }; |
| | | assertEquals(LDAPDelete.mainDelete(args, false, null, System.err), 0); |
| | | conn.bind(dnString, "password"); |
| | | |
| | | assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get(userDN).size(), 1); |
| | | |
| | | s.close(); |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Directory Manager", |
| | | "-w", "password", |
| | | "-J", OID_SUBTREE_DELETE_CONTROL + ":true", |
| | | "--noPropertiesFile", |
| | | "ou=people,dc=example,dc=com" |
| | | }; |
| | | assertEquals(LDAPDelete.mainDelete(args, false, null, System.err), 0); |
| | | |
| | | TestCaseUtils.clearBackend("userRoot"); |
| | | assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | } |
| | | finally |
| | | { |
| | | TestCaseUtils.clearBackend("userRoot"); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | String dnString = "uid=test,ou=people,dc=example,dc=com"; |
| | | DN userDN = DN.valueOf(dnString); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | TestCaseUtils.configureSocket(s); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8(dnString), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = |
| | | message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get( |
| | | userDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get( |
| | | userDN).size(), 1); |
| | | |
| | | String path = TestCaseUtils.createTempFile( |
| | | "dn: ou=people,dc=example,dc=com", |
| | | "changetype: moddn", |
| | | "newRDN: ou=users", |
| | | "deleteOldRDN: 1"); |
| | | String[] args = |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Directory Manager", |
| | | "-w", "password", |
| | | "--noPropertiesFile", |
| | | "-f", path |
| | | }; |
| | | assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0); |
| | | conn.bind(dnString, "password"); |
| | | |
| | | String newDNString = "uid=test,ou=users,dc=example,dc=com"; |
| | | DN newUserDN = DN.valueOf(newDNString); |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get(userDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get(userDN).size(), 1); |
| | | |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get( |
| | | newUserDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get( |
| | | newUserDN).size(), 1); |
| | | String path = TestCaseUtils.createTempFile( |
| | | "dn: ou=people,dc=example,dc=com", |
| | | "changetype: moddn", |
| | | "newRDN: ou=users", |
| | | "deleteOldRDN: 1"); |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | | "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", "cn=Directory Manager", |
| | | "-w", "password", |
| | | "--noPropertiesFile", |
| | | "-f", path |
| | | }; |
| | | assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0); |
| | | |
| | | s.close(); |
| | | |
| | | TestCaseUtils.clearBackend("userRoot"); |
| | | DN newUserDN = DN.valueOf("uid=test,ou=users,dc=example,dc=com"); |
| | | assertNotNull(DirectoryServer.getAuthenticatedUsers().get(newUserDN)); |
| | | assertEquals(DirectoryServer.getAuthenticatedUsers().get(newUserDN).size(), 1); |
| | | } |
| | | finally |
| | | { |
| | | TestCaseUtils.clearBackend("userRoot"); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.server.GroupImplementationCfg; |
| | | import org.opends.server.api.Group; |
| | |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.tools.LDAPDelete; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.MemberList; |
| | | import org.opends.server.types.MembershipException; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | |
| | | //Add even numbered members. |
| | | group1Instance.addMember(user2Entry); |
| | | group1Instance.addMember(user4Entry); |
| | | |
| | | //Switch things around, change groups and members to odd numbered nested |
| | | //groups and odd numbered members via ldap modify. |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | Attribute g1 = Attributes.create("member", "cn=group 1,ou=Groups,o=test"); |
| | | Attribute g2 = Attributes.create("member", "cn=group 2,ou=Groups,o=test"); |
| | | Attribute g3 = Attributes.create("member", "cn=group 3,ou=Groups,o=test"); |
| | | Attribute g4 = Attributes.create("member", "cn=group 4,ou=Groups,o=test"); |
| | | Attribute u1 = Attributes.create("member", "uid=user.1,ou=People,o=test"); |
| | | Attribute u2 = Attributes.create("member", "uid=user.2,ou=People,o=test"); |
| | | Attribute u3 = Attributes.create("member", "uid=user.3,ou=People,o=test"); |
| | | Attribute u4 = Attributes.create("member", "uid=user.4,ou=People,o=test"); |
| | | Attribute u5 = Attributes.create("member", "uid=user.5,ou=People,o=test"); |
| | | //Delete even groups and users. |
| | | mods.add(new Modification(ModificationType.DELETE, g2)); |
| | | mods.add(new Modification(ModificationType.DELETE, g4)); |
| | | mods.add(new Modification(ModificationType.DELETE, u2)); |
| | | mods.add(new Modification(ModificationType.DELETE, u4)); |
| | | final ModifyRequest modifyRequest = newModifyRequest(from(group1Instance.getGroupDN())); |
| | | modifyRequest.addModification(DELETE, "member", "cn=group 2,ou=Groups,o=test"); |
| | | modifyRequest.addModification(DELETE, "member", "cn=group 4,ou=Groups,o=test"); |
| | | modifyRequest.addModification(DELETE, "member", "uid=user.2,ou=People,o=test"); |
| | | modifyRequest.addModification(DELETE, "member", "uid=user.4,ou=People,o=test"); |
| | | //Add odd groups and users. |
| | | mods.add(new Modification(ModificationType.ADD, g1)); |
| | | mods.add(new Modification(ModificationType.ADD, g3)); |
| | | mods.add(new Modification(ModificationType.ADD, u1)); |
| | | mods.add(new Modification(ModificationType.ADD, u3)); |
| | | mods.add(new Modification(ModificationType.ADD, u5)); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(group1Instance.getGroupDN(), mods); |
| | | modifyRequest.addModification(ADD, "member", "cn=group 1,ou=Groups,o=test"); |
| | | modifyRequest.addModification(ADD, "member", "cn=group 3,ou=Groups,o=test"); |
| | | modifyRequest.addModification(ADD, "member", "uid=user.1,ou=People,o=test"); |
| | | modifyRequest.addModification(ADD, "member", "uid=user.3,ou=People,o=test"); |
| | | modifyRequest.addModification(ADD, "member", "uid=user.5,ou=People,o=test"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | //Check that the user membership changes were picked up. |
| | | assertFalse(group1Instance.isMember(user2Entry)); |
| | | assertFalse(group1Instance.isMember(user4Entry)); |
| | |
| | | //Add some nested groups and members. |
| | | group1Instance.addNestedGroup(group2DN); |
| | | group1Instance.addMember(user1Entry); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | //Delete the group. |
| | | DeleteOperation deleteOperation = conn.processDelete(group1DN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(group1DN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(group1DN)); |
| | | //Membership check should throw an exception. |
| | |
| | | "it didn't"); |
| | | } catch (DirectoryException ex) {} |
| | | //Modify list via ldap modify. |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | Attribute a2 = Attributes.create("member", "cn=group 2,ou=Groups,o=test"); |
| | | Attribute a3 = Attributes.create("member", "cn=group 1,ou=Groups,o=test"); |
| | | mods.add(new Modification(ModificationType.DELETE, a2)); |
| | | mods.add(new Modification(ModificationType.ADD, a3)); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(group1Instance.getGroupDN(), mods); |
| | | final ModifyRequest modifyRequest = newModifyRequest(from(group1Instance.getGroupDN())) |
| | | .addModification(DELETE, "member", "cn=group 2,ou=Groups,o=test") |
| | | .addModification(ADD, "member", "cn=group 1,ou=Groups,o=test"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | //Check removing a group already removed via ldap modify fails. |
| | | try |
| | |
| | | groupInstance.toString(new StringBuilder()); |
| | | |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Modify the group and make sure the group manager gets updated accordingly |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | Attribute a2 = Attributes.create("member", "uid=user.2,ou=People,o=test"); |
| | | Attribute a3 = Attributes.create("member", "uid=user.3,ou=People,o=test"); |
| | | mods.add(new Modification(ModificationType.DELETE, a2)); |
| | | mods.add(new Modification(ModificationType.ADD, a3)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyOperation modifyOperation = conn.processModify(groupDN, mods); |
| | | final ModifyRequest modifyRequest = newModifyRequest(from(groupDN)) |
| | | .addModification(DELETE, "member", "uid=user.2,ou=People,o=test") |
| | | .addModification(ADD, "member", "uid=user.3,ou=People,o=test"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | groupInstance = groupManager.getGroupInstance(groupDN); |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Modify the group and make sure the group manager gets updated accordingly |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | Attribute a2 = Attributes.create("uniquemember", "uid=user.2,ou=People,o=test"); |
| | | Attribute a3 = Attributes.create("uniquemember", "uid=user.3,ou=People,o=test"); |
| | | mods.add(new Modification(ModificationType.DELETE, a2)); |
| | | mods.add(new Modification(ModificationType.ADD, a3)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyOperation modifyOperation = conn.processModify(groupDN, mods); |
| | | final ModifyRequest modifyRequest = newModifyRequest(from(groupDN)) |
| | | .addModification(DELETE, "uniquemember", "uid=user.2,ou=People,o=test") |
| | | .addModification(ADD, "uniquemember", "uid=user.3,ou=People,o=test"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | groupInstance = groupManager.getGroupInstance(groupDN); |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Modify the group and make sure the group manager gets updated accordingly |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | Attribute a2 = Attributes.create("member", "uid=user.2,ou=People,o=test"); |
| | | Attribute a3 = Attributes.create("member", "uid=user.3,ou=People,o=test"); |
| | | mods.add(new Modification(ModificationType.DELETE, a2)); |
| | | mods.add(new Modification(ModificationType.ADD, a3)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyOperation modifyOperation = conn.processModify(groupDN, mods); |
| | | final ModifyRequest modifyRequest = newModifyRequest(from(groupDN)) |
| | | .addModification(DELETE, "member", "uid=user.2,ou=People,o=test") |
| | | .addModification(ADD, "member", "uid=user.3,ou=People,o=test"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | groupInstance = groupManager.getGroupInstance(groupDN); |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | RDN newRDN = RDN.decode("cn=Renamed Group"); |
| | | DN newDN = DN.valueOf("cn=Renamed Group,ou=Groups,o=test"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyDNOperation modifyDNOperation = |
| | | conn.processModifyDN(groupDN, newRDN, true); |
| | | getRootConnection().processModifyDN(groupDN, newRDN, true); |
| | | assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | groupInstance = groupManager.getGroupInstance(groupDN); |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | DeleteOperation deleteOperation = conn.processDelete(newDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(newDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(newDN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Delete all of the groups and make sure the group manager gets updated accordingly |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(group1DN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(group1DN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(group1DN)); |
| | | |
| | | deleteOperation = conn.processDelete(group2DN); |
| | | deleteOperation = getRootConnection().processDelete(group2DN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(group2DN)); |
| | | |
| | | deleteOperation = conn.processDelete(group3DN); |
| | | deleteOperation = getRootConnection().processDelete(group3DN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(group3DN)); |
| | | |
| | | deleteOperation = conn.processDelete(group4DN); |
| | | deleteOperation = getRootConnection().processDelete(group4DN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(group3DN)); |
| | | } |
| | |
| | | |
| | | |
| | | // Delete the group and make sure the group manager gets updated accordingly |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | groupInstance.toString(new StringBuilder()); |
| | | |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | DynamicGroup dynamicGroup = (DynamicGroup) groupInstance; |
| | | assertTrue(dynamicGroup.getMemberURLs().isEmpty()); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | "Expected member set to be empty but it was not: " + memberSet); |
| | | |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | "Expected member set to be empty but it was not: " + memberSet); |
| | | |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | "Expected member set to be empty but it was not: " + memberSet); |
| | | |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | "Expected member set to be empty but it was not: " + memberSet); |
| | | |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = conn.processDelete(groupDN); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(groupDN); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertNull(groupManager.getGroupInstance(groupDN)); |
| | | } |
| | |
| | | import org.opends.server.plugins.DisconnectClientPlugin; |
| | | import org.opends.server.plugins.ShortCircuitPlugin; |
| | | import org.opends.server.plugins.UpdatePreOpPlugin; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.opends.server.protocols.ldap.ModifyRequestProtocolOp; |
| | |
| | | import org.opends.server.types.RawModification; |
| | | import org.opends.server.types.WritabilityMode; |
| | | import org.opends.server.util.Base64; |
| | | import org.opends.server.util.ServerConstants; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendModifyOperation; |
| | | import org.testng.annotations.AfterMethod; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.controls.GenericControl.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.protocols.ldap.LDAPConstants.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | |
| | | retrieveFailedOperationElements(modifyOperation); |
| | | } |
| | | |
| | | private ModifyOperation processModify(String entryDN, List<RawModification> mods) |
| | | { |
| | | InternalClientConnection conn = getRootConnection(); |
| | | return conn.processModify(ByteString.valueOfUtf8(entryDN), mods); |
| | | } |
| | | |
| | | private ModifyOperation processModify(String entryDN, RawModification... mods) |
| | | { |
| | | InternalClientConnection conn = getRootConnection(); |
| | | return conn.processModify(ByteString.valueOfUtf8(entryDN), Arrays.asList(mods)); |
| | | } |
| | | |
| | | private ModifyOperation processModify(String entryDN, |
| | | List<RawModification> mods, List<Control> requestControls) |
| | | { |
| | | InternalClientConnection conn = getRootConnection(); |
| | | return conn.processModify(ByteString.valueOfUtf8(entryDN), mods, requestControls); |
| | | return getRootConnection().processModify(ByteString.valueOfUtf8(entryDN), Arrays.asList(mods)); |
| | | } |
| | | |
| | | /** |
| | |
| | | "mail: foo"); |
| | | |
| | | String dn = "uid=test.user," + baseDN; |
| | | ModifyOperation modifyOperation = processModify(dn, newRawModifications(REPLACE, "uid", "test.user")); |
| | | ModifyOperation modifyOperation = processModify(dn, newRawModification(REPLACE, "uid", "test.user")); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | retrieveSuccessfulOperationElements(modifyOperation); |
| | | |
| | |
| | | "displayName: Test User", |
| | | "userPassword: password"); |
| | | |
| | | List<RawModification> mods = newRawModifications(ADD, "givenName", "Test"); |
| | | |
| | | List<Control> requestControls = new ArrayList<>(); |
| | | requestControls.add( |
| | | new LDAPControl(ServerConstants.OID_PERMISSIVE_MODIFY_CONTROL, false)); |
| | | |
| | | ModifyOperation modifyOperation = processModify("uid=test.user," + baseDN, |
| | | mods, requestControls); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest("uid=test.user," + baseDN) |
| | | .addModification(ADD, "givenName", "Test") |
| | | .addControl(newControl(OID_PERMISSIVE_MODIFY_CONTROL)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | retrieveSuccessfulOperationElements(modifyOperation); |
| | | } |
| | |
| | | "displayName: Test User", |
| | | "userPassword: password"); |
| | | |
| | | List<RawModification> mods = newRawModifications(DELETE, "givenName", "Foo"); |
| | | |
| | | List<Control> requestControls = new ArrayList<>(); |
| | | requestControls.add( |
| | | new LDAPControl(ServerConstants.OID_PERMISSIVE_MODIFY_CONTROL, false)); |
| | | |
| | | ModifyOperation modifyOperation = processModify("uid=test.user," + baseDN, |
| | | mods, requestControls); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest("uid=test.user," + baseDN) |
| | | .addModification(DELETE, "givenName", "Foo") |
| | | .addControl(newControl(OID_PERMISSIVE_MODIFY_CONTROL)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | retrieveSuccessfulOperationElements(modifyOperation); |
| | | } |
| | |
| | | "displayName: Test User", |
| | | "userPassword: password"); |
| | | |
| | | List<RawModification> mods = newRawModifications(DELETE, "description"); |
| | | |
| | | List<Control> requestControls = new ArrayList<>(); |
| | | requestControls.add( |
| | | new LDAPControl(ServerConstants.OID_PERMISSIVE_MODIFY_CONTROL, false)); |
| | | |
| | | ModifyOperation modifyOperation = processModify("uid=test.user," + baseDN, |
| | | mods, requestControls); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest("uid=test.user," + baseDN) |
| | | .addModification(DELETE, "description") |
| | | .addControl(newControl(OID_PERMISSIVE_MODIFY_CONTROL)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | retrieveSuccessfulOperationElements(modifyOperation); |
| | | } |
| | |
| | | "objectClass: top", "objectClass: person", |
| | | "objectClass: organizationalPerson", "sn: User", "cn: Test User"); |
| | | |
| | | // First check that adding "dc" fails because it is not allowed by |
| | | // inetOrgPerson. |
| | | List<RawModification> mods = newRawModifications(ADD, "dc", "foo"); |
| | | |
| | | ModifyOperation modifyOperation = processModify("cn=Test User," + baseDN, mods); |
| | | // First check that adding "dc" fails because it is not allowed by inetOrgPerson. |
| | | RawModification mod = newRawModification(ADD, "dc", "foo"); |
| | | ModifyOperation modifyOperation = processModify("cn=Test User," + baseDN, mod); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.OBJECTCLASS_VIOLATION); |
| | | |
| | | int res = applyModifications( |
| | |
| | | try |
| | | { |
| | | // Modify existing entry. |
| | | modifyOperation = processModify("cn=Test User," + baseDN, mods); |
| | | modifyOperation = processModify("cn=Test User," + baseDN, mod); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | // Add new entry and modify. |
| | |
| | | "objectClass: top", "objectClass: person", |
| | | "objectClass: organizationalPerson", "sn: User2", "cn: Test User2"); |
| | | |
| | | modifyOperation = processModify("cn=Test User2," + baseDN, mods); |
| | | modifyOperation = processModify("cn=Test User2," + baseDN, mod); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | finally |
| | |
| | | "objectClass: top", "objectClass: person", |
| | | "objectClass: organizationalPerson", "sn: User3", "cn: Test User3"); |
| | | |
| | | modifyOperation = processModify("cn=Test User3," + baseDN, mods); |
| | | modifyOperation = processModify("cn=Test User3," + baseDN, mod); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.OBJECTCLASS_VIOLATION); |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.core; |
| | | |
| | | |
| | | |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | import org.testng.annotations.Test; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.types.*; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.UnbindRequestProtocolOp; |
| | | import org.opends.server.tools.*; |
| | | import static org.testng.Assert.*; |
| | | import org.opends.server.tools.LDAPAuthenticationHandler; |
| | | import org.opends.server.tools.LDAPCompare; |
| | | import org.opends.server.tools.LDAPDelete; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import com.forgerock.opendj.cli.ClientException; |
| | | |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * A set of testcases for configuration attribute |
| | | * "ds-cfg-reject-unauthenticated-requests". |
| | | */ |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class RejectUnauthReqTests extends CoreTestCase |
| | | { |
| | | private class Args |
| | | { |
| | | private final List<String> args = new ArrayList<>(); |
| | | |
| | | public void add(String arg) |
| | | { |
| | | args.add(arg); |
| | | } |
| | | |
| | | public void add(String arg, Object value) |
| | | { |
| | | args.add(arg); |
| | | args.add(value.toString()); |
| | | } |
| | | |
| | | public String[] toArray() |
| | | { |
| | | return args.toArray(new String[args.size()]); |
| | | } |
| | | |
| | | @Override |
| | | public String toString() |
| | | { |
| | | return args.toString(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Utility method which is called by the testcase sending an ADD |
| | | * request. |
| | | * Utility method which is called by the testcase sending an ADD request. |
| | | * |
| | | * @param authentication |
| | | * @param authenticate |
| | | * The flag to set the authentication on and off. |
| | | * @return The error code of operation performed. |
| | | * @throws Exception |
| | | * If an unexpected problem occurs. |
| | | */ |
| | | private int performAddOperation(boolean authentication) throws Exception |
| | | private int performAddOperation(boolean authenticate) throws Exception |
| | | { |
| | | String filePath = TestCaseUtils.createTempFile( |
| | | "dn: o=rejectTestCase,o=test", "objectclass: top", |
| | | "objectclass: organization", "o: rejectTestCase", |
| | | "description: Reject Test Case"); |
| | | String[] args = null; |
| | | if (authentication) |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=directory manager", |
| | | "-w", |
| | | "password", |
| | | "-a", |
| | | "-f", |
| | | filePath, |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-a", |
| | | "-f", |
| | | filePath, |
| | | }; |
| | | } |
| | | return LDAPModify.mainModify(args, false, null, null); |
| | | return LDAPModify.mainModify(addArgs(authenticate, filePath), false, null, null); |
| | | } |
| | | |
| | | private String[] modifyArgs(boolean authenticate, String filePath) |
| | | { |
| | | return args(authenticate, false, filePath); |
| | | } |
| | | |
| | | private String[] addArgs(boolean authenticate, String filePath) |
| | | { |
| | | return args(authenticate, true, filePath); |
| | | } |
| | | |
| | | private String[] args(boolean authenticate, boolean add, String filePath) |
| | | { |
| | | Args args = new Args(); |
| | | args.add("--noPropertiesFile"); |
| | | args.add("-h", "127.0.0.1"); |
| | | args.add("-p", TestCaseUtils.getServerLdapPort()); |
| | | if (authenticate) |
| | | { |
| | | args.add("-D", "cn=directory manager"); |
| | | args.add("-w", "password"); |
| | | } |
| | | if (add) |
| | | { |
| | | args.add("-a"); |
| | | } |
| | | args.add("-f", filePath); |
| | | return args.toArray(); |
| | | } |
| | | |
| | | /** |
| | | * Utility method which is called by the testcase sending a MODIFY |
| | | * request. |
| | | * Utility method which is called by the testcase sending a MODIFY request. |
| | | * |
| | | * @param authentication |
| | | * @param authenticate |
| | | * The flag to set the authentication on and off. |
| | | * @return The error code of operation performed. |
| | | * @throws Exception |
| | | * If an unexpected problem occurs. |
| | | */ |
| | | private int performModifyOperation(boolean authentication) throws Exception |
| | | private int performModifyOperation(boolean authenticate) throws Exception |
| | | { |
| | | String path = TestCaseUtils.createTempFile("dn: o=rejectTestCase,o=test", |
| | | "changetype: modify", "replace: description", |
| | | "description: New Description"); |
| | | String[] args = null; |
| | | if (authentication) |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=directory manager", |
| | | "-w", |
| | | "password", |
| | | "-f", |
| | | path |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-f", |
| | | path |
| | | }; |
| | | } |
| | | return LDAPModify.mainModify(args, false, null, null); |
| | | return LDAPModify.mainModify(modifyArgs(authenticate, path), false, null, null); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | private int performCompareOperation(boolean authentication) throws Exception |
| | | { |
| | | String[] args = null; |
| | | if (authentication) |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=Directory Manager", |
| | | "-w", |
| | | "password", |
| | | "o:test", |
| | | "o=test" |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "o:test", |
| | | "o=test" |
| | | }; |
| | | } |
| | | |
| | | return LDAPCompare.mainCompare(args, false, null, null); |
| | | return LDAPCompare.mainCompare(compareArgs(authentication), false, null, null); |
| | | } |
| | | |
| | | |
| | | private String[] compareArgs(boolean authenticate) |
| | | { |
| | | Args args = new Args(); |
| | | args.add("--noPropertiesFile"); |
| | | args.add("-h", "127.0.0.1"); |
| | | args.add("-p", TestCaseUtils.getServerLdapPort()); |
| | | if (authenticate) |
| | | { |
| | | args.add("-D", "cn=Directory Manager"); |
| | | args.add("-w", "password"); |
| | | } |
| | | args.add("o:test", "o=test"); |
| | | return args.toArray(); |
| | | } |
| | | |
| | | /** |
| | | * Utility method which is called by the testcase sending a MODRDN |
| | |
| | | String path = TestCaseUtils |
| | | .createTempFile("dn: o=rejectTestCase,o=Test", "changetype: modrdn", |
| | | "newrdn: o=mod_rejectTestCase", "deleteoldrdn: 0"); |
| | | String[] args = null; |
| | | if (authentication) |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=directory manager", |
| | | "-w", |
| | | "password", |
| | | "-f", |
| | | path |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-f", |
| | | path |
| | | }; |
| | | } |
| | | return LDAPModify.mainModify(args, false, null, null); |
| | | return LDAPModify.mainModify(modRdnArgs(authentication, path), false, null, null); |
| | | } |
| | | |
| | | |
| | | private String[] modRdnArgs(boolean authenticate, String path) |
| | | { |
| | | Args args = new Args(); |
| | | args.add("--noPropertiesFile"); |
| | | args.add("-h", "127.0.0.1"); |
| | | args.add("-p", TestCaseUtils.getServerLdapPort()); |
| | | if (authenticate) |
| | | { |
| | | args.add("-D", "cn=directory manager"); |
| | | args.add("-w", "password"); |
| | | } |
| | | args.add("-f", path); |
| | | return args.toArray(); |
| | | } |
| | | |
| | | /** |
| | | * Utility method which is called by the testcase sending a DELETE |
| | |
| | | */ |
| | | private int performDeleteOperation(boolean authentication) throws Exception |
| | | { |
| | | String[] args = null; |
| | | if (authentication) |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-V", |
| | | "3", |
| | | "-D", |
| | | "cn=Directory Manager", |
| | | "-w", |
| | | "password", |
| | | "o=mod_rejectTestCase,o=test" |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | args = new String[] |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "o=mod_rejectTestCase,o=test" |
| | | }; |
| | | } |
| | | return LDAPDelete.mainDelete(args, false, null, null); |
| | | return LDAPDelete.mainDelete(deleteArgs(authentication), false, null, null); |
| | | } |
| | | |
| | | |
| | | private String[] deleteArgs(boolean authenticate) |
| | | { |
| | | Args args = new Args(); |
| | | args.add("--noPropertiesFile"); |
| | | args.add("-h", "127.0.0.1"); |
| | | args.add("-p", TestCaseUtils.getServerLdapPort()); |
| | | if (authenticate) |
| | | { |
| | | args.add("-V", "3"); |
| | | args.add("-D", "cn=Directory Manager"); |
| | | args.add("-w", "password"); |
| | | } |
| | | args.add("o=mod_rejectTestCase,o=test"); |
| | | return args.toArray(); |
| | | } |
| | | |
| | | /** |
| | | * Ensures that the Directory Server is running before executing the |
| | |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | } |
| | | |
| | | private enum Auth |
| | | { |
| | | ANONYMOUS, SIMPLE, START_TLS |
| | | } |
| | | |
| | | private String[] searchArgs(Auth auth) |
| | | { |
| | | Args args = new Args(); |
| | | args.add("--noPropertiesFile"); |
| | | args.add("-h", "127.0.0.1"); |
| | | args.add("-p", TestCaseUtils.getServerLdapPort()); |
| | | if (!Auth.ANONYMOUS.equals(auth)) |
| | | { |
| | | args.add("-D", "cn=Directory Manager"); |
| | | args.add("-w", "password"); |
| | | } |
| | | if (Auth.START_TLS.equals(auth)) |
| | | { |
| | | args.add("-q"); |
| | | args.add("-X"); |
| | | } |
| | | args.add("-b", ""); |
| | | args.add("-s", "base"); |
| | | args.add("(objectClass=*)"); |
| | | return args.toArray(); |
| | | } |
| | | |
| | | /** |
| | | * Tests whether an authenticated SEARCH request will be allowed |
| | | * with the default configuration settings for |
| | | * "ds-cfg-reject-unauthenticated-requests". |
| | | * Tests whether an authenticated SEARCH request will be allowed with the default configuration |
| | | * settings for "ds-cfg-reject-unauthenticated-requests". |
| | | */ |
| | | @Test |
| | | public void testAuthSearchDefCfg() |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | String[] args = |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=Directory Manager", |
| | | "-w", |
| | | "password", |
| | | "-b", |
| | | "", |
| | | "-s", |
| | | "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0); |
| | | assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.SIMPLE), false, null, System.err), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests whether an unauthenticated SEARCH request will be allowed |
| | | * with the default configuration settings for |
| | | * "ds-cfg-reject-unauthenticated-requests". |
| | | * Tests whether an unauthenticated SEARCH request will be allowed with the default configuration |
| | | * settings for "ds-cfg-reject-unauthenticated-requests". |
| | | */ |
| | | @Test |
| | | public void testUnauthSearchDefCfg() |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | String[] args = |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-b", |
| | | "", |
| | | "-s", |
| | | "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0); |
| | | assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.ANONYMOUS), false, null, System.err), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests whether an authenticated BIND request will be allowed with |
| | | * the default configuration settings for |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | InternalClientConnection conn = new InternalClientConnection( |
| | | new AuthenticationInfo()); |
| | | InternalClientConnection conn = new InternalClientConnection(new AuthenticationInfo()); |
| | | ByteString user = ByteString.valueOfUtf8("cn=Directory Manager"); |
| | | ByteString password = ByteString.valueOfUtf8("password"); |
| | | BindOperation bindOperation = conn.processSimpleBind(user, password); |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | InternalClientConnection conn = new InternalClientConnection( |
| | | new AuthenticationInfo()); |
| | | InternalClientConnection conn = new InternalClientConnection(new AuthenticationInfo()); |
| | | BindOperation bindOperation = conn.processSimpleBind(DN.rootDN(), null); |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | ByteString.valueOfUtf8("password"), new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | | |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = new LDAPAuthenticationHandler( |
| | | reader, writer, "localhost", nextMessageID); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | ByteString.valueOfUtf8("password"), new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNotNull(authzID); |
| | | |
| | | LDAPMessage unbindMessage = new LDAPMessage( |
| | | nextMessageID.getAndIncrement(), new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(unbindMessage); |
| | | s.close(); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = new LDAPAuthenticationHandler( |
| | | reader, writer, "localhost", nextMessageID); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNull(authzID); |
| | | |
| | | LDAPMessage unbindMessage = new LDAPMessage( |
| | | nextMessageID.getAndIncrement(), new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(unbindMessage); |
| | | s.close(); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | assertNull(authHandler.requestAuthorizationIdentity()); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public void testStartTLSUnauthDefCfg() throws Exception |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | String[] argSearch = |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=directory manager", |
| | | "-w", |
| | | "password", |
| | | "-q", |
| | | "-X", |
| | | "-b", |
| | | "", |
| | | "-s", |
| | | "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | assertEquals(LDAPSearch.mainSearch(argSearch, false, null, System.err), 0); |
| | | assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.START_TLS), false, null, System.err), 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the whether the authenticated ADD,MODIFY,COMPARE,MODRDN and |
| | | * DELETE requests succeed with the default configuration settings. |
| | |
| | | DirectoryServer.setRejectUnauthenticatedRequests(false); |
| | | |
| | | assertEquals(performAddOperation(true), 0); |
| | | |
| | | assertEquals(performModifyOperation(true), 0); |
| | | |
| | | assertEquals(performCompareOperation(true), 0); |
| | | |
| | | assertEquals(performModRdnOperation(true), 0); |
| | | |
| | | assertEquals(performDeleteOperation(true), 0); |
| | | } |
| | | |
| | |
| | | public void testOtherOpsUnauthDefCfg() throws Exception |
| | | { |
| | | assertEquals(performAddOperation(false), 0); |
| | | |
| | | assertEquals(performModifyOperation(false), 0); |
| | | |
| | | assertEquals(performCompareOperation(false), 0); |
| | | |
| | | assertEquals(performModRdnOperation(false), 0); |
| | | |
| | | assertEquals(performDeleteOperation(false), 0); |
| | | } |
| | | |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(true); |
| | | |
| | | String[] args = |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-b", |
| | | "", |
| | | "-s", |
| | | "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0); |
| | | |
| | | String[] authArgs = |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=Directory Manager", |
| | | "-w", |
| | | "password", |
| | | "-b", |
| | | "", |
| | | "-s", |
| | | "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | assertEquals(LDAPSearch.mainSearch(authArgs, false, null, System.err), 0); |
| | | assertFalse(LDAPSearch.mainSearch(searchArgs(Auth.ANONYMOUS), false, null, null) == 0); |
| | | assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.START_TLS), false, null, System.err), 0); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests whether authenticated and unauthenticated BIND requests |
| | | * will be allowed with the new configuration settings for |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(true); |
| | | |
| | | InternalClientConnection conn = new InternalClientConnection( |
| | | new AuthenticationInfo()); |
| | | InternalClientConnection conn = new InternalClientConnection(new AuthenticationInfo()); |
| | | ByteString user = ByteString.valueOfUtf8("cn=Directory Manager"); |
| | | ByteString password = ByteString.valueOfUtf8("password"); |
| | | // Unauthenticated BIND request. |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(true); |
| | | |
| | | String[] argSearch = |
| | | { |
| | | "--noPropertiesFile", |
| | | "-h", |
| | | "127.0.0.1", |
| | | "-p", |
| | | String.valueOf(TestCaseUtils.getServerLdapPort()), |
| | | "-D", |
| | | "cn=directory manager", |
| | | "-w", |
| | | "password", |
| | | "-q", |
| | | "-X", |
| | | "-b", |
| | | "", |
| | | "-s", |
| | | "base", |
| | | "(objectClass=*)" |
| | | }; |
| | | assertEquals(LDAPSearch.mainSearch(argSearch, false, null, System.err), 0); |
| | | assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.START_TLS), false, null, System.err), 0); |
| | | } |
| | | finally |
| | | { |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(true); |
| | | |
| | | InternalClientConnection conn = InternalClientConnection |
| | | .getRootConnection(); |
| | | ExtendedOperation extOp = conn.processExtendedOperation( |
| | | OID_WHO_AM_I_REQUEST, null); |
| | | ExtendedOperation extOp = getRootConnection().processExtendedOperation(OID_WHO_AM_I_REQUEST, null); |
| | | assertEquals(extOp.getResultCode(), ResultCode.SUCCESS); |
| | | assertNotNull(extOp.getResponseValue()); |
| | | } |
| | |
| | | * Tests whether the who am I? extended operation with an |
| | | * unauthenticated connection fails with new setting of |
| | | * "ds-cfg-reject-unauthenticated-requests". |
| | | * |
| | | * @throws UnsupportedEncodingException |
| | | * If an unexpected problem occurs. |
| | | * @throws IOException |
| | | * If an unexpected problem occurs. |
| | | * @throws ClientException |
| | | * If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testUnauthWAINewCfg() throws UnsupportedEncodingException, |
| | | IOException, ClientException |
| | | public void testUnauthWAINewCfg() throws Exception |
| | | { |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(true); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = new LDAPAuthenticationHandler( |
| | | reader, writer, "localhost", nextMessageID); |
| | | ByteString authzID = null; |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | try |
| | | { |
| | | authzID = authHandler.requestAuthorizationIdentity(); |
| | | authHandler.requestAuthorizationIdentity(); |
| | | fail(); |
| | | } |
| | | catch (LDAPException e) |
| | | catch (LDAPException expected) |
| | | { |
| | | assertNull(authzID); |
| | | } |
| | | finally |
| | | { |
| | | LDAPMessage unbindMessage = new LDAPMessage(nextMessageID |
| | | .getAndIncrement(), new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(unbindMessage); |
| | | s.close(); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | finally |
| | |
| | | DirectoryServer.setRejectUnauthenticatedRequests(true); |
| | | |
| | | assertEquals(performAddOperation(true), 0); |
| | | |
| | | assertEquals(performModifyOperation(true), 0); |
| | | |
| | | assertEquals(performCompareOperation(true), 0); |
| | | |
| | | assertEquals(performModRdnOperation(true), 0); |
| | | |
| | | assertEquals(performDeleteOperation(true), 0); |
| | | } |
| | | finally |
| | |
| | | { |
| | | DirectoryServer.setRejectUnauthenticatedRequests(true); |
| | | |
| | | assertFalse(performAddOperation(false) == 0); |
| | | |
| | | assertFalse(performModifyOperation(false) == 0); |
| | | |
| | | assertFalse(performCompareOperation(false) == 0); |
| | | |
| | | assertFalse(performModRdnOperation(false) == 0); |
| | | |
| | | assertFalse(performDeleteOperation(false) == 0); |
| | | assertNotEquals(performAddOperation(false), 0); |
| | | assertNotEquals(performModifyOperation(false), 0); |
| | | assertNotEquals(performCompareOperation(false), 0); |
| | | assertNotEquals(performModRdnOperation(false), 0); |
| | | assertNotEquals(performDeleteOperation(false), 0); |
| | | } |
| | | finally |
| | | { |
| | |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.Requests; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.BindResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPConstants; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | |
| | | assertTrue(DirectoryServer.getWorkQueue().waitUntilIdle(10000)); |
| | | |
| | | InvocationCounterPlugin.resetAllCounters(); |
| | | LDAPMessage message = conn.bind("cn=Directory Manager", "password"); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | } |
| | | |
| | | @Test |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2015 ForgeRock AS. |
| | | * Portions Copyright 2012-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.io.IOException; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.io.ASN1; |
| | | import org.forgerock.opendj.io.ASN1Writer; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.plugins.DelayPreOpPlugin; |
| | | import org.opends.server.protocols.ldap.AddRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.AddResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.CompareRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.CompareResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.DeleteRequestProtocolOp; |
| | |
| | | import org.opends.server.protocols.ldap.ModifyResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.SearchRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.SearchResultDoneProtocolOp; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.types.RawModification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.protocols.ldap.LDAPConstants.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * A set of test cases for the cancel extended operation handler. |
| | | */ |
| | | /** A set of test cases for the cancel extended operation handler. */ |
| | | public class CancelExtendedOperationTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass |
| | | public void startServer() |
| | | throws Exception |
| | | public void startServer() throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | } |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelAddOperation() |
| | | throws Exception |
| | | public void testCancelAddOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create an add request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | ArrayList<RawAttribute> attributes = new ArrayList<>(); |
| | | attributes.add(new LDAPAttribute("objectClass", newArrayList("top", "organizationalUnit"))); |
| | | attributes.add(new LDAPAttribute("ou", "People")); |
| | | |
| | | AddRequestProtocolOp addRequest = |
| | | new AddRequestProtocolOp(ByteString.valueOfUtf8("ou=People,o=test"), attributes); |
| | | message = new LDAPMessage(2, addRequest, |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read two response messages from the server. One should be an add |
| | | // response and the other should be an extended response. |
| | | for (int i=0; i < 2; i++) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | message = r.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case OP_TYPE_ADD_RESPONSE: |
| | | AddResponseProtocolOp addResponse = |
| | | message.getAddResponseProtocolOp(); |
| | | assertEquals(addResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | break; |
| | | case OP_TYPE_EXTENDED_RESPONSE: |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | socket.close(); |
| | | // Create an add request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | List<RawAttribute> attributes = newArrayList( |
| | | newRawAttribute("objectClass", "top", "organizationalUnit"), |
| | | newRawAttribute("ou", "People")); |
| | | AddRequestProtocolOp addRequest = |
| | | new AddRequestProtocolOp(ByteString.valueOfUtf8("ou=People,o=test"), attributes); |
| | | conn.writeMessage(addRequest, DelayPreOpPlugin.createDelayControlList(5000)); |
| | | |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | |
| | | assertEquals(getCancelledResponseMessageType(conn), OP_TYPE_ADD_RESPONSE); |
| | | } |
| | | } |
| | | |
| | | |
| | | private RawAttribute newRawAttribute(String attrName, String... attrValues) |
| | | { |
| | | return new LDAPAttribute(attrName, newArrayList(attrValues)); |
| | | } |
| | | |
| | | /** |
| | | * Tests the ability to cancel a compare operation. |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelCompareOperation() |
| | | throws Exception |
| | | public void testCancelCompareOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a compare request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | CompareRequestProtocolOp compareRequest = |
| | | new CompareRequestProtocolOp(ByteString.valueOfUtf8("o=test"), "o", |
| | | ByteString.valueOfUtf8("test")); |
| | | message = new LDAPMessage(2, compareRequest, |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read two response messages from the server. One should be a compare |
| | | // response and the other should be an extended response. |
| | | for (int i=0; i < 2; i++) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | message = r.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case OP_TYPE_COMPARE_RESPONSE: |
| | | CompareResponseProtocolOp compareResponse = |
| | | message.getCompareResponseProtocolOp(); |
| | | assertEquals(compareResponse.getResultCode(), |
| | | LDAPResultCode.CANCELED); |
| | | break; |
| | | case OP_TYPE_EXTENDED_RESPONSE: |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | socket.close(); |
| | | // Create a compare request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | CompareRequestProtocolOp compareRequest = |
| | | new CompareRequestProtocolOp(ByteString.valueOfUtf8("o=test"), "o", ByteString.valueOfUtf8("test")); |
| | | conn.writeMessage(compareRequest, DelayPreOpPlugin.createDelayControlList(5000)); |
| | | |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | |
| | | assertEquals(getCancelledResponseMessageType(conn), OP_TYPE_COMPARE_RESPONSE); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelDeleteOperation() |
| | | throws Exception |
| | | public void testCancelDeleteOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | // Add an entry to the server that we can delete. |
| | |
| | | "objectClass: device", |
| | | "cn: test"); |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a delete request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | DeleteRequestProtocolOp deleteRequest = |
| | | new DeleteRequestProtocolOp(ByteString.valueOfUtf8("cn=test,o=test")); |
| | | message = new LDAPMessage(2, deleteRequest, |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read two response messages from the server. One should be a delete |
| | | // response and the other should be an extended response. |
| | | for (int i=0; i < 2; i++) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | message = r.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case OP_TYPE_DELETE_RESPONSE: |
| | | DeleteResponseProtocolOp deleteResponse = |
| | | message.getDeleteResponseProtocolOp(); |
| | | assertEquals(deleteResponse.getResultCode(), |
| | | LDAPResultCode.CANCELED); |
| | | break; |
| | | case OP_TYPE_EXTENDED_RESPONSE: |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | socket.close(); |
| | | // Create a delete request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | DeleteRequestProtocolOp deleteRequest = |
| | | new DeleteRequestProtocolOp(ByteString.valueOfUtf8("cn=test,o=test")); |
| | | conn.writeMessage(deleteRequest, DelayPreOpPlugin.createDelayControlList(5000)); |
| | | |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | |
| | | assertEquals(getCancelledResponseMessageType(conn), OP_TYPE_DELETE_RESPONSE); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelExtendedOperation() |
| | | throws Exception |
| | | public void testCancelExtendedOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | // Create a "Who Am I?" extended operation and send it to the server. Make |
| | | // sure to include the delay request control so it won't complete before we |
| | | // can send the cancel request. |
| | | ExtendedRequestProtocolOp whoAmIRequest = new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST, null); |
| | | conn.writeMessage(whoAmIRequest, DelayPreOpPlugin.createDelayControlList(5000)); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | // Read two response messages from the server. They should both be extended |
| | | // responses, one with the result code CANCELED and one with SUCCESS. |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | |
| | | |
| | | // Create a "Who Am I?" extended operation and send it to the server. Make |
| | | // sure to include the delay request control so it won't complete before we |
| | | // can send the cancel request. |
| | | ExtendedRequestProtocolOp whoAmIRequest = |
| | | new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST, null); |
| | | message = new LDAPMessage(2, whoAmIRequest, |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read two response messages from the server. They should both be extended |
| | | // responses, one with the result code CANCELED and one with SUCCESS. |
| | | message = r.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | |
| | | message = r.readMessage(); |
| | | extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | socket.close(); |
| | | message = conn.readMessage(); |
| | | extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelModifyOperation() |
| | | throws Exception |
| | | public void testCancelModifyOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | // Create a modify request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | List<RawModification> mods = newArrayList( |
| | | (RawModification) new LDAPModification(REPLACE, new LDAPAttribute("description", "foo"))); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | conn.writeMessage( |
| | | new ModifyRequestProtocolOp(ByteString.valueOfUtf8("o=test"), mods), |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | // Create a cancel request and send it to the server. |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | |
| | | assertEquals(getCancelledResponseMessageType(conn), OP_TYPE_MODIFY_RESPONSE); |
| | | } |
| | | } |
| | | |
| | | // Create a modify request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | ArrayList<RawModification> mods = new ArrayList<>(1); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, |
| | | new LDAPAttribute("description", "foo"))); |
| | | private ExtendedRequestProtocolOp cancelRequestExtendedOp(int messageNb) throws IOException |
| | | { |
| | | return new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, cancelRequest(messageNb)); |
| | | } |
| | | |
| | | ModifyRequestProtocolOp modifyRequest = |
| | | new ModifyRequestProtocolOp(ByteString.valueOfUtf8("o=test"), mods); |
| | | message = new LDAPMessage(2, modifyRequest, |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | private ByteString cancelRequest(int messageNb) throws IOException |
| | | { |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeInteger(messageNb); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read two response messages from the server. One should be a modify |
| | | // response and the other should be an extended response. |
| | | for (int i=0; i < 2; i++) |
| | | { |
| | | message = r.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case OP_TYPE_MODIFY_RESPONSE: |
| | | ModifyResponseProtocolOp modifyResponse = |
| | | message.getModifyResponseProtocolOp(); |
| | | assertEquals(modifyResponse.getResultCode(), |
| | | LDAPResultCode.CANCELED); |
| | | break; |
| | | case OP_TYPE_EXTENDED_RESPONSE: |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | |
| | | socket.close(); |
| | | return builder.toByteString(); |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelModifyDNOperation() |
| | | throws Exception |
| | | public void testCancelModifyDNOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | // Add an entry to the server that we can rename. |
| | |
| | | "objectClass: device", |
| | | "cn: test"); |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a modify DN request and send it to the server. Make sure to |
| | | // include the delay request control so it won't complete before we can send |
| | | // the cancel request. |
| | | ModifyDNRequestProtocolOp modifyDNRequest = |
| | | new ModifyDNRequestProtocolOp(ByteString.valueOfUtf8("cn=test,o=test"), |
| | | ByteString.valueOfUtf8("cn=test2"), true); |
| | | message = new LDAPMessage(2, modifyDNRequest, |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read two response messages from the server. One should be a modify DN |
| | | // response and the other should be an extended response. |
| | | for (int i=0; i < 2; i++) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | message = r.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case OP_TYPE_MODIFY_DN_RESPONSE: |
| | | ModifyDNResponseProtocolOp modifyDNResponse = |
| | | message.getModifyDNResponseProtocolOp(); |
| | | assertEquals(modifyDNResponse.getResultCode(), |
| | | LDAPResultCode.CANCELED); |
| | | break; |
| | | case OP_TYPE_EXTENDED_RESPONSE: |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | socket.close(); |
| | | // Create a modify DN request and send it to the server. Make sure to |
| | | // include the delay request control so it won't complete before we can send |
| | | // the cancel request. |
| | | ModifyDNRequestProtocolOp modifyDNRequest = new ModifyDNRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=test,o=test"), ByteString.valueOfUtf8("cn=test2"), true); |
| | | conn.writeMessage(modifyDNRequest, DelayPreOpPlugin.createDelayControlList(5000)); |
| | | |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | |
| | | assertEquals(getCancelledResponseMessageType(conn), OP_TYPE_MODIFY_DN_RESPONSE); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | private byte getCancelledResponseMessageType(RemoteConnection conn) throws IOException, LDAPException |
| | | { |
| | | boolean cancelSuccessful = false; |
| | | byte cancelledMessageType = 0; |
| | | |
| | | for (int i = 0; i < 2; i++) |
| | | { |
| | | LDAPMessage message = conn.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case OP_TYPE_ADD_RESPONSE: |
| | | AddResponseProtocolOp addResponse = message.getAddResponseProtocolOp(); |
| | | assertEquals(addResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | cancelledMessageType = OP_TYPE_ADD_RESPONSE; |
| | | break; |
| | | case OP_TYPE_MODIFY_RESPONSE: |
| | | ModifyResponseProtocolOp modifyResponse = message.getModifyResponseProtocolOp(); |
| | | assertEquals(modifyResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | cancelledMessageType = OP_TYPE_MODIFY_RESPONSE; |
| | | break; |
| | | case OP_TYPE_MODIFY_DN_RESPONSE: |
| | | ModifyDNResponseProtocolOp modifyDNResponse = message.getModifyDNResponseProtocolOp(); |
| | | assertEquals(modifyDNResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | cancelledMessageType = OP_TYPE_MODIFY_DN_RESPONSE; |
| | | break; |
| | | case OP_TYPE_DELETE_RESPONSE: |
| | | DeleteResponseProtocolOp deleteResponse = message.getDeleteResponseProtocolOp(); |
| | | assertEquals(deleteResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | cancelledMessageType = OP_TYPE_DELETE_RESPONSE; |
| | | break; |
| | | case OP_TYPE_SEARCH_RESULT_DONE: |
| | | SearchResultDoneProtocolOp searchResultDone = message.getSearchResultDoneProtocolOp(); |
| | | assertEquals(searchResultDone.getResultCode(), LDAPResultCode.CANCELED); |
| | | cancelledMessageType = OP_TYPE_SEARCH_RESULT_DONE; |
| | | break; |
| | | case OP_TYPE_COMPARE_RESPONSE: |
| | | CompareResponseProtocolOp compareResponse = message.getCompareResponseProtocolOp(); |
| | | assertEquals(compareResponse.getResultCode(), LDAPResultCode.CANCELED); |
| | | cancelledMessageType = OP_TYPE_COMPARE_RESPONSE; |
| | | break; |
| | | |
| | | case OP_TYPE_EXTENDED_RESPONSE: |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | cancelSuccessful = true; |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | |
| | | assertTrue(cancelSuccessful); |
| | | return cancelledMessageType; |
| | | } |
| | | |
| | | /** |
| | | * Tests the ability to cancel a search operation. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelSearchOperation() |
| | | throws Exception |
| | | public void testCancelSearchOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a search request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | SearchRequestProtocolOp searchRequest = |
| | | new SearchRequestProtocolOp(ByteString.valueOfUtf8("o=test"), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, |
| | | LDAPFilter.decode("(match=false)"), |
| | | new LinkedHashSet<String>()); |
| | | message = new LDAPMessage(2, searchRequest, |
| | | DelayPreOpPlugin.createDelayControlList(5000)); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read two response messages from the server. One should be a search |
| | | // result done and the other should be an extended response. |
| | | for (int i=0; i < 2; i++) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | message = r.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case OP_TYPE_SEARCH_RESULT_DONE: |
| | | SearchResultDoneProtocolOp searchResultDone = |
| | | message.getSearchResultDoneProtocolOp(); |
| | | assertEquals(searchResultDone.getResultCode(), |
| | | LDAPResultCode.CANCELED); |
| | | break; |
| | | case OP_TYPE_EXTENDED_RESPONSE: |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | socket.close(); |
| | | // Create a search request and send it to the server. Make sure to include |
| | | // the delay request control so it won't complete before we can send the |
| | | // cancel request. |
| | | SearchRequestProtocolOp searchRequest = |
| | | new SearchRequestProtocolOp(ByteString.valueOfUtf8("o=test"), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, |
| | | LDAPFilter.decode("(match=false)"), |
| | | new LinkedHashSet<String>()); |
| | | conn.writeMessage(searchRequest, DelayPreOpPlugin.createDelayControlList(5000)); |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | assertEquals(getCancelledResponseMessageType(conn), OP_TYPE_SEARCH_RESULT_DONE); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelNoSuchOperation() |
| | | throws Exception |
| | | public void testCancelNoSuchOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | ExtendedRequestProtocolOp extendedRequest = cancelRequestExtendedOp(2); |
| | | conn.getLdapWriter().writeMessage(new LDAPMessage(3, extendedRequest)); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read the response message from the server. It should be an extended |
| | | // response with a result code of "no such operation". |
| | | message = r.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.NO_SUCH_OPERATION); |
| | | |
| | | socket.close(); |
| | | // Read the response message from the server. It should be an extended |
| | | // response with a result code of "no such operation". |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.NO_SUCH_OPERATION); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelNoValue() |
| | | throws Exception |
| | | public void testCancelNoValue() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | // Create a cancel request and send it to the server. |
| | | ExtendedRequestProtocolOp extendedRequest = new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, null); |
| | | conn.writeMessage(extendedRequest); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, null); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read the response message from the server. It should be an extended |
| | | // response with a result code of "no such operation". |
| | | message = r.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.PROTOCOL_ERROR); |
| | | |
| | | socket.close(); |
| | | // Read the response message from the server. It should be an extended |
| | | // response with a result code of "no such operation". |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelMalformedValue() |
| | | throws Exception |
| | | public void testCancelMalformedValue() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | // Create a cancel request and send it to the server. |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, ByteString.valueOfUtf8("malformed")); |
| | | conn.writeMessage(extendedRequest); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a cancel request and send it to the server. |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | ByteString.valueOfUtf8("malformed")); |
| | | message = new LDAPMessage(3, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | |
| | | // Read the response message from the server. It should be an extended |
| | | // response with a result code of "no such operation". |
| | | message = r.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.PROTOCOL_ERROR); |
| | | |
| | | socket.close(); |
| | | // Read the response message from the server. It should be an extended |
| | | // response with a result code of "no such operation". |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testCancelCancelExtendedOperation() |
| | | throws Exception |
| | | public void testCancelCancelExtendedOperation() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | // Create a new connection to the Directory Server and authenticate as |
| | | // the Directory Manager. |
| | | Socket socket = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(socket); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(socket); |
| | | conn.writeMessage(cancelRequestExtendedOp(2)); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | |
| | | // Create a self cancelling request and send it to the server. Make sure |
| | | // to include the delay request control so it won't complete before we |
| | | // can send the cancel request. |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(builder); |
| | | writer.writeStartSequence(); |
| | | writer.writeInteger(2); |
| | | writer.writeEndSequence(); |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST, |
| | | builder.toByteString()); |
| | | message = new LDAPMessage(2, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.CANNOT_CANCEL); |
| | | |
| | | socket.close(); |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.CANNOT_CANCEL); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.controls.AssertionRequestControl; |
| | | import org.forgerock.opendj.ldap.controls.PostReadRequestControl; |
| | | import org.forgerock.opendj.ldap.controls.PreReadRequestControl; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | |
| | | import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn.Scope; |
| | | import org.opends.server.admin.std.server.EntityTagVirtualAttributeCfg; |
| | | import org.opends.server.admin.std.server.VirtualAttributeCfg; |
| | | import org.opends.server.controls.LDAPAssertionRequestControl; |
| | | import org.opends.server.controls.LDAPPostReadRequestControl; |
| | | import org.opends.server.controls.LDAPPostReadResponseControl; |
| | | import org.opends.server.controls.LDAPPreReadRequestControl; |
| | | import org.opends.server.controls.LDAPPreReadResponseControl; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.Requests; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPFilter; |
| | | import org.opends.server.types.Attribute; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.VirtualAttributeRule; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static java.util.Collections.*; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.mockito.Mockito.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | |
| | | Entry e1 = readEntry(userDN); |
| | | String etag1 = e1.parseAttribute(ETAG).asString(); |
| | | assertNotNull(etag1); |
| | | AssertionRequestControl ctrl = AssertionRequestControl.newControl(true, Filter.equality(ETAG, etag1)); |
| | | |
| | | // Apply a change using the assertion control for optimistic concurrency. |
| | | Attribute attr = Attributes.create(DESCRIPTION, "first modify"); |
| | | List<Modification> mods = newArrayList(new Modification(ModificationType.REPLACE, attr)); |
| | | Control c = new LDAPAssertionRequestControl(true, LDAPFilter.createEqualityFilter(ETAG, ByteString.valueOfUtf8(etag1))); |
| | | List<Control> ctrls = Collections.singletonList(c); |
| | | ModifyOperation modifyOperation = conn.processModify(userDN, mods, ctrls); |
| | | ModifyRequest modifyRequest = newModifyRequest(from(userDN)) |
| | | .addModification(REPLACE, DESCRIPTION, "first modify") |
| | | .addControl(ctrl); |
| | | ModifyOperation modifyOperation = conn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | // Reread the entry and check that the description has been added and that |
| | |
| | | assertNotNull(etag2); |
| | | assertFalse(etag1.equals(etag2)); |
| | | |
| | | String description2 = e2.parseAttribute(DESCRIPTION).asString(); |
| | | assertNotNull(description2); |
| | | assertEquals(description2, "first modify"); |
| | | String description2 = assertDescriptionValue(e2, "first modify"); |
| | | |
| | | // Simulate a concurrent update: perform another update using the old etag. |
| | | Attribute attr2 = Attributes.create(DESCRIPTION, "second modify"); |
| | | mods = newArrayList(new Modification(ModificationType.REPLACE, attr2)); |
| | | modifyOperation = conn.processModify(userDN, mods, ctrls); |
| | | modifyRequest = newModifyRequest(from(userDN)) |
| | | .addModification(REPLACE, DESCRIPTION, "second modify") |
| | | .addControl(ctrl); |
| | | modifyOperation = conn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.ASSERTION_FAILED); |
| | | |
| | | // Reread the entry and check that the description and etag have not changed |
| | |
| | | assertNotNull(etag3); |
| | | assertEquals(etag2, etag3); |
| | | |
| | | String description3 = e3.parseAttribute(DESCRIPTION).asString(); |
| | | assertNotNull(description3); |
| | | assertEquals(description3, description2); |
| | | assertDescriptionValue(e3, description2); |
| | | } |
| | | |
| | | /** |
| | |
| | | assertNotNull(etag1); |
| | | |
| | | // Apply a change using the pre and post read controls. |
| | | Attribute attr = Attributes.create(DESCRIPTION, "modified value"); |
| | | List<Modification> mods = newArrayList(new Modification(ModificationType.REPLACE, attr)); |
| | | List<Control> ctrls = singletonList((Control) new LDAPPreReadRequestControl(true, singleton(ETAG))); |
| | | ModifyOperation modifyOperation = conn.processModify(userDN, mods, ctrls); |
| | | ModifyRequest modifyRequest = newModifyRequest(from(userDN)) |
| | | .addModification(REPLACE, DESCRIPTION, "modified value") |
| | | .addControl(PreReadRequestControl.newControl(true, ETAG)); |
| | | ModifyOperation modifyOperation = conn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | // Reread the entry and check that the description has been added and that |
| | |
| | | assertNotNull(etag2); |
| | | assertFalse(etag1.equals(etag2)); |
| | | |
| | | String description2 = e2.parseAttribute(DESCRIPTION).asString(); |
| | | assertNotNull(description2); |
| | | assertEquals(description2, "modified value"); |
| | | assertDescriptionValue(e2, "modified value"); |
| | | |
| | | // Now check that the pre-read is the same as the initial etag. |
| | | LDAPPreReadResponseControl preReadControl = getLDAPPreReadResponseControl(modifyOperation); |
| | |
| | | assertEquals(etagPreRead, etag1); |
| | | } |
| | | |
| | | private String assertDescriptionValue(Entry entry, String expected) |
| | | { |
| | | String description = entry.parseAttribute(DESCRIPTION).asString(); |
| | | assertNotNull(description); |
| | | assertEquals(description, expected); |
| | | return description; |
| | | } |
| | | |
| | | /** |
| | | * Tests that the etag returned with a post-read control after a modify |
| | | * operation is correct. See OPENDJ-861. |
| | |
| | | assertNotNull(etag1); |
| | | |
| | | // Apply a change using the pre and post read controls. |
| | | Attribute attr = Attributes.create(DESCRIPTION, "modified value"); |
| | | List<Modification> mods = newArrayList(new Modification(ModificationType.REPLACE, attr)); |
| | | List<Control> ctrls = singletonList((Control) new LDAPPostReadRequestControl(true, singleton(ETAG))); |
| | | ModifyOperation modifyOperation = conn.processModify(userDN, mods, ctrls); |
| | | ModifyRequest modifyRequest = newModifyRequest(from(userDN)) |
| | | .addModification(REPLACE, DESCRIPTION, "modified value") |
| | | .addControl(PostReadRequestControl.newControl(true, ETAG)); |
| | | ModifyOperation modifyOperation = conn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | // Reread the entry and check that the description has been added and that |
| | |
| | | assertNotNull(etag2); |
| | | assertFalse(etag1.equals(etag2)); |
| | | |
| | | String description2 = e2.parseAttribute(DESCRIPTION).asString(); |
| | | assertNotNull(description2); |
| | | assertEquals(description2, "modified value"); |
| | | assertDescriptionValue(e2, "modified value"); |
| | | |
| | | // Now check that the post-read is the same as the initial etag. |
| | | LDAPPostReadResponseControl postReadControl = getLDAPPostReadResponseControl(modifyOperation); |
| | |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | | import org.opends.server.admin.std.meta.ExactMatchIdentityMapperCfgDefn; |
| | |
| | | import org.opends.server.api.IdentityMapper; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * A set of test cases for the exact match identity mapper. |
| | | */ |
| | | /** A set of test cases for the exact match identity mapper. */ |
| | | public class ExactMatchIdentityMapperTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | private static final String MAPPER_DN = "cn=Exact Match,cn=Identity Mappers,cn=config"; |
| | | |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | |
| | | public void testMapperEnabled() |
| | | throws Exception |
| | | { |
| | | DN mapperDN = DN.valueOf("cn=Exact Match,cn=Identity Mappers,cn=config"); |
| | | DN mapperDN = DN.valueOf(MAPPER_DN); |
| | | IdentityMapper mapper = DirectoryServer.getIdentityMapper(mapperDN); |
| | | assertNotNull(mapper); |
| | | assertTrue(mapper instanceof ExactMatchIdentityMapper); |
| | |
| | | public void testChangingMapAttribute() |
| | | throws Exception |
| | | { |
| | | String mapperDNString = "cn=Exact Match,cn=Identity Mappers,cn=config"; |
| | | DN mapperDN = DN.valueOf(mapperDNString); |
| | | DN mapperDN = DN.valueOf(MAPPER_DN); |
| | | IdentityMapper mapper = DirectoryServer.getIdentityMapper(mapperDN); |
| | | assertNotNull(mapper); |
| | | assertTrue(mapper instanceof ExactMatchIdentityMapper); |
| | |
| | | assertNull(mappedEntry); |
| | | |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | // Create a modification to change the map attribute from uid to cn. |
| | | ArrayList<ByteString> values = newArrayList(ByteString.valueOfUtf8("cn")); |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, |
| | | new LDAPAttribute("ds-cfg-match-attribute", |
| | | values))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ModifyRequest modifyRequest = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-attribute", "cn"); |
| | | processModifyIsSuccessful(modifyRequest); |
| | | |
| | | // Verify that "test" no longer works but "test user" does. |
| | | mappedEntry = mapper.getEntryForID("test"); |
| | |
| | | |
| | | |
| | | // Change the configuration back to the way it was. |
| | | values.set(0, ByteString.valueOfUtf8("uid")); |
| | | modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | ModifyRequest modifyRequest2 = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-attribute", "uid"); |
| | | processModifyIsSuccessful(modifyRequest2); |
| | | |
| | | |
| | | // Verify that the original matching pattern is back. |
| | |
| | | public void testChangingMapBaseDN() |
| | | throws Exception |
| | | { |
| | | String mapperDNString = "cn=Exact Match,cn=Identity Mappers,cn=config"; |
| | | DN mapperDN = DN.valueOf(mapperDNString); |
| | | DN mapperDN = DN.valueOf(MAPPER_DN); |
| | | IdentityMapper mapper = DirectoryServer.getIdentityMapper(mapperDN); |
| | | assertNotNull(mapper); |
| | | assertTrue(mapper instanceof ExactMatchIdentityMapper); |
| | |
| | | assertEquals(mappedEntry.getName(), DN.valueOf("uid=test,o=test")); |
| | | |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | // Create a modification to set the map base DN to "dc=example,dc=com". |
| | | ArrayList<ByteString> values = newArrayList(ByteString.valueOfUtf8("dc=example,dc=com")); |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, |
| | | new LDAPAttribute("ds-cfg-match-base-dn", |
| | | values))); |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | ModifyRequest modifyRequest = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-base-dn", "dc=example,dc=com"); |
| | | processModifyIsSuccessful(modifyRequest); |
| | | |
| | | |
| | | // Verify that we can't find the user anymore. |
| | |
| | | |
| | | |
| | | // Change the base DN to "o=test". |
| | | values.set(0, ByteString.valueOfUtf8("o=test")); |
| | | modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | modifyRequest = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-base-dn", "o=test"); |
| | | processModifyIsSuccessful(modifyRequest); |
| | | |
| | | |
| | | // Verify that we can retrieve the user again. |
| | |
| | | |
| | | |
| | | // Change the configuration back to its original setting. |
| | | values.clear(); |
| | | modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | modifyRequest = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-base-dn"); |
| | | processModifyIsSuccessful(modifyRequest); |
| | | |
| | | |
| | | // Verify that we can still retrieve the user. |
| | |
| | | assertEquals(mappedEntry.getName(), DN.valueOf("uid=test,o=test")); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests that an internal modification to remove the match attribute will be |
| | | * rejected. |
| | |
| | | throws Exception |
| | | { |
| | | // Create a modification to remove the match attribute. |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, |
| | | new LDAPAttribute("ds-cfg-match-attribute"))); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | String mapperDNString = "cn=Exact Match,cn=Identity Mappers,cn=config"; |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | ModifyRequest modifyRequest = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-attribute"); |
| | | processModifyIsNotSuccessful(modifyRequest); |
| | | } |
| | | |
| | | |
| | |
| | | throws Exception |
| | | { |
| | | // Create a modification to remove the match attribute. |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, |
| | | new LDAPAttribute("ds-cfg-match-attribute", "undefinedAttribute"))); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | String mapperDNString = "cn=Exact Match,cn=Identity Mappers,cn=config"; |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | ModifyRequest modifyRequest = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-attribute", "undefinedAttribute"); |
| | | processModifyIsNotSuccessful(modifyRequest); |
| | | } |
| | | |
| | | |
| | |
| | | throws Exception |
| | | { |
| | | // Create a modification to remove the match attribute. |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, |
| | | new LDAPAttribute("ds-cfg-match-base-dn", "invalidDN"))); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | String mapperDNString = "cn=Exact Match,cn=Identity Mappers,cn=config"; |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(ByteString.valueOfUtf8(mapperDNString), mods); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | ModifyRequest modifyRequest = newModifyRequest(MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-match-base-dn", "invalidDN"); |
| | | processModifyIsNotSuccessful(modifyRequest); |
| | | } |
| | | |
| | | private void processModifyIsSuccessful(ModifyRequest modifyRequest) |
| | | { |
| | | ModifyOperation op = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(op.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | private void processModifyIsNotSuccessful(ModifyRequest modifyRequest) |
| | | { |
| | | ModifyOperation op = getRootConnection().processModify(modifyRequest); |
| | | assertNotSame(op.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2015 ForgeRock AS. |
| | | * Portions Copyright 2012-2016 ForgeRock AS. |
| | | */ |
| | | 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.opends.server.protocols.ldap.BindRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.tools.LDAPReader; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.tools.LDAPWriter; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.writeMessage(new BindRequestProtocolOp(ByteString.empty(), "EXTERNAL", null)); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.empty(), "EXTERNAL", null); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | |
| | | message = reader.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertFalse(bindResponse.getResultCode() == 0); |
| | | |
| | | s.close(); |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertFalse(bindResponse.getResultCode() == 0); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | package org.opends.server.extensions; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | | import org.opends.server.admin.std.meta.FingerprintCertificateMapperCfgDefn; |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.Modification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | |
| | | public class FingerprintCertificateMapperTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | private static final String FINGERPRINT_MAPPER_DN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config"; |
| | | |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | |
| | | @Test |
| | | public void testRemoveFingerprintAttribute() throws Exception |
| | | { |
| | | String mapperDN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute a = Attributes.empty(DirectoryServer.getAttributeType("ds-cfg-fingerprint-attribute")); |
| | | |
| | | ArrayList<Modification> mods = newArrayList(new Modification(DELETE, a)); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | delete(FINGERPRINT_MAPPER_DN, "ds-cfg-fingerprint-attribute"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that an attempt to remove the fingerprint algorithm will fail. |
| | | * |
| | |
| | | @Test |
| | | public void testRemoveFingerprintAlgorithm() throws Exception |
| | | { |
| | | String mapperDN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute a = Attributes.empty(DirectoryServer.getAttributeType("ds-cfg-fingerprint-algorithm")); |
| | | |
| | | ArrayList<Modification> mods = newArrayList(new Modification(DELETE, a)); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | delete(FINGERPRINT_MAPPER_DN, "ds-cfg-fingerprint-algorithm"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that an attmept to set an undefined fingerprint attribute |
| | | * will fail. |
| | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that an attmept to set an invalid base DN will fail. |
| | | * Tests to ensure that an attempt to set an invalid base DN will fail. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(expectedExceptions = { AssertionError.class }) |
| | | public void testSetInvalidBaseDN() |
| | | throws Exception |
| | | @Test |
| | | public void testSetInvalidBaseDN() throws Exception |
| | | { |
| | | setBaseDNs(new String[] { "invalid" }); |
| | | ModifyRequest modifyRequest = newModifyRequest(FINGERPRINT_MAPPER_DN) |
| | | .addModification(REPLACE, "ds-cfg-user-base-dn", "invalid"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.INVALID_ATTRIBUTE_SYNTAX); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void enableMapper() |
| | | throws Exception |
| | | private void enableMapper() throws Exception |
| | | { |
| | | String externalDN = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String mapperDN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config"; |
| | | |
| | | ArrayList<Modification> mods = newArrayList( |
| | | new Modification(REPLACE, Attributes.create("ds-cfg-certificate-mapper", mapperDN))); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(externalDN), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | replace("cn=EXTERNAL,cn=SASL Mechanisms,cn=config", "ds-cfg-certificate-mapper", FINGERPRINT_MAPPER_DN); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void disableMapper() |
| | | throws Exception |
| | | private void disableMapper() throws Exception |
| | | { |
| | | String externalDN = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String mapperDN = "cn=Subject Equals DN,cn=Certificate Mappers,cn=config"; |
| | | |
| | | ArrayList<Modification> mods = newArrayList( |
| | | new Modification(REPLACE, Attributes.create("ds-cfg-certificate-mapper", mapperDN))); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(externalDN), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | replace("cn=EXTERNAL,cn=SASL Mechanisms,cn=config", "ds-cfg-certificate-mapper", mapperDN); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void setFingerprintAttribute(String attrName) |
| | | throws Exception |
| | | private void setFingerprintAttribute(String attrName) throws Exception |
| | | { |
| | | String mapperDN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config"; |
| | | replace(FINGERPRINT_MAPPER_DN, "ds-cfg-fingerprint-attribute", attrName); |
| | | } |
| | | |
| | | ArrayList<Modification> mods = newArrayList( |
| | | new Modification(REPLACE, Attributes.create("ds-cfg-fingerprint-attribute", attrName))); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | private void replace(String mapperDN, String attrName, String attrValues) throws DirectoryException |
| | | { |
| | | ModifyRequest modifyRequest = newModifyRequest(mapperDN).addModification(REPLACE, attrName, attrValues); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | |
| | | private void delete(String mapperDN, String attrName) throws DirectoryException |
| | | { |
| | | ModifyRequest modifyRequest = newModifyRequest(mapperDN).addModification(DELETE, attrName); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | /** |
| | | * Alters the configuration of the fingerprint certificate mapper so that it |
| | |
| | | private void setFingerprintAlgorithm(String algorithm) |
| | | throws Exception |
| | | { |
| | | String mapperDN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config"; |
| | | |
| | | ArrayList<Modification> mods = newArrayList( |
| | | new Modification(REPLACE, Attributes.create("ds-cfg-fingerprint-algorithm", algorithm))); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Alters the configuration of the Subject DN to User Attribute certificate |
| | | * mapper so that it will look for the subject DN below the specified set of |
| | | * base DNs. |
| | | * |
| | | * @param baseDNs The set of base DNs to use when mapping certificates to |
| | | * users. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void setBaseDNs(String[] baseDNs) |
| | | throws Exception |
| | | { |
| | | String mapperDN = "cn=Fingerprint Mapper,cn=Certificate Mappers,cn=config"; |
| | | |
| | | ArrayList<Modification> mods = newArrayList( |
| | | new Modification(REPLACE, Attributes.create("ds-cfg-user-base-dn", baseDNs))); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | replace(FINGERPRINT_MAPPER_DN, "ds-cfg-fingerprint-algorithm", algorithm); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.forgerock.opendj.io.ASN1Writer; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.tools.LDAPPasswordModify; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.Modification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.extensions.ExtensionsConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | |
| | | |
| | | String dnStr = "cn=Default Password Policy,cn=Password Policies,cn=config"; |
| | | String attr = "ds-cfg-password-generator"; |
| | | applyPwdPolicyMods(dnStr, attr, null); |
| | | applyPwdPolicyMods(dnStr, attr); |
| | | |
| | | |
| | | String[] args = |
| | |
| | | |
| | | String dnStr = "cn=Default Password Policy,cn=Password Policies,cn=config"; |
| | | String attr = "ds-cfg-password-generator"; |
| | | applyPwdPolicyMods(dnStr, attr, null); |
| | | applyPwdPolicyMods(dnStr, attr); |
| | | |
| | | String[] args = |
| | | { |
| | |
| | | assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null)); |
| | | } |
| | | finally { |
| | | applyPwdPolicyMods(dnStr, attr, null); |
| | | applyPwdPolicyMods(dnStr, attr); |
| | | } |
| | | } |
| | | |
| | |
| | | assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null)); |
| | | } |
| | | finally { |
| | | applyPwdPolicyMods(dnStr, attr, null); |
| | | applyPwdPolicyMods(dnStr, attr); |
| | | } |
| | | } |
| | | |
| | |
| | | assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | private void applyPwdPolicyMods(String pwPolDN, String attr, String value) |
| | | private void applyPwdPolicyMods(String pwpDN, String attrName, Object... attrValues) |
| | | throws DirectoryException |
| | | { |
| | | List<Modification> mods = newModifications(REPLACE, attr, value); |
| | | ModifyOperation op = getRootConnection().processModify(DN.valueOf(pwPolDN), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(pwpDN) |
| | | .addModification(REPLACE, attrName, attrValues); |
| | | ModifyOperation op = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(op.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | private void setPasswordChangedTime(Entry userEntry) { |
| | | List<Modification> mods = newModifications(REPLACE, "pwdchangedtime", "20050101000000.000Z"); |
| | | ModifyOperation op = getRootConnection().processModify(userEntry.getName(), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(from(userEntry.getName())) |
| | | .addModification(REPLACE, "pwdchangedtime", "20050101000000.000Z"); |
| | | ModifyOperation op = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(op.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | private List<Modification> newModifications(ModificationType modType, String attrName, String attrValue) |
| | | { |
| | | return newArrayList(new Modification(modType, |
| | | attrValue == null ? Attributes.empty(attrName) : Attributes.create(attrName, attrValue))); |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2010-2015 ForgeRock AS. |
| | | * Portions Copyright 2010-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.api.PasswordStorageScheme; |
| | | import org.opends.server.config.ConfigEntry; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.PasswordPolicy; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.schema.AuthPasswordSyntax; |
| | | import org.opends.server.schema.UserPasswordSyntax; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** A set of generic test cases for password storage schemes. */ |
| | |
| | | { |
| | | // This code was borrowed from |
| | | // PasswordPolicyTestCase.testAllowPreEncodedPasswordsAuth |
| | | boolean previousValue = false; |
| | | try { |
| | | DN dn = DN.valueOf("cn=Default Password Policy,cn=Password Policies,cn=config"); |
| | | PasswordPolicy p = (PasswordPolicy) DirectoryServer.getAuthenticationPolicy(dn); |
| | | previousValue = p.isAllowPreEncodedPasswords(); |
| | | final boolean previousValue = p.isAllowPreEncodedPasswords(); |
| | | |
| | | String attr = "ds-cfg-allow-pre-encoded-passwords"; |
| | | |
| | | ArrayList<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create(attr, String.valueOf(allowPreencoded)))); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyOperation modifyOperation = conn.processModify(dn, mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest("cn=Default Password Policy,cn=Password Policies,cn=config") |
| | | .addModification(REPLACE, "ds-cfg-allow-pre-encoded-passwords", allowPreencoded); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | p = (PasswordPolicy) DirectoryServer.getAuthenticationPolicy(dn); |
| | | assertEquals(p.isAllowPreEncodedPasswords(), allowPreencoded); |
| | | return previousValue; |
| | | } catch (Exception e) { |
| | | System.err.println("Failed to set ds-cfg-allow-pre-encoded-passwords " + |
| | | " to " + allowPreencoded); |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | |
| | | return previousValue; |
| | | } |
| | | |
| | | protected static void testAuthPasswords(final String upperName, |
| | |
| | | package org.opends.server.extensions; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | | import org.opends.server.admin.std.meta.SubjectAttributeToUserAttributeCertificateMapperCfgDefn; |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.Modification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | |
| | | { |
| | | String mapperDN = "cn=Subject Attribute to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute a = Attributes.empty(DirectoryServer.getAttributeType("ds-cfg-subject-attribute-mapping")); |
| | | |
| | | ArrayList<Modification> mods = newArrayList( |
| | | new Modification(ModificationType.DELETE, a)); |
| | | |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | ModifyRequest modifyRequest = |
| | | newModifyRequest(mapperDN).addModification(DELETE, "ds-cfg-subject-attribute-mapping"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | String mapperDN = "cn=Subject Attribute to User Attribute," + |
| | | "cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute attr = Attributes.create("ds-cfg-certificate-mapper", mapperDN); |
| | | assertModifyReplaceIsSuccess(externalDN, attr); |
| | | assertModifyReplaceIsSuccess(externalDN, "ds-cfg-certificate-mapper", mapperDN); |
| | | } |
| | | |
| | | /** |
| | |
| | | String externalDN = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String mapperDN = "cn=Subject Equals DN,cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute attr = Attributes.create("ds-cfg-certificate-mapper", mapperDN); |
| | | assertModifyReplaceIsSuccess(externalDN, attr); |
| | | assertModifyReplaceIsSuccess(externalDN, "ds-cfg-certificate-mapper", mapperDN); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void setAttributeMappings(String... mappings) throws Exception |
| | | private void setAttributeMappings(Object... mappings) throws Exception |
| | | { |
| | | String mapperDN = "cn=Subject Attribute to User Attribute," + |
| | | "cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute attr = Attributes.create("ds-cfg-subject-attribute-mapping", mappings); |
| | | assertModifyReplaceIsSuccess(mapperDN, attr); |
| | | assertModifyReplaceIsSuccess(mapperDN, "ds-cfg-subject-attribute-mapping", mappings); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void setBaseDNs(String... baseDNs) throws Exception |
| | | private void setBaseDNs(Object... baseDNs) throws Exception |
| | | { |
| | | String mapperDN = "cn=Subject Attribute to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | |
| | | AttributeType attrType = DirectoryServer.getAttributeType("ds-cfg-user-base-dn"); |
| | | AttributeBuilder builder = new AttributeBuilder(attrType); |
| | | if (baseDNs != null) |
| | | { |
| | | builder.addAllStrings(Arrays.asList(baseDNs)); |
| | | } |
| | | |
| | | assertModifyReplaceIsSuccess(mapperDN, builder.toAttribute()); |
| | | assertModifyReplaceIsSuccess(mapperDN, "ds-cfg-user-base-dn", baseDNs); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | private void assertModifyReplaceIsSuccess(String dn, Attribute replaceAttr) throws DirectoryException |
| | | private void assertModifyReplaceIsSuccess(String dn, String attrName, Object... attrValues) throws DirectoryException |
| | | { |
| | | ArrayList<Modification> mods = newArrayList(new Modification(REPLACE, replaceAttr)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(DN.valueOf(dn), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest(dn); |
| | | if (attrValues != null) |
| | | { |
| | | modifyRequest.addModification(REPLACE, attrName, attrValues); |
| | | } |
| | | else |
| | | { |
| | | modifyRequest.addModification(REPLACE, attrName); |
| | | } |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | package org.opends.server.extensions; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | | import org.opends.server.admin.std.meta.SubjectDNToUserAttributeCertificateMapperCfgDefn; |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.Modification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | |
| | | throws Exception |
| | | { |
| | | String mapperDN = "cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | Attribute a = Attributes.empty(DirectoryServer.getAttributeType("ds-cfg-subject-attribute")); |
| | | |
| | | ArrayList<Modification> mods = newArrayList(new Modification(ModificationType.DELETE, a)); |
| | | ModifyOperation modifyOperation = |
| | | getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest(mapperDN) |
| | | .addModification(DELETE, "ds-cfg-subject-attribute"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertNotSame(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | throws Exception |
| | | { |
| | | String externalDN = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String mapperDN = |
| | | "cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | String mapperDN = "cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute attr = Attributes.create("ds-cfg-certificate-mapper", mapperDN); |
| | | assertModifyReplaceIsSuccess(externalDN, attr); |
| | | assertModifyReplaceIsSuccess(externalDN, "ds-cfg-certificate-mapper", mapperDN); |
| | | } |
| | | |
| | | |
| | |
| | | String externalDN = "cn=EXTERNAL,cn=SASL Mechanisms,cn=config"; |
| | | String mapperDN = "cn=Subject Equals DN,cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute attr = Attributes.create("ds-cfg-certificate-mapper", mapperDN); |
| | | assertModifyReplaceIsSuccess(externalDN, attr); |
| | | assertModifyReplaceIsSuccess(externalDN, "ds-cfg-certificate-mapper", mapperDN); |
| | | } |
| | | |
| | | |
| | |
| | | private void setSubjectAttribute(String attrName) |
| | | throws Exception |
| | | { |
| | | String mapperDN = |
| | | "cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | String mapperDN = "cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | |
| | | Attribute attr = Attributes.create("ds-cfg-subject-attribute", attrName); |
| | | assertModifyReplaceIsSuccess(mapperDN, attr); |
| | | assertModifyReplaceIsSuccess(mapperDN, "ds-cfg-subject-attribute", attrName); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void setBaseDNs(String[] baseDNs) throws Exception |
| | | private void setBaseDNs(Object[] baseDNs) throws Exception |
| | | { |
| | | String mapperDN = "cn=Subject DN to User Attribute,cn=Certificate Mappers,cn=config"; |
| | | |
| | | AttributeType attrType = DirectoryServer.getAttributeType("ds-cfg-user-base-dn"); |
| | | AttributeBuilder builder = new AttributeBuilder(attrType); |
| | | if (baseDNs != null) |
| | | { |
| | | builder.addAllStrings(Arrays.asList(baseDNs)); |
| | | } |
| | | |
| | | assertModifyReplaceIsSuccess(mapperDN, builder.toAttribute()); |
| | | assertModifyReplaceIsSuccess(mapperDN, "ds-cfg-user-base-dn", baseDNs); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | private void assertModifyReplaceIsSuccess(String mapperDN, Attribute attr) throws DirectoryException |
| | | private void assertModifyReplaceIsSuccess(String mapperDN, String attrName, Object... attrValues) |
| | | throws DirectoryException |
| | | { |
| | | ArrayList<Modification> mods = newArrayList(new Modification(REPLACE, attr)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(DN.valueOf(mapperDN), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest(mapperDN); |
| | | if (attrValues != null) |
| | | { |
| | | modifyRequest.addModification(REPLACE, attrName, attrValues); |
| | | } |
| | | else |
| | | { |
| | | modifyRequest.addModification(REPLACE, attrName); |
| | | } |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.opends.server.protocols.ldap.UnbindRequestProtocolOp; |
| | | import org.opends.server.tools.LDAPAuthenticationHandler; |
| | | import org.opends.server.tools.LDAPReader; |
| | | import org.opends.server.tools.LDAPWriter; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.forgerock.opendj.cli.ClientException; |
| | | |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | |
| | | public void testAsLDAPRootUser() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | doSimpleBind(authHandler, "cn=Directory Manager", "password"); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | | |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = |
| | | new LDAPAuthenticationHandler(reader, writer, "localhost", |
| | | nextMessageID); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | ByteString.valueOfUtf8("password"), |
| | | new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNotNull(authzID); |
| | | |
| | | LDAPMessage unbindMessage = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(unbindMessage); |
| | | s.close(); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the use of the Who Am I? extended operation with an unauthenticated |
| | | * LDAP connection. |
| | |
| | | public void testAsLDAPAnonymous() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = |
| | | new LDAPAuthenticationHandler(reader, writer, "localhost", |
| | | nextMessageID); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNull(authzID); |
| | | |
| | | LDAPMessage unbindMessage = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(unbindMessage); |
| | | s.close(); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | assertNull(authHandler.requestAuthorizationIdentity()); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | "userPassword: password"); |
| | | |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = |
| | | new LDAPAuthenticationHandler(reader, writer, "localhost", |
| | | nextMessageID); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("uid=test.user,o=test"), |
| | | ByteString.valueOfUtf8("password"), |
| | | new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNotNull(authzID); |
| | | doSimpleBind(authHandler, "uid=test.user,o=test", "password"); |
| | | assertNotNull(authHandler.requestAuthorizationIdentity()); |
| | | |
| | | LDAPMessage unbindMessage = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(unbindMessage); |
| | | s.close(); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | "ds-privilege-name: bypass-acl", |
| | | "ds-privilege-name: proxied-auth"); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | // Bind as the proxy user with an alternate authorization identity, and use |
| | | // the "Who Am I?" operation. |
| | | HashMap<String,List<String>> saslProperties = new HashMap<>(2); |
| | | saslProperties.put("authID", newArrayList("dn:uid=proxy.user,o=test")); |
| | | saslProperties.put("authzID", newArrayList("dn:uid=test.user,o=test")); |
| | | |
| | | authHandler.doSASLPlain(ByteString.empty(), |
| | | ByteString.valueOfUtf8("password"), saslProperties, |
| | | new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | assertAuthzID(authHandler.requestAuthorizationIdentity(), "dn:uid=test.user,o=test"); |
| | | |
| | | // Bind as the proxy user with an alternate authorization identity, and use |
| | | // the "Who Am I?" operation. |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = |
| | | new LDAPAuthenticationHandler(reader, writer, "localhost", |
| | | nextMessageID); |
| | | |
| | | HashMap<String,List<String>> saslProperties = new HashMap<>(2); |
| | | saslProperties.put("authID", newArrayList("dn:uid=proxy.user,o=test")); |
| | | saslProperties.put("authzID", newArrayList("dn:uid=test.user,o=test")); |
| | | |
| | | authHandler.doSASLPlain(ByteString.empty(), |
| | | ByteString.valueOfUtf8("password"), saslProperties, |
| | | new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNotNull(authzID); |
| | | assertEquals(authzID.toString(), "dn:uid=test.user,o=test"); |
| | | |
| | | |
| | | // Close the connection to the server. |
| | | LDAPMessage unbindMessage = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(unbindMessage); |
| | | s.close(); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | "ds-privilege-name: bypass-acl", |
| | | "ds-privilege-name: proxied-auth"); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | // Bind as the proxy user and use the "Who Am I?" operation, but without the |
| | | // proxied auth control. |
| | | doSimpleBind(authHandler, "uid=proxy.user,o=test", "password"); |
| | | assertAuthzID(authHandler.requestAuthorizationIdentity(), "dn:uid=proxy.user,o=test"); |
| | | |
| | | // Use the "Who Am I?" operation again, this time with the proxy control. |
| | | conn.writeMessage( |
| | | new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST), |
| | | new ProxiedAuthV2Control(ByteString.valueOfUtf8("dn:uid=test.user,o=test"))); |
| | | |
| | | // Bind as the proxy user and use the "Who Am I?" operation, but without the |
| | | // proxied auth control. |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = |
| | | new LDAPAuthenticationHandler(reader, writer, "localhost", |
| | | nextMessageID); |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8("uid=proxy.user,o=test"), |
| | | ByteString.valueOfUtf8("password"), |
| | | new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNotNull(authzID); |
| | | assertEquals(authzID.toString(), "dn:uid=proxy.user,o=test"); |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | assertAuthzID(extendedResponse.getValue(), "dn:uid=test.user,o=test"); |
| | | |
| | | |
| | | // Use the "Who Am I?" operation again, this time with the proxy control. |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST); |
| | | ArrayList<Control> requestControls = new ArrayList<>(1); |
| | | requestControls.add(new ProxiedAuthV2Control( |
| | | ByteString.valueOfUtf8("dn:uid=test.user,o=test"))); |
| | | LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | extendedRequest, requestControls); |
| | | writer.writeMessage(message); |
| | | |
| | | message = reader.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | authzID = extendedResponse.getValue(); |
| | | assertNotNull(authzID); |
| | | assertEquals(authzID.toString(), "dn:uid=test.user,o=test"); |
| | | |
| | | |
| | | // Close the connection to the server. |
| | | message = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(message); |
| | | s.close(); |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void assertAuthzID(ByteString authzID, String expected) |
| | | { |
| | | assertNotNull(authzID); |
| | | assertEquals(authzID.toString(), expected); |
| | | } |
| | | |
| | | /** |
| | | * Tests the use of the Who Am I? extended operation in conjunction with the |
| | |
| | | "userPassword: password", |
| | | "ds-privilege-name: bypass-acl"); |
| | | |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | LDAPAuthenticationHandler authHandler = conn.newLDAPAuthenticationHandler(); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | LDAPReader reader = new LDAPReader(s); |
| | | LDAPWriter writer = new LDAPWriter(s); |
| | | // Bind as the proxy user and use the "Who Am I?" operation, but without the |
| | | // proxied auth control. |
| | | doSimpleBind(authHandler, "uid=cantproxy.user,o=test", "password"); |
| | | assertAuthzID(authHandler.requestAuthorizationIdentity(), "dn:uid=cantproxy.user,o=test"); |
| | | |
| | | // Use the "Who Am I?" operation again, this time with the proxy control. |
| | | conn.writeMessage( |
| | | new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST), |
| | | new ProxiedAuthV2Control(ByteString.valueOfUtf8("dn:uid=test.user,o=test"))); |
| | | |
| | | // Bind as the proxy user and use the "Who Am I?" operation, but without the |
| | | // proxied auth control. |
| | | AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | LDAPAuthenticationHandler authHandler = |
| | | new LDAPAuthenticationHandler(reader, writer, "localhost", |
| | | nextMessageID); |
| | | authHandler.doSimpleBind(3, |
| | | ByteString.valueOfUtf8("uid=cantproxy.user,o=test"), |
| | | ByteString.valueOfUtf8("password"), |
| | | new ArrayList<Control>(), |
| | | new ArrayList<Control>()); |
| | | ByteString authzID = authHandler.requestAuthorizationIdentity(); |
| | | assertNotNull(authzID); |
| | | assertEquals(authzID.toString(), "dn:uid=cantproxy.user,o=test"); |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.AUTHORIZATION_DENIED); |
| | | assertNull(extendedResponse.getValue()); |
| | | |
| | | conn.unbind(); |
| | | } |
| | | } |
| | | |
| | | // Use the "Who Am I?" operation again, this time with the proxy control. |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST); |
| | | ArrayList<Control> requestControls = new ArrayList<>(1); |
| | | requestControls.add(new ProxiedAuthV2Control( |
| | | ByteString.valueOfUtf8("dn:uid=test.user,o=test"))); |
| | | LDAPMessage message = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | extendedRequest, requestControls); |
| | | writer.writeMessage(message); |
| | | |
| | | message = reader.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), |
| | | LDAPResultCode.AUTHORIZATION_DENIED); |
| | | assertNull(extendedResponse.getValue()); |
| | | |
| | | |
| | | // Close the connection to the server. |
| | | message = new LDAPMessage(nextMessageID.getAndIncrement(), |
| | | new UnbindRequestProtocolOp()); |
| | | writer.writeMessage(message); |
| | | s.close(); |
| | | private void doSimpleBind(LDAPAuthenticationHandler authHandler, String bindDn, String bindPwd) |
| | | throws ClientException, LDAPException |
| | | { |
| | | authHandler.doSimpleBind(3, ByteString.valueOfUtf8(bindDn), ByteString.valueOfUtf8(bindPwd), |
| | | new ArrayList<Control>(), new ArrayList<Control>()); |
| | | } |
| | | } |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2011 profiq s.r.o. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.plugins; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | |
| | | import org.opends.server.api.plugin.PluginType; |
| | | import org.opends.server.core.AddOperationBasis; |
| | | import org.opends.server.core.ModifyOperationBasis; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.types.RawModification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * Tests for the attribute cleanup plugin. |
| | | */ |
| | | /** Tests for the attribute cleanup plugin. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class AttributeCleanupPluginTestCase extends PluginTestCase |
| | | { |
| | |
| | | * cn: Name Surname |
| | | * sn: Surname |
| | | */ |
| | | ArrayList<ByteString> values = new ArrayList<>(); |
| | | values.add(ByteString.valueOfUtf8("top")); |
| | | values.add(ByteString.valueOfUtf8("person")); |
| | | values.add(ByteString.valueOfUtf8("organizationalperson")); |
| | | values.add(ByteString.valueOfUtf8("inetorgperson")); |
| | | AddOperationBasis addOperation = add("dn: uid=test,dc=example,dc=com", |
| | | RawAttribute.create("objectClass", toByteStrings("top", "person", "organizationalperson", "inetorgperson")), |
| | | RawAttribute.create("uid", "test"), |
| | | RawAttribute.create("cn", "Name Surname"), |
| | | RawAttribute.create("sn", "Surname")); |
| | | |
| | | List<RawAttribute> rawAttributes = new ArrayList<>(); |
| | | rawAttributes.add(RawAttribute.create("objectClass", values)); |
| | | rawAttributes.add(RawAttribute.create("uid", "test")); |
| | | rawAttributes.add(RawAttribute.create("cn", "Name Surname")); |
| | | rawAttributes.add(RawAttribute.create("sn", "Surname")); |
| | | |
| | | AddOperationBasis addOperation = |
| | | new AddOperationBasis(InternalClientConnection.getRootConnection(), |
| | | 1, |
| | | 1, |
| | | null, |
| | | ByteString.valueOfUtf8("dn: uid=test,dc=example,dc=com"), |
| | | rawAttributes); |
| | | |
| | | /* Process the operation. The processing should continue. */ |
| | | |
| | | PluginResult.PreParse res = plugin.doPreParse(addOperation); |
| | | |
| | | assertTrue(res.continueProcessing()); |
| | | |
| | | /* Verify that the 'cn' attribute has been renamed to 'description' |
| | |
| | | } |
| | | |
| | | fail(); |
| | | } |
| | | |
| | | private ArrayList<ByteString> toByteStrings(String... strings) |
| | | { |
| | | ArrayList<ByteString> results = new ArrayList<>(strings.length); |
| | | for (String s : strings) |
| | | { |
| | | results.add(ByteString.valueOfUtf8(s)); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | private AddOperationBasis add(String entryDN, RawAttribute... rawAttributes) |
| | | { |
| | | return new AddOperationBasis(getRootConnection(), 1, 1, null, |
| | | ByteString.valueOfUtf8(entryDN), Arrays.asList(rawAttributes)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * modifyTimeStamp: 2011091212400000Z |
| | | * createTimeStamp: 2011091212400000Z |
| | | */ |
| | | AddOperationBasis addOperation = add("dn: uid=test,dc=example,dc=com", |
| | | RawAttribute.create("objectClass", toByteStrings("top", "person", "organizationalperson", "inetorgperson")), |
| | | RawAttribute.create("uid", "test"), |
| | | RawAttribute.create("cn", "Name Surname"), |
| | | RawAttribute.create("sn", "Surname"), |
| | | RawAttribute.create("modifyTimeStamp", "2011091212400000Z"), |
| | | RawAttribute.create("createTimeStamp", "2011091212400000Z")); |
| | | |
| | | ArrayList<ByteString> values = new ArrayList<>(); |
| | | values.add(ByteString.valueOfUtf8("top")); |
| | | values.add(ByteString.valueOfUtf8("person")); |
| | | values.add(ByteString.valueOfUtf8("organizationalperson")); |
| | | values.add(ByteString.valueOfUtf8("inetorgperson")); |
| | | |
| | | List<RawAttribute> rawAttributes = new ArrayList<>(); |
| | | |
| | | rawAttributes.add(RawAttribute.create("objectClass", values)); |
| | | rawAttributes.add(RawAttribute.create("uid", "test")); |
| | | rawAttributes.add(RawAttribute.create("cn", "Name Surname")); |
| | | rawAttributes.add(RawAttribute.create("sn", "Surname")); |
| | | rawAttributes.add(RawAttribute.create("modifyTimeStamp", "2011091212400000Z")); |
| | | rawAttributes.add(RawAttribute.create("createTimeStamp", "2011091212400000Z")); |
| | | |
| | | AddOperationBasis addOperation = |
| | | new AddOperationBasis(InternalClientConnection.getRootConnection(), |
| | | 1, |
| | | 1, |
| | | null, |
| | | ByteString.valueOfUtf8("dn: uid=test,dc=example,dc=com"), |
| | | rawAttributes); |
| | | |
| | | /* Process the operation and expect the server to continue |
| | | * processing the operation. |
| | |
| | | * createTimeStamp: 2011091212400000Z |
| | | * - |
| | | */ |
| | | |
| | | List<RawModification> rawMods= new ArrayList<>(); |
| | | |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "modifyTimeStamp", |
| | | "2011091212400000Z")); |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "createTimeStamp", |
| | | "2011091212400000Z")); |
| | | |
| | | ModifyOperationBasis modifyOperation = |
| | | new ModifyOperationBasis(InternalClientConnection.getRootConnection(), |
| | | 1, |
| | | 1, |
| | | null, |
| | | ByteString.valueOfUtf8("dn: uid=test,dc=example,dc=com"), |
| | | rawMods); |
| | | ModifyOperationBasis modifyOperation = modify("dn: uid=test,dc=example,dc=com", |
| | | newRawModification(REPLACE, "modifyTimeStamp", "2011091212400000Z"), |
| | | newRawModification(REPLACE, "createTimeStamp", "2011091212400000Z")); |
| | | |
| | | /* Process the request. The result should be SUCCESS and the server |
| | | * should stop the processing. |
| | |
| | | |
| | | } |
| | | |
| | | private ModifyOperationBasis modify(String entryDN, RawModification... rawMods) |
| | | { |
| | | return new ModifyOperationBasis(getRootConnection(), 1, 1, null, ByteString.valueOfUtf8(entryDN), newArrayList(rawMods)); |
| | | } |
| | | |
| | | /** |
| | | * Verify the attribute renaming for a MODIFY operation. |
| | | * @throws Exception in case of a bug. |
| | |
| | | * createTimeStamp: 2011091212400000Z |
| | | * - |
| | | */ |
| | | |
| | | List<RawModification> rawMods= new ArrayList<>(); |
| | | |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "cn", |
| | | "Test User")); |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "sn", |
| | | "User")); |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "modifyTimeStamp", |
| | | "2011091212400000Z")); |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "createTimeStamp", |
| | | "2011091212400000Z")); |
| | | |
| | | ModifyOperationBasis modifyOperation = |
| | | new ModifyOperationBasis(InternalClientConnection.getRootConnection(), |
| | | 1, |
| | | 1, |
| | | null, |
| | | ByteString.valueOfUtf8("dn: uid=test,dc=example,dc=com"), |
| | | rawMods); |
| | | ModifyOperationBasis modifyOperation = modify("dn: uid=test,dc=example,dc=com", |
| | | newRawModification(REPLACE, "cn", "Test User"), |
| | | newRawModification(REPLACE, "sn", "User"), |
| | | newRawModification(REPLACE, "modifyTimeStamp", "2011091212400000Z"), |
| | | newRawModification(REPLACE, "createTimeStamp", "2011091212400000Z")); |
| | | |
| | | /* Process the MODIFY operation making sure the remaining number of |
| | | * modifications is 2 and that the '*TimeStamp' modifications are |
| | |
| | | |
| | | assertEquals(modifyOperation.getRawModifications().size(), 2); |
| | | |
| | | rawMods = modifyOperation.getRawModifications(); |
| | | List<RawModification> rawMods = modifyOperation.getRawModifications(); |
| | | assertNotNull(rawMods); |
| | | |
| | | for(RawModification rawMod : rawMods ) |
| | |
| | | |
| | | } |
| | | |
| | | private RawModification newRawModification(ModificationType modType, String attrName, String attrValue) |
| | | { |
| | | return RawModification.create(modType, attrName, attrValue); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Verify the attribute renaming for the MODIFY operation. |
| | |
| | | * replace: modifyTimeStamp |
| | | * modifyTimeStamp: 2011091212400000Z |
| | | */ |
| | | List<RawModification> rawMods= new ArrayList<>(); |
| | | |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "cn", |
| | | "Test User")); |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "sn", |
| | | "User")); |
| | | rawMods.add(RawModification.create(ModificationType.REPLACE, |
| | | "modifyTimeStamp", |
| | | "2011091212400000Z")); |
| | | |
| | | ModifyOperationBasis modifyOperation = |
| | | new ModifyOperationBasis(InternalClientConnection.getRootConnection(), |
| | | 1, |
| | | 1, |
| | | null, |
| | | ByteString.valueOfUtf8("dn: uid=test,dc=example,dc=com"), |
| | | rawMods); |
| | | ModifyOperationBasis modifyOperation = modify("dn: uid=test,dc=example,dc=com", |
| | | newRawModification(REPLACE, "cn", "Test User"), |
| | | newRawModification(REPLACE, "sn", "User"), |
| | | newRawModification(REPLACE, "modifyTimeStamp", "2011091212400000Z")); |
| | | |
| | | /* Process the MODIFY operation. */ |
| | | |
| | | PluginResult.PreParse res = plugin.doPreParse(modifyOperation); |
| | | |
| | | assertTrue(res.continueProcessing()); |
| | | |
| | | /* Verify that the attribute has been properly renamed by comparing |
| | | * the value of the attribute 'description' with the original value |
| | | * of the 'modifyTimeStamp' attribute. |
| | | */ |
| | | rawMods = modifyOperation.getRawModifications(); |
| | | |
| | | List<RawModification> rawMods = modifyOperation.getRawModifications(); |
| | | assertNotNull(rawMods); |
| | | |
| | | for(RawModification rawMod : rawMods ) |
| | | { |
| | | RawAttribute modAttr = rawMod.getAttribute(); |
| | |
| | | package org.opends.server.plugins; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.testng.annotations.AfterClass; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | |
| | | * @param attrValStrings The values to add to the entry. |
| | | */ |
| | | private ModifyOperation |
| | | addAttrEntry(DN dn, String attrName, String... attrValStrings) { |
| | | LinkedList<Modification> mods = newLinkedList( |
| | | new Modification(ADD, Attributes.create(attrName, attrValStrings))); |
| | | return getRootConnection().processModify(dn, mods); |
| | | addAttrEntry(DN dn, String attrName, Object... attrValStrings) { |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(from(dn)) |
| | | .addModification(ADD, attrName, attrValStrings); |
| | | return getRootConnection().processModify(modifyRequest); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param attrName The attribute type to replace the values in. |
| | | * @param attrValStrings The values to replace in the the entry. |
| | | */ |
| | | private ModifyOperation replaceAttrEntry(DN dn, String attrName, String... attrValStrings) { |
| | | LinkedList<Modification> mods = newLinkedList( |
| | | new Modification(REPLACE, Attributes.create(attrName, attrValStrings))); |
| | | return getRootConnection().processModify(dn, mods); |
| | | private ModifyOperation replaceAttrEntry(DN dn, String attrName, Object... attrValStrings) { |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(from(dn)) |
| | | .addModification(REPLACE, attrName, attrValStrings); |
| | | return getRootConnection().processModify(modifyRequest); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private void |
| | | deleteAttrsEntry(DN dn, String... attrTypeStrings) throws Exception { |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(from(dn)); |
| | | for(String attrTypeString : attrTypeStrings) { |
| | | AttributeType attrType = getAttributeType(attrTypeString); |
| | | mods.add(new Modification(ModificationType.DELETE, |
| | | Attributes.empty(attrType))); |
| | | modifyRequest.addModification(DELETE, attrTypeString); |
| | | } |
| | | getRootConnection().processModify(dn, mods); |
| | | getRootConnection().processModify(modifyRequest); |
| | | } |
| | | |
| | | private void deleteEntries(String... dns) throws Exception{ |
| | |
| | | package org.opends.server.plugins; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ExtendedOperation; |
| | |
| | | * Samba administrative user needs a permission to manipulate user accounts. |
| | | * Hence, we add a very permissive ACI. |
| | | */ |
| | | LinkedList<Modification> mods = |
| | | newLinkedList(new Modification(ModificationType.ADD, Attributes.create("aci", |
| | | "(target=\"ldap:///uid=*,o=test\")(targetattr=\"*\")" |
| | | + "(version 3.0; acl \"Samba admin\"; allow (all) " |
| | | + "userdn=\"ldap:///cn=samba admin,o=test\";)"))); |
| | | |
| | | ModifyOperation modOp = getRootConnection().processModify(DN.valueOf("o=test"), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest("o=test") |
| | | .addModification(ADD, "aci", |
| | | "(target=\"ldap:///uid=*,o=test\")(targetattr=\"*\")" |
| | | + "(version 3.0; acl \"Samba admin\"; allow (all) " |
| | | + "userdn=\"ldap:///cn=samba admin,o=test\";)"); |
| | | ModifyOperation modOp = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modOp.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | TestCaseUtils.addEntry(testEntry); |
| | | |
| | | // Perform the modify operation |
| | | LinkedList<Modification> mods = newLinkedList( |
| | | new Modification(ModificationType.REPLACE, Attributes.create("userPassword", "password"))); |
| | | |
| | | ModifyOperation modOp = getRootConnection().processModify(testEntry.getName(), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(from(testEntry.getName())) |
| | | .addModification(REPLACE, "userPassword", "password"); |
| | | ModifyOperation modOp = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modOp.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | // Verification of the change |
| | |
| | | package org.opends.server.protocols.internal; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.CancelRequest; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | |
| | | "objectClass: device", |
| | | "cn: test"); |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(new LDAPModification(ModificationType.REPLACE, |
| | | new LDAPAttribute("description", "This is a test"))); |
| | | List<RawModification> mods = newArrayList(RawModification.create(REPLACE, "description", "This is a test")); |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyOperation modifyOperation = |
| | |
| | | "objectClass: device", |
| | | "cn: test"); |
| | | |
| | | ArrayList<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("description", "This is a test"))); |
| | | List<Modification> mods = newArrayList( |
| | | new Modification(REPLACE, Attributes.create("description", "This is a test"))); |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyOperation modifyOperation = |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.protocols.internal; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Hashtable; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | |
| | | import javax.naming.Context; |
| | | import javax.naming.NamingEnumeration; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.ldap.*; |
| | | import org.opends.server.protocols.ldap.AddRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.CompareRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.DeleteRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPFilter; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.opends.server.protocols.ldap.ModifyDNRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.ModifyRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.SearchRequestProtocolOp; |
| | | import org.opends.server.tools.LDAPReader; |
| | | import org.opends.server.tools.LDAPWriter; |
| | | import org.opends.server.types.DN; |
| | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * This class provides a number of tests to cover the internal LDAP socket |
| | | * implementation. |
| | | */ |
| | | /** This class provides a number of tests to cover the internal LDAP socket implementation. */ |
| | | public class InternalLDAPSocketTestCase extends InternalTestCase |
| | | { |
| | | /** |
| | |
| | | TestCaseUtils.initializeTestBackend(false); |
| | | assertFalse(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | |
| | | InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket); |
| | | try (InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket)) |
| | | { |
| | | writer.writeMessage(bindRequestMessage()); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | LDAPMessage message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | List<RawAttribute> attrList = newArrayList( |
| | | RawAttribute.create("objectClass", "organization"), |
| | | RawAttribute.create("o", "test")); |
| | | |
| | | AddRequestProtocolOp addRequest = new AddRequestProtocolOp(ByteString.valueOfUtf8("o=test"), attrList); |
| | | writer.writeMessage(new LDAPMessage(2, addRequest)); |
| | | |
| | | ArrayList<RawAttribute> attrList = new ArrayList<>(); |
| | | attrList.add(RawAttribute.create("objectClass", "organization")); |
| | | attrList.add(RawAttribute.create("o", "test")); |
| | | |
| | | AddRequestProtocolOp addRequest = |
| | | new AddRequestProtocolOp(ByteString.valueOfUtf8("o=test"), attrList); |
| | | writer.writeMessage(new LDAPMessage(2, addRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getAddResponseProtocolOp().getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | |
| | | reader.close(); |
| | | writer.close(); |
| | | socket.close(); |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getAddResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | |
| | | InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket); |
| | | try (InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket)) |
| | | { |
| | | writer.writeMessage(bindRequestMessage()); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | LDAPMessage message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | CompareRequestProtocolOp compareRequest = |
| | | new CompareRequestProtocolOp(ByteString.valueOfUtf8("o=test"), "o", ByteString.valueOfUtf8("test")); |
| | | writer.writeMessage(new LDAPMessage(2, compareRequest)); |
| | | |
| | | |
| | | CompareRequestProtocolOp compareRequest = |
| | | new CompareRequestProtocolOp(ByteString.valueOfUtf8("o=test"), "o", |
| | | ByteString.valueOfUtf8("test")); |
| | | writer.writeMessage(new LDAPMessage(2, compareRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getCompareResponseProtocolOp().getResultCode(), |
| | | LDAPResultCode.COMPARE_TRUE); |
| | | |
| | | reader.close(); |
| | | writer.close(); |
| | | socket.close(); |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getCompareResponseProtocolOp().getResultCode(), LDAPResultCode.COMPARE_TRUE); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | |
| | | InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket); |
| | | try (InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket)) |
| | | { |
| | | writer.writeMessage(bindRequestMessage()); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | LDAPMessage message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | DeleteRequestProtocolOp deleteRequest = new DeleteRequestProtocolOp(ByteString.valueOfUtf8("o=test")); |
| | | writer.writeMessage(new LDAPMessage(2, deleteRequest)); |
| | | |
| | | |
| | | DeleteRequestProtocolOp deleteRequest = |
| | | new DeleteRequestProtocolOp(ByteString.valueOfUtf8("o=test")); |
| | | writer.writeMessage(new LDAPMessage(2, deleteRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getDeleteResponseProtocolOp().getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | assertFalse(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | |
| | | reader.close(); |
| | | writer.close(); |
| | | socket.close(); |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getDeleteResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS); |
| | | assertFalse(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | @Test |
| | | public void testExtendedOperation() throws Exception |
| | | { |
| | | InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket); |
| | | try (InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket)) |
| | | { |
| | | writer.writeMessage(bindRequestMessage()); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | LDAPMessage message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | ExtendedRequestProtocolOp extendedRequest = new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST); |
| | | writer.writeMessage(new LDAPMessage(2, extendedRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST); |
| | | writer.writeMessage(new LDAPMessage(2, extendedRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | assertTrue(extendedResponse.getValue().toString().equalsIgnoreCase( |
| | | "dn:cn=Directory Manager,cn=Root DNs,cn=config")); |
| | | |
| | | reader.close(); |
| | | writer.close(); |
| | | socket.close(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | assertTrue(extendedResponse.getValue().toString().equalsIgnoreCase( |
| | | "dn:cn=Directory Manager,cn=Root DNs,cn=config")); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | |
| | | InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket); |
| | | try (InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket)) |
| | | { |
| | | writer.writeMessage(bindRequestMessage()); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | List<RawModification> mods = newArrayList( |
| | | RawModification.create(REPLACE, "description", "foo")); |
| | | |
| | | ModifyRequestProtocolOp modifyRequest = new ModifyRequestProtocolOp(ByteString.valueOfUtf8("o=test"), mods); |
| | | writer.writeMessage(new LDAPMessage(2, modifyRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getModifyResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @return |
| | | */ |
| | | private LDAPMessage bindRequestMessage() |
| | | { |
| | | BindRequestProtocolOp bindRequest = bindRequest(); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(RawModification.create(ModificationType.REPLACE, "description", "foo")); |
| | | |
| | | ModifyRequestProtocolOp modifyRequest = |
| | | new ModifyRequestProtocolOp(ByteString.valueOfUtf8("o=test"), mods); |
| | | writer.writeMessage(new LDAPMessage(2, modifyRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getModifyResponseProtocolOp().getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | |
| | | reader.close(); |
| | | writer.close(); |
| | | socket.close(); |
| | | return message; |
| | | } |
| | | |
| | | |
| | |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=People,o=test"))); |
| | | assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=Users,o=test"))); |
| | | |
| | | InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket); |
| | | try (InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket)) |
| | | { |
| | | LDAPMessage message = bindRequestMessage(); |
| | | writer.writeMessage(message); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | ModifyDNRequestProtocolOp modifyDNRequest = |
| | | new ModifyDNRequestProtocolOp(ByteString.valueOfUtf8("ou=People,o=test"), ByteString.valueOfUtf8("ou=Users"), |
| | | true); |
| | | writer.writeMessage(new LDAPMessage(2, modifyDNRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getModifyDNResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS); |
| | | |
| | | assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=People,o=test"))); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=Users,o=test"))); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @return |
| | | */ |
| | | private BindRequestProtocolOp bindRequest() |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | |
| | | ModifyDNRequestProtocolOp modifyDNRequest = |
| | | new ModifyDNRequestProtocolOp(ByteString.valueOfUtf8("ou=People,o=test"), |
| | | ByteString.valueOfUtf8("ou=Users"), true); |
| | | writer.writeMessage(new LDAPMessage(2, modifyDNRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getModifyDNResponseProtocolOp().getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | |
| | | assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=People,o=test"))); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=Users,o=test"))); |
| | | |
| | | reader.close(); |
| | | writer.close(); |
| | | socket.close(); |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), 3, ByteString |
| | | .valueOfUtf8("password")); |
| | | return bindRequest; |
| | | } |
| | | |
| | | |
| | |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test"))); |
| | | |
| | | InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket); |
| | | try (InternalLDAPSocket socket = new InternalLDAPSocket(); |
| | | LDAPReader reader = new LDAPReader(socket); |
| | | LDAPWriter writer = new LDAPWriter(socket)) |
| | | { |
| | | writer.writeMessage(bindRequestMessage()); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | writer.writeMessage(message); |
| | | LDAPMessage message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0); |
| | | SearchRequestProtocolOp searchRequest = |
| | | new SearchRequestProtocolOp(ByteString.valueOfUtf8("o=test"), SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, LDAPFilter.objectClassPresent(), new LinkedHashSet<String>()); |
| | | writer.writeMessage(new LDAPMessage(2, searchRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getSearchResultEntryProtocolOp().getDN(), DN.valueOf("o=test")); |
| | | |
| | | SearchRequestProtocolOp searchRequest = |
| | | new SearchRequestProtocolOp(ByteString.valueOfUtf8("o=test"), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, |
| | | 0, 0, false, |
| | | LDAPFilter.objectClassPresent(), |
| | | new LinkedHashSet<String>()); |
| | | writer.writeMessage(new LDAPMessage(2, searchRequest)); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getSearchResultEntryProtocolOp().getDN(), |
| | | DN.valueOf("o=test")); |
| | | |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getSearchResultDoneProtocolOp().getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | |
| | | reader.close(); |
| | | writer.close(); |
| | | socket.close(); |
| | | message = reader.readMessage(); |
| | | assertNotNull(message); |
| | | assertEquals(message.getSearchResultDoneProtocolOp().getResultCode(), LDAPResultCode.SUCCESS); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | context.close(); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.controls.ProxiedAuthV1Control; |
| | | import org.opends.server.controls.ProxiedAuthV2Control; |
| | |
| | | import org.opends.server.core.SchemaConfigManager; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.Privilege; |
| | | import org.opends.server.types.RDN; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.messages.ProtocolMessages.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | |
| | | |
| | | private void processModify(DN dn, ModificationType modType, String attrName, String attrValue) |
| | | { |
| | | ArrayList<Modification> mods = newModifications(modType, attrName, attrValue); |
| | | ModifyOperation modifyOp = getRootConnection().processModify(dn, mods); |
| | | ModifyOperation modifyOp = getRootConnection().processModify( |
| | | Requests.newModifyRequest(from(dn)).addModification(modType, attrName, attrValue)); |
| | | assertEquals(modifyOp.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | package org.opends.server.protocols.ldap; |
| | | |
| | | import static org.assertj.core.api.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.FileReader; |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashSet; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.core.DirectoryServer; |
| | |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.ExistingFileBehavior; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.opends.server.types.LDIFExportConfig; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.util.Base64; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | public void binaryOptionUsingV2() throws Exception |
| | | { |
| | | //Construct a V2 connection. |
| | | try (Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | org.opends.server.tools.LDAPWriter w = new org.opends.server.tools.LDAPWriter(s)) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | ArrayList<RawAttribute> addAttrs = new ArrayList<>(); |
| | | addAttrs.add(RawAttribute.create("objectClass", "inetOrgPerson")); |
| | | addAttrs.add(RawAttribute.create("uid", "user.7")); |
| | | addAttrs.add(RawAttribute.create("cn", "user 7")); |
| | | addAttrs.add(RawAttribute.create("sn", "sn#1")); |
| | | addAttrs.add(RawAttribute.create("sn;x-foo", "sn#2")); |
| | | addAttrs.add(RawAttribute.create("sn;lang-fr", "sn#3")); |
| | | addAttrs.add(RawAttribute.create("userCertificate;binary", |
| | | ByteString.wrap(Base64.decode(CERT)))); |
| | | |
| | | AddRequestProtocolOp addRequest = |
| | | new AddRequestProtocolOp(ByteString.valueOfUtf8("uid=user.7,o=test"), |
| | | addAttrs); |
| | | message = new LDAPMessage(2, addRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | AddRequest addRequest = Requests.newAddRequest("uid=user.7,o=test") |
| | | .addAttribute("objectClass", "inetOrgPerson") |
| | | .addAttribute("uid", "user.7") |
| | | .addAttribute("cn", "user 7") |
| | | .addAttribute("sn", "sn#1") |
| | | .addAttribute("sn;x-foo", "sn#2") |
| | | .addAttribute("sn;lang-fr", "sn#3") |
| | | .addAttribute("userCertificate;binary", ByteString.wrap(Base64.decode(CERT))); |
| | | LDAPMessage message = conn.add(addRequest); |
| | | AddResponseProtocolOp addResponse = message.getAddResponseProtocolOp(); |
| | | assertEquals(addResponse.getResultCode(),0); |
| | | |
| | | //Create a SEARCH request to search for this added entry. |
| | | LinkedHashSet<String> attrs = new LinkedHashSet<>(); |
| | | //Request only the interesting attributes. |
| | | attrs.add("sn"); |
| | | attrs.add("userCertificate;binary"); |
| | | SearchRequestProtocolOp searchRequest = |
| | | new SearchRequestProtocolOp(ByteString.valueOfUtf8("o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, |
| | | LDAPFilter.decode("(uid=user.7)"), |
| | | attrs); |
| | | message = new LDAPMessage(2, searchRequest); |
| | | w.writeMessage(message); |
| | | |
| | | SearchResultEntryProtocolOp searchResultEntry = null; |
| | | SearchResultDoneProtocolOp searchResultDone = null; |
| | | while (searchResultDone == null) |
| | | { |
| | | message = r.readMessage(); |
| | | switch (message.getProtocolOpType()) |
| | | { |
| | | case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY: |
| | | searchResultEntry = message.getSearchResultEntryProtocolOp(); |
| | | break; |
| | | case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE: |
| | | searchResultDone = message.getSearchResultDoneProtocolOp(); |
| | | assertEquals(searchResultDone.getResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | break; |
| | | } |
| | | } |
| | | assertNotNull(searchResultEntry); |
| | | conn.search(Requests.newSearchRequest("o=test", WHOLE_SUBTREE, "(uid=user.7)", "sn", "userCertificate;binary")); |
| | | List<SearchResultEntryProtocolOp> entries = conn.readEntries(); |
| | | assertThat(entries).hasSize(1); |
| | | boolean certWithNoOption = false; |
| | | boolean snWithMultiVal = false; |
| | | for(LDAPAttribute a:searchResultEntry.getAttributes()) |
| | | for (LDAPAttribute a : entries.get(0).getAttributes()) |
| | | { |
| | | //Shouldn't be userCertificate;binary. |
| | | if ("userCertificate".equalsIgnoreCase(a.getAttributeType())) |
| | |
| | | } |
| | | } |
| | | |
| | | private void bindLdapV2(RemoteConnection conn, String bindDN, String bindPwd) throws IOException, LDAPException |
| | | { |
| | | conn.writeMessage(new BindRequestProtocolOp(ByteString.valueOfUtf8(bindDN), 2, ByteString.valueOfUtf8(bindPwd))); |
| | | |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | } |
| | | |
| | | /** |
| | | * Test to verify that the DB stores the binary option by |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2010-2015 ForgeRock AS. |
| | | * Portions Copyright 2010-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.protocols.ldap ; |
| | | |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.tools.LDAPWriter; |
| | | import org.opends.server.types.Control; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.types.RawModification; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.controls.GenericControl.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.CompareRequest; |
| | | import org.forgerock.opendj.ldap.requests.DeleteRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyDNRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.requests.SearchRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * This class provides a number of tests to ensure that the server interacts |
| | | * with LDAPv2 clients as expected. |
| | |
| | | "replace: ds-cfg-allow-ldap-v2", |
| | | "ds-cfg-allow-ldap-v2: false"); |
| | | |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), |
| | | LDAPResultCode.PROTOCOL_ERROR); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password", LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | |
| | | "changetype: modify", |
| | | "replace: ds-cfg-allow-ldap-v2", |
| | | "ds-cfg-allow-ldap-v2: true"); |
| | | |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | } |
| | | } |
| | | |
| | |
| | | public void testRejectExtendedRequest() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_START_TLS_REQUEST); |
| | | message = new LDAPMessage(2, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | assertNull(r.readMessage()); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | conn.writeMessage(new ExtendedRequestProtocolOp(OID_START_TLS_REQUEST)); |
| | | assertNull(conn.readMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | public void testRejectAddControls() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | AddRequest addRequest = Requests.newAddRequest("ou=People,o=test") |
| | | .addAttribute("objectClass", "organizationalUnit") |
| | | .addAttribute("ou", "People") |
| | | .addControl(newControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | |
| | | ArrayList<RawAttribute> addAttrs = new ArrayList<>(); |
| | | addAttrs.add(RawAttribute.create("objectClass", "organizationalUnit")); |
| | | addAttrs.add(RawAttribute.create("ou", "People")); |
| | | |
| | | AddRequestProtocolOp addRequest = |
| | | new AddRequestProtocolOp(ByteString.valueOfUtf8("ou=People,o=test"), addAttrs); |
| | | ArrayList<Control> controls = new ArrayList<>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | message = new LDAPMessage(2, addRequest, controls); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | LDAPMessage message = conn.add(addRequest, false); |
| | | AddResponseProtocolOp addResponse = message.getAddResponseProtocolOp(); |
| | | assertEquals(addResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | } |
| | | } |
| | | |
| | | private void bindLdapV2(RemoteConnection conn, String bindDN, String bindPwd) throws IOException, LDAPException |
| | | { |
| | | bindLdapV2(conn, bindDN, bindPwd, LDAPResultCode.SUCCESS); |
| | | } |
| | | |
| | | private void bindLdapV2(RemoteConnection conn, String bindDN, String bindPwd, int expectedRC, Control... controls) |
| | | throws IOException, LDAPException |
| | | { |
| | | conn.writeMessage(new BindRequestProtocolOp(ByteString.valueOfUtf8(bindDN), 2, ByteString.valueOfUtf8(bindPwd)), |
| | | Arrays.asList(controls)); |
| | | |
| | | LDAPMessage message = conn.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), expectedRC); |
| | | } |
| | | |
| | | /** |
| | | * Tests to ensure that the server will reject an LDAPv2 bind request if it |
| | |
| | | public void testRejectBindControls() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | ArrayList<Control> controls = new ArrayList<>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest, controls); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password", |
| | | LDAPResultCode.PROTOCOL_ERROR, new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that the server will reject an LDAPv2 compare request if it |
| | | * contains any controls. |
| | |
| | | public void testRejectCompareControls() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | CompareRequestProtocolOp compareRequest = |
| | | new CompareRequestProtocolOp(ByteString.valueOfUtf8("o=test"), |
| | | "o", ByteString.valueOfUtf8("test")); |
| | | ArrayList<Control> controls = new ArrayList<>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | message = new LDAPMessage(2, compareRequest, controls); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | CompareResponseProtocolOp compareResponse = |
| | | message.getCompareResponseProtocolOp(); |
| | | assertEquals(compareResponse.getResultCode(), |
| | | LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | CompareRequest compareRequest = newCompareRequest("o=test", "o", "test") |
| | | .addControl(newControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | LDAPMessage message = conn.compare(compareRequest, false); |
| | | CompareResponseProtocolOp compareResponse = message.getCompareResponseProtocolOp(); |
| | | assertEquals(compareResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | } |
| | | |
| | |
| | | public void testRejectDeleteControls() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | DeleteRequestProtocolOp deleteRequest = |
| | | new DeleteRequestProtocolOp(ByteString.valueOfUtf8("o=test")); |
| | | ArrayList<Control> controls = new ArrayList<>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | message = new LDAPMessage(2, deleteRequest, controls); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | DeleteResponseProtocolOp deleteResponse = |
| | | message.getDeleteResponseProtocolOp(); |
| | | assertEquals(deleteResponse.getResultCode(), |
| | | LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | DeleteRequest deleteRequest = newDeleteRequest("o=test") |
| | | .addControl(newControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | LDAPMessage message = conn.delete(deleteRequest, false); |
| | | DeleteResponseProtocolOp deleteResponse = message.getDeleteResponseProtocolOp(); |
| | | assertEquals(deleteResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | } |
| | | |
| | |
| | | public void testRejectModifyControls() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | ArrayList<RawModification> mods = new ArrayList<>(); |
| | | mods.add(RawModification.create(ModificationType.REPLACE, "description", "foo")); |
| | | |
| | | ModifyRequestProtocolOp modifyRequest = |
| | | new ModifyRequestProtocolOp(ByteString.valueOfUtf8("o=test"), mods); |
| | | ArrayList<Control> controls = new ArrayList<>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | message = new LDAPMessage(2, modifyRequest, controls); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | ModifyResponseProtocolOp modifyResponse = |
| | | message.getModifyResponseProtocolOp(); |
| | | assertEquals(modifyResponse.getResultCode(), |
| | | LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | ModifyRequest modifyRequest = newModifyRequest("o=test") |
| | | .addModification(REPLACE, "description", "foo") |
| | | .addControl(newControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | LDAPMessage message = conn.modify(modifyRequest, false); |
| | | ModifyResponseProtocolOp modifyResponse = message.getModifyResponseProtocolOp(); |
| | | assertEquals(modifyResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | } |
| | | |
| | |
| | | public void testRejectModifyDNControls() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | ModifyDNRequestProtocolOp modifyDNRequest = |
| | | new ModifyDNRequestProtocolOp(ByteString.valueOfUtf8("o=test"), |
| | | ByteString.valueOfUtf8("cn=test"), false); |
| | | ArrayList<Control> controls = new ArrayList<>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | message = new LDAPMessage(2, modifyDNRequest, controls); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | ModifyDNResponseProtocolOp modifyDNResponse = |
| | | message.getModifyDNResponseProtocolOp(); |
| | | assertEquals(modifyDNResponse.getResultCode(), |
| | | LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | ModifyDNRequest modifyDNRequest = newModifyDNRequest("o=test", "cn=test") |
| | | .addControl(newControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | LDAPMessage message = conn.modifyDN(modifyDNRequest, false); |
| | | ModifyDNResponseProtocolOp modifyDNResponse = message.getModifyDNResponseProtocolOp(); |
| | | assertEquals(modifyDNResponse.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | } |
| | | |
| | |
| | | public void testRejectSearchControls() |
| | | throws Exception |
| | | { |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | try |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Directory Manager"), 2, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | bindLdapV2(conn, "cn=Directory Manager", "password"); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | |
| | | SearchRequestProtocolOp searchRequest = |
| | | new SearchRequestProtocolOp(ByteString.empty(), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | LDAPFilter.objectClassPresent(), null); |
| | | ArrayList<Control> controls = new ArrayList<>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | message = new LDAPMessage(2, searchRequest, controls); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | SearchResultDoneProtocolOp searchDone = |
| | | message.getSearchResultDoneProtocolOp(); |
| | | SearchRequest searchRequest = newSearchRequest(DN.rootDN(), BASE_OBJECT, Filter.objectClassPresent()) |
| | | .addControl(newControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | conn.search(searchRequest); |
| | | LDAPMessage message = conn.readMessage(); |
| | | SearchResultDoneProtocolOp searchDone = message.getSearchResultDoneProtocolOp(); |
| | | assertEquals(searchDone.getResultCode(), LDAPResultCode.PROTOCOL_ERROR); |
| | | } |
| | | finally |
| | | { |
| | | StaticUtils.close(r, w); |
| | | StaticUtils.close(s); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.protocols.ldap; |
| | | |
| | |
| | | import org.forgerock.opendj.io.ASN1Writer; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.opends.server.types.RawModification; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | * |
| | | * @param numAttributes Number of attributes to generate. 0 will return |
| | | * a empty list. |
| | | * @param prefix String to prefix the attribute values |
| | | * @return The generate attributes. |
| | | * |
| | | */ |
| | | private List<RawModification> generateModifications(int numAttributes, |
| | | String prefix) |
| | | private List<RawModification> generateModifications(int numAttributes) |
| | | { |
| | | List<RawModification> modifies = new ArrayList<>(); |
| | | ModificationType modificationType; |
| | | |
| | | for(int i = 0; i < numAttributes; i++) |
| | | { |
| | | LDAPAttribute attribute = new LDAPAttribute("testAttribute" + i); |
| | | switch(i % 4) |
| | | { |
| | | case 0 : modificationType = ModificationType.ADD; |
| | | break; |
| | | case 1 : modificationType = ModificationType.DELETE; |
| | | break; |
| | | case 2 : modificationType = ModificationType.REPLACE; |
| | | break; |
| | | case 3 : modificationType = ModificationType.INCREMENT; |
| | | break; |
| | | default : modificationType = ModificationType.ADD; |
| | | } |
| | | |
| | | modifies.add(new LDAPModification(modificationType, attribute)); |
| | | modifies.add(new LDAPModification(toModificationType(i), attribute)); |
| | | } |
| | | |
| | | return modifies; |
| | | } |
| | | |
| | | private ModificationType toModificationType(int i) |
| | | { |
| | | switch(i % 4) |
| | | { |
| | | case 0: |
| | | return ModificationType.ADD; |
| | | case 1: |
| | | return ModificationType.DELETE; |
| | | case 2: |
| | | return ModificationType.REPLACE; |
| | | case 3: |
| | | return ModificationType.INCREMENT; |
| | | default: |
| | | return ModificationType.ADD; |
| | | } |
| | | } |
| | | |
| | | private Boolean modificationsEquals(List<RawModification> modifies1, |
| | | List<RawModification> modifies2) |
| | | { |
| | |
| | | assertEquals(modifyRequest.getModifications().size(), 0); |
| | | |
| | | //Test to make sure the constructor with dn and attribute params works. |
| | | modifications = generateModifications(10, "test"); |
| | | modifications = generateModifications(10); |
| | | modifyRequest = new ModifyRequestProtocolOp(dn, modifications); |
| | | assertEquals(modifyRequest.getDN(), dn); |
| | | assertEquals(modifyRequest.getModifications(), modifications); |
| | |
| | | |
| | | |
| | | //Test case for a full encode decode operation with normal params. |
| | | modifies = generateModifications(10,"test"); |
| | | modifies = generateModifications(10); |
| | | modifyEncoded = new ModifyRequestProtocolOp(dn, modifies); |
| | | modifyEncoded.write(writer); |
| | | ASN1Reader reader = ASN1.getReader(builder.toByteString()); |
| | |
| | | modifyDecoded.getModifications())); |
| | | |
| | | //Test case for a full encode decode operation with large modifications. |
| | | modifies = generateModifications(100,"test"); |
| | | modifies = generateModifications(100); |
| | | modifyEncoded = new ModifyRequestProtocolOp(dn, modifies); |
| | | builder.clear(); |
| | | modifyEncoded.write(writer); |
| | |
| | | { |
| | | StringBuilder buffer = new StringBuilder(); |
| | | StringBuilder key = new StringBuilder(); |
| | | int numModifications = 10; |
| | | List<RawModification> modifications = |
| | | generateModifications(numModifications, "test"); |
| | | ModifyRequestProtocolOp modifyRequest = |
| | | new ModifyRequestProtocolOp(dn, modifications); |
| | | List<RawModification> modifications = generateModifications(10); |
| | | ModifyRequestProtocolOp modifyRequest = new ModifyRequestProtocolOp(dn, modifications); |
| | | modifyRequest.toString(buffer); |
| | | |
| | | key.append("ModifyRequest(dn=").append(dn).append(", mods={"); |
| | | for (int i = 0; i < numModifications; i++) |
| | | { |
| | | modifications.get(i).toString(key); |
| | | if(i < numModifications - 1) |
| | | { |
| | | key.append(", "); |
| | | } |
| | | } |
| | | Utils.joinAsString(key, ", ", modifications); |
| | | key.append("})"); |
| | | |
| | | assertEquals(buffer.toString(), key.toString()); |
| | |
| | | |
| | | int numModifications = 10; |
| | | int indent = 5; |
| | | List<RawModification> modifications = |
| | | generateModifications(numModifications, "test"); |
| | | List<RawModification> modifications = generateModifications(numModifications); |
| | | ModifyRequestProtocolOp modifyRequest = |
| | | new ModifyRequestProtocolOp(dn, modifications); |
| | | modifyRequest.toString(buffer, indent); |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.replication; |
| | | |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.DirectoryServerTestCase; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.server.ReplicationDomainCfg; |
| | |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | |
| | | return newArrayList(new Modification(REPLACE, attr)); |
| | | } |
| | | |
| | | protected static ModifyRequest modifyRequest(DN entryDN, ModificationType modType, String attrName, String attrValue) |
| | | { |
| | | return Requests.newModifyRequest(from(entryDN)).addModification(modType, attrName, attrValue); |
| | | } |
| | | |
| | | /** Utility method to create, run a task and check its result. */ |
| | | protected void task(String task) throws Exception |
| | | { |
| | |
| | | |
| | | import java.net.SocketTimeoutException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.concurrent.Callable; |
| | | |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.DeleteOperation; |
| | |
| | | import org.opends.server.plugins.ShortCircuitPlugin; |
| | | import org.opends.server.replication.common.CSN; |
| | | import org.opends.server.replication.common.CSNGenerator; |
| | | import org.opends.server.replication.protocol.*; |
| | | import org.opends.server.replication.protocol.AddMsg; |
| | | import org.opends.server.replication.protocol.DeleteMsg; |
| | | import org.opends.server.replication.protocol.HeartbeatThread; |
| | | import org.opends.server.replication.protocol.LDAPUpdateMsg; |
| | | import org.opends.server.replication.protocol.ModifyDNMsg; |
| | | import org.opends.server.replication.protocol.ModifyMsg; |
| | | import org.opends.server.replication.protocol.OperationContext; |
| | | import org.opends.server.replication.protocol.ReplicationMsg; |
| | | import org.opends.server.replication.service.ReplicationBroker; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.OperationType; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TimeThread; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.replication.plugin.LDAPReplicationDomain.*; |
| | |
| | | assertClientReceivesExpectedMsg(broker, AddMsg.class, personEntry.getName()); |
| | | |
| | | // Modify the entry |
| | | List<Modification> mods = generatemods("telephonenumber", "01 02 45"); |
| | | connection.processModify(personEntry.getName(), mods); |
| | | connection.processModify(modifyRequest(personEntry.getName(), REPLACE, "telephonenumber", "01 02 45")); |
| | | assertClientReceivesExpectedMsg(broker, ModifyMsg.class, personEntry.getName()); |
| | | |
| | | // Modify the entry DN |
| | |
| | | * Test the reception of Modify Msg |
| | | */ |
| | | ModifyMsg modMsg = new ModifyMsg(gen.newCSN(), personWithUUIDEntry.getName(), |
| | | mods, user1entryUUID); |
| | | generatemods("telephonenumber", "01 02 45"), user1entryUUID); |
| | | modMsg.setAssured(assured); |
| | | broker.publish(modMsg); |
| | | |
| | |
| | | */ |
| | | private static void setReceiveStatus(DN syncConfigDN, boolean enable) |
| | | { |
| | | Attribute attr = Attributes.create("ds-cfg-receive-status", enable ? "TRUE" : "FALSE"); |
| | | ModifyOperation modOp = getRootConnection().processModify(syncConfigDN, |
| | | Arrays.asList(new Modification(ModificationType.REPLACE, attr))); |
| | | String attrValue = enable ? "TRUE" : "FALSE"; |
| | | ModifyRequest request = modifyRequest(syncConfigDN, REPLACE, "ds-cfg-receive-status", attrValue); |
| | | ModifyOperation modOp = getRootConnection().processModify(request); |
| | | assertEquals(modOp.getResultCode(), ResultCode.SUCCESS, "Cannot set receive status"); |
| | | } |
| | | |
| | |
| | | "The entry has not been created"); |
| | | |
| | | // Modify the entry |
| | | List<Modification> mods = generatemods("telephonenumber", "01 02 45"); |
| | | connection.processModify(user3Entry.getName(), mods); |
| | | connection.processModify(modifyRequest(user3Entry.getName(), REPLACE, "telephonenumber", "01 02 45")); |
| | | |
| | | // See if the client has received the msg |
| | | ReplicationMsg msg = broker.receive(); |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.replication.plugin; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.meta.ReplicationDomainCfgDefn.IsolationPolicy; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.replication.ReplicationTestCase; |
| | | import org.opends.server.types.DN; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | |
| | | domain.start(); |
| | | |
| | | // check that the updates fail with the unwilling to perform error. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyOperation op = |
| | | conn.processModify(baseDn, generatemods("description", "test")); |
| | | |
| | | // check that the update failed. |
| | | assertEquals(ResultCode.UNWILLING_TO_PERFORM, op.getResultCode()); |
| | | ModifyOperation op = modify(baseDn, "description", "test"); |
| | | assertEquals(op.getResultCode(), ResultCode.UNWILLING_TO_PERFORM); |
| | | |
| | | // now configure the domain to accept changes even though it is not |
| | | // connected to any replication server. |
| | |
| | | domain.applyConfigurationChange(domainConf); |
| | | |
| | | // try a new modify operation on the base entry. |
| | | op = conn.processModify(baseDn, generatemods("description", "test")); |
| | | op = modify(baseDn, "description", "test"); |
| | | |
| | | // check that the operation was successful. |
| | | assertEquals(op.getResultCode(), ResultCode.SUCCESS, |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private ModifyOperation modify(DN baseDn, String attrName, String attrValue) |
| | | { |
| | | return getRootConnection().processModify(modifyRequest(baseDn, REPLACE, attrName, attrValue)); |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tasks; |
| | | |
| | | import java.net.Socket; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.extensions.GetConnectionIDExtendedOperation; |
| | | import org.opends.server.protocols.ldap.*; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.util.StaticUtils; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.extensions.GetConnectionIDExtendedOperation; |
| | | import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPConstants; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** Tests the disconnect client task. */ |
| | | public class DisconnectClientTaskTestCase |
| | | extends TasksTestCase |
| | |
| | | throws Exception |
| | | { |
| | | // Establish a connection to the server, bind, and get the connection ID. |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(s); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | long connectionID = getConnectionID(conn); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | // Invoke the disconnect client task. |
| | | String taskID = "Disconnect Client " + connectionID; |
| | | LocalizableMessage disconnectMessage = LocalizableMessage.raw("testDisconnectWithNotification"); |
| | | DN taskDN = DN.valueOf("ds-task-id=" + taskID + ",cn=Scheduled Tasks,cn=Tasks"); |
| | | TestCaseUtils.addEntry( |
| | | "dn: " + taskDN, |
| | | "objectClass: top", |
| | | "objectClass: ds-task", |
| | | "objectClass: ds-task-disconnect", |
| | | "ds-task-id: " + taskID, |
| | | "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask", |
| | | "ds-task-disconnect-connection-id: " + connectionID, |
| | | "ds-task-disconnect-notify-client: true", |
| | | "ds-task-disconnect-message: " + disconnectMessage); |
| | | |
| | | waitTaskCompletedSuccessfully(taskDN); |
| | | |
| | | |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_GET_CONNECTION_ID_EXTOP); |
| | | message = new LDAPMessage(2, extendedRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | assertEquals(extendedResponse.getOID(), OID_GET_CONNECTION_ID_EXTOP); |
| | | long connectionID = GetConnectionIDExtendedOperation.decodeResponseValue( |
| | | extendedResponse.getValue()); |
| | | |
| | | |
| | | // Invoke the disconnect client task. |
| | | String taskID = "Disconnect Client " + connectionID; |
| | | LocalizableMessage disconnectMessage = LocalizableMessage.raw("testDisconnectWithNotification"); |
| | | DN taskDN = DN.valueOf("ds-task-id=" + taskID + |
| | | ",cn=Scheduled Tasks,cn=Tasks"); |
| | | TestCaseUtils.addEntry( |
| | | "dn: " + taskDN, |
| | | "objectClass: top", |
| | | "objectClass: ds-task", |
| | | "objectClass: ds-task-disconnect", |
| | | "ds-task-id: " + taskID, |
| | | "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask", |
| | | "ds-task-disconnect-connection-id: " + connectionID, |
| | | "ds-task-disconnect-notify-client: true", |
| | | "ds-task-disconnect-message: " + disconnectMessage); |
| | | |
| | | waitTaskCompletedSuccessfully(taskDN); |
| | | |
| | | |
| | | // Make sure that we get a notice of disconnection on the initial connection. |
| | | message = r.readMessage(); |
| | | extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getOID(), |
| | | LDAPConstants.OID_NOTICE_OF_DISCONNECTION); |
| | | assertEquals(extendedResponse.getErrorMessage(), disconnectMessage); |
| | | |
| | | StaticUtils.close(s); |
| | | // Make sure that we get a notice of disconnection on the initial connection. |
| | | LDAPMessage message = conn.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getOID(), LDAPConstants.OID_NOTICE_OF_DISCONNECTION); |
| | | assertEquals(extendedResponse.getErrorMessage(), disconnectMessage); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | throws Exception |
| | | { |
| | | // Establish a connection to the server, bind, and get the connection ID. |
| | | Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort()); |
| | | org.opends.server.tools.LDAPReader r = |
| | | new org.opends.server.tools.LDAPReader(s); |
| | | org.opends.server.tools.LDAPWriter w = |
| | | new org.opends.server.tools.LDAPWriter(s); |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | conn.bind("cn=Directory Manager", "password"); |
| | | |
| | | BindRequestProtocolOp bindRequest = |
| | | new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), |
| | | 3, ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | long connectionID = getConnectionID(conn); |
| | | |
| | | |
| | | ExtendedRequestProtocolOp extendedRequest = |
| | | new ExtendedRequestProtocolOp(OID_GET_CONNECTION_ID_EXTOP); |
| | | message = new LDAPMessage(2, extendedRequest); |
| | | w.writeMessage(message); |
| | | // Invoke the disconnect client task. |
| | | String taskID = "Disconnect Client " + connectionID; |
| | | DN taskDN = DN.valueOf("ds-task-id=" + taskID + ",cn=Scheduled Tasks,cn=Tasks"); |
| | | TestCaseUtils.addEntry( |
| | | "dn: " + taskDN, |
| | | "objectClass: top", |
| | | "objectClass: ds-task", |
| | | "objectClass: ds-task-disconnect", |
| | | "ds-task-id: " + taskID, |
| | | "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask", |
| | | "ds-task-disconnect-connection-id: " + connectionID, |
| | | "ds-task-disconnect-notify-client: false"); |
| | | |
| | | message = r.readMessage(); |
| | | ExtendedResponseProtocolOp extendedResponse = |
| | | message.getExtendedResponseProtocolOp(); |
| | | waitTaskCompletedSuccessfully(taskDN); |
| | | |
| | | |
| | | // Make sure that the client connection has been closed with no notice of disconnection. |
| | | assertNull(conn.readMessage()); |
| | | } |
| | | } |
| | | |
| | | private long getConnectionID(RemoteConnection conn) throws IOException, LDAPException, LdapException, DecodeException |
| | | { |
| | | LDAPMessage message = conn.extendedRequest(OID_GET_CONNECTION_ID_EXTOP); |
| | | |
| | | ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp(); |
| | | assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS); |
| | | assertEquals(extendedResponse.getOID(), OID_GET_CONNECTION_ID_EXTOP); |
| | | long connectionID = GetConnectionIDExtendedOperation.decodeResponseValue( |
| | | extendedResponse.getValue()); |
| | | |
| | | |
| | | // Invoke the disconnect client task. |
| | | String taskID = "Disconnect Client " + connectionID; |
| | | DN taskDN = DN.valueOf("ds-task-id=" + taskID + |
| | | ",cn=Scheduled Tasks,cn=Tasks"); |
| | | TestCaseUtils.addEntry( |
| | | "dn: " + taskDN, |
| | | "objectClass: top", |
| | | "objectClass: ds-task", |
| | | "objectClass: ds-task-disconnect", |
| | | "ds-task-id: " + taskID, |
| | | "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask", |
| | | "ds-task-disconnect-connection-id: " + connectionID, |
| | | "ds-task-disconnect-notify-client: false"); |
| | | |
| | | waitTaskCompletedSuccessfully(taskDN); |
| | | |
| | | |
| | | // Make sure that the client connection has been closed with no notice of disconnection. |
| | | assertNull(r.readMessage()); |
| | | |
| | | StaticUtils.close(s); |
| | | return GetConnectionIDExtendedOperation.decodeResponseValue(extendedResponse.getValue()); |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Modification; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of test cases for the rebuild-index tool (see issue #1897). |
| | | */ |
| | | /** A set of test cases for the rebuild-index tool (see issue #1897). */ |
| | | @SuppressWarnings("javadoc") |
| | | public class RebuildIndexTestCase |
| | | extends ToolsTestCase |
| | | { |
| | |
| | | configFilePath = DirectoryServer.getConfigFile(); |
| | | |
| | | // Add the airius.com suffix to userRoot |
| | | final InternalClientConnection rootConnection = |
| | | InternalClientConnection.getRootConnection(); |
| | | final ArrayList<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.ADD, |
| | | Attributes.create("ds-cfg-base-dn", baseDN))); |
| | | // Backend should be disabled. |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("ds-cfg-enabled", "false"))); |
| | | final ModifyOperation modifyOperation = |
| | | rootConnection.processModify(DN.valueOf(userRootDN), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(userRootDN) |
| | | .addModification(ADD, "ds-cfg-base-dn", baseDN) |
| | | .addModification(REPLACE, "ds-cfg-enabled", "false"); |
| | | final ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Performs necessary cleanup. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @AfterClass |
| | | public void cleanup() |
| | | throws Exception |
| | | public void cleanup() throws Exception |
| | | { |
| | | // remove the airius.com suffix to userRoot |
| | | final InternalClientConnection rootConnection = |
| | | InternalClientConnection.getRootConnection(); |
| | | final ArrayList<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.DELETE, |
| | | Attributes.create("ds-cfg-base-dn", baseDN))); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("ds-cfg-enabled", "true"))); |
| | | final ModifyOperation modifyOperation = |
| | | rootConnection.processModify(DN.valueOf(userRootDN), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(userRootDN) |
| | | .addModification(DELETE, "ds-cfg-base-dn", baseDN) |
| | | .addModification(REPLACE, "ds-cfg-enabled", "true"); |
| | | final ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | | /** |
| | | * Tries to rebuild an index but the index doesn't exist in the base DN. |
| | | */ |
| | | /** Tries to rebuild an index but the index doesn't exist in the base DN. */ |
| | | @Test |
| | | public void testRebuildIndexOnNonExistentShouldFail() |
| | | { |
| | |
| | | }; |
| | | assertEquals(RebuildIndex.mainRebuildIndex(args, false, null, null), 0); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | import java.util.Arrays; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.SSLSocketFactory; |
| | |
| | | import org.opends.server.protocols.ldap.CompareResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.DeleteRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.DeleteResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.LDAPMessage; |
| | | import org.opends.server.protocols.ldap.ModifyDNRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.ModifyDNResponseProtocolOp; |
| | |
| | | import org.opends.server.protocols.ldap.SearchRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.SearchResultDoneProtocolOp; |
| | | import org.opends.server.protocols.ldap.SearchResultEntryProtocolOp; |
| | | import org.opends.server.protocols.ldap.UnbindRequestProtocolOp; |
| | | import org.opends.server.types.LDAPException; |
| | | |
| | | /** Modeled like an SDK Connection, but implemented using the servers' ProtocolOp classes */ |
| | | @SuppressWarnings("javadoc") |
| | | public final class RemoteConnection implements Closeable |
| | | { |
| | | private final String host; |
| | | private final Socket socket; |
| | | private LDAPReader r; |
| | | private LDAPWriter w; |
| | | private int messageID; |
| | | private AtomicInteger messageID = new AtomicInteger(1); |
| | | |
| | | public RemoteConnection(String host, int port) throws Exception |
| | | { |
| | |
| | | |
| | | public RemoteConnection(String host, int port, boolean secure) throws Exception |
| | | { |
| | | this.host = host; |
| | | socket = secure ? getSslSocket(host, port) : new Socket(host, port); |
| | | r = new LDAPReader(socket); |
| | | w = new LDAPWriter(socket); |
| | |
| | | .getControls()); |
| | | } |
| | | |
| | | public LDAPMessage bind(String bindDN, String bindPassword, Control... controls) |
| | | public void bind(String bindDN, String bindPassword, Control... controls) |
| | | throws IOException, LDAPException, LdapException |
| | | { |
| | | return bind(bindDN, bindPassword.getBytes(), true, Arrays.asList(controls)); |
| | | bind(bindDN, bindPassword.getBytes(), true, Arrays.asList(controls)); |
| | | } |
| | | |
| | | private LDAPMessage bind(String bindDN, byte[] bindPassword, boolean throwOnExceptionalResultCode, |
| | |
| | | return message; |
| | | } |
| | | |
| | | public void unbind() throws IOException, LDAPException, LdapException |
| | | { |
| | | writeMessage(new UnbindRequestProtocolOp()); |
| | | } |
| | | |
| | | public LDAPMessage add(AddRequest addRequest) throws IOException, LDAPException, LdapException |
| | | { |
| | | return add(addRequest, true); |
| | |
| | | return delete(deleteRequest, true); |
| | | } |
| | | |
| | | public LDAPMessage delete(DeleteRequest deleteRequest, boolean throwOnExceptionalResultCode) throws IOException, |
| | | LDAPException, LdapException |
| | | public LDAPMessage delete(DeleteRequest deleteRequest, boolean throwOnExceptionalResultCode) |
| | | throws IOException, LDAPException, LdapException |
| | | { |
| | | writeMessage(new DeleteRequestProtocolOp(bs(deleteRequest.getName())), to(deleteRequest.getControls())); |
| | | LDAPMessage message = r.readMessage(); |
| | |
| | | return message; |
| | | } |
| | | |
| | | public LDAPMessage extendedRequest(String oid) throws IOException, LDAPException, LdapException |
| | | { |
| | | return extendedRequest(oid, null); |
| | | } |
| | | |
| | | public LDAPMessage extendedRequest(String oid, ByteString requestValue) |
| | | throws IOException, LDAPException, LdapException |
| | | { |
| | | writeMessage(new ExtendedRequestProtocolOp(oid, requestValue)); |
| | | return r.readMessage(); |
| | | } |
| | | |
| | | private ByteString bs(Object o) |
| | | { |
| | | return o != null ? ByteString.valueOfObject(o) : null; |
| | |
| | | |
| | | public void writeMessage(ProtocolOp protocolOp) throws IOException |
| | | { |
| | | writeMessage(protocolOp, null); |
| | | writeMessage(protocolOp, (List<org.opends.server.types.Control>) null); |
| | | } |
| | | |
| | | public void writeMessage(ProtocolOp protocolOp, List<org.opends.server.types.Control> controls) throws IOException |
| | | { |
| | | w.writeMessage(new LDAPMessage(++messageID, protocolOp, controls)); |
| | | w.writeMessage(new LDAPMessage(messageID.getAndIncrement(), protocolOp, controls)); |
| | | } |
| | | |
| | | public void writeMessage(ProtocolOp protocolOp, org.opends.server.types.Control control) throws IOException |
| | | { |
| | | w.writeMessage(new LDAPMessage(messageID.getAndIncrement(), protocolOp, Arrays.asList(control))); |
| | | } |
| | | |
| | | public LDAPMessage readMessage() throws IOException, LDAPException |
| | |
| | | return message; |
| | | } |
| | | |
| | | public LDAPWriter getLdapWriter() |
| | | { |
| | | return this.w; |
| | | } |
| | | |
| | | public LDAPAuthenticationHandler newLDAPAuthenticationHandler() |
| | | { |
| | | return new LDAPAuthenticationHandler(r, w, host, messageID); |
| | | } |
| | | |
| | | @Override |
| | | public void close() throws IOException |
| | | { |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Modification; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * A set of test cases for the verify-index tool (see issue #1897). |
| | | */ |
| | | /** A set of test cases for the verify-index tool (see issue #1897). */ |
| | | @SuppressWarnings("javadoc") |
| | | public class VerifyIndexTestCase |
| | | extends ToolsTestCase |
| | | { |
| | | |
| | | private String configFilePath ; |
| | | |
| | | /** |
| | | * Ensures that the Directory Server is running and performs other necessary |
| | | * setup. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | /** Ensures that the Directory Server is running and performs other necessary setup. */ |
| | | @BeforeClass |
| | | public void setup() |
| | | throws Exception |
| | | public void setup() throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | configFilePath = DirectoryServer.getConfigFile(); |
| | | |
| | | // Add the airius.com suffix to userRoot |
| | | InternalClientConnection rootConnection = |
| | | InternalClientConnection.getRootConnection(); |
| | | ArrayList<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.ADD, |
| | | Attributes.create("ds-cfg-base-dn", "o=airius.com"))); |
| | | String userRootDN = "ds-cfg-backend-id=userRoot,cn=Backends,cn=config"; |
| | | ModifyOperation modifyOperation = |
| | | rootConnection.processModify(DN.valueOf(userRootDN), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(userRootDN) |
| | | .addModification(ADD, "ds-cfg-base-dn", "o=airius.com"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | throws Exception |
| | | { |
| | | // remove the airius.com suffix to userRoot |
| | | InternalClientConnection rootConnection = |
| | | InternalClientConnection.getRootConnection(); |
| | | ArrayList<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.DELETE, |
| | | Attributes.create("ds-cfg-base-dn", "o=airius.com"))); |
| | | String userRootDN = "ds-cfg-backend-id=userRoot,cn=Backends,cn=config"; |
| | | ModifyOperation modifyOperation = |
| | | rootConnection.processModify(DN.valueOf(userRootDN), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(userRootDN) |
| | | .addModification(DELETE, "ds-cfg-base-dn", "o=airius.com"); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.meta.GlobalCfgDefn.DisabledPrivilege; |
| | | import org.opends.server.admin.std.meta.RootDNCfgDefn; |
| | |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.Requests; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | 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.LDAPModify; |
| | | import org.opends.server.tools.LDAPPasswordModify; |
| | | import org.opends.server.tools.LDAPReader; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.tools.LDAPWriter; |
| | | import org.opends.server.tools.RemoteConnection; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.CONFIG_WRITE, null), hasPrivilege); |
| | | |
| | | List<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("ds-cfg-size-limit", "2000"))); |
| | | |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.valueOf("cn=config"), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest("cn=config") |
| | | .addModification(REPLACE, "ds-cfg-size-limit", "2000"); |
| | | ModifyOperation modifyOperation = conn.processModify(modifyRequest); |
| | | assertPrivilege(modifyOperation.getResultCode(), hasPrivilege); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("ds-cfg-size-limit", "1000"))); |
| | | |
| | | modifyOperation = conn.processModify(DN.valueOf("cn=config"), mods); |
| | | modifyRequest = newModifyRequest("cn=config") |
| | | .addModification(REPLACE, "ds-cfg-size-limit", "1000"); |
| | | modifyOperation = conn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | assertEquals(conn.hasPrivilege(Privilege.SUBENTRY_WRITE, null), |
| | | hasPrivilege); |
| | | |
| | | List<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("subtreeSpecification", |
| | | "{base \"ou=doesnotexist\"}"))); |
| | | |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.valueOf("cn=Subentry Target,o=test"), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest("cn=Subentry Target,o=test") |
| | | .addModification(REPLACE, "subtreeSpecification", "{base \"ou=doesnotexist\"}"); |
| | | ModifyOperation modifyOperation = conn.processModify(modifyRequest); |
| | | assertPrivilege(modifyOperation.getResultCode(), hasPrivilege); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("subtreeSpecification", "{}"))); |
| | | |
| | | modifyOperation = conn.processModify( |
| | | DN.valueOf("cn=Subentry Target,o=test"), mods); |
| | | modifyRequest = newModifyRequest("cn=Subentry Target,o=test") |
| | | .addModification(REPLACE, "subtreeSpecification", "{}"); |
| | | modifyOperation = conn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE " + |
| | | "X-ORIGIN 'PrivilegeTestCase' )"; |
| | | |
| | | List<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.ADD, |
| | | Attributes.create("attributetypes", attrDefinition))); |
| | | |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.valueOf("cn=schema"), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest("cn=schema") |
| | | .addModification(ADD, "attributetypes", attrDefinition); |
| | | ModifyOperation modifyOperation = conn.processModify(modifyRequest); |
| | | assertPrivilege(modifyOperation.getResultCode(), hasPrivilege); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.DELETE, |
| | | Attributes.create("attributetypes", attrDefinition))); |
| | | |
| | | modifyOperation = conn.processModify(DN.valueOf("cn=schema"), mods); |
| | | modifyRequest = newModifyRequest("cn=schema") |
| | | .addModification(DELETE, "attributetypes", attrDefinition); |
| | | modifyOperation = conn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | // Try to modify the entry to add a description. |
| | | List<Modification> mods = new ArrayList<>(1); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("description", "foo"))); |
| | | |
| | | ModifyOperation modifyOperation = new ModifyOperationBasis(conn, nextOperationID(), nextMessageID(), |
| | | controls, e.getName(), mods); |
| | | modifyOperation.run(); |
| | | List<Modification> mods = newModifications(REPLACE, "description", "foo"); |
| | | ModifyOperation modifyOperation = runModifyOperation(conn, e, controls, mods); |
| | | assertProxyPrivilege(modifyOperation.getResultCode(), hasProxyPrivilege); |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private List<Modification> newModifications(ModificationType modType, String attrName, String attrValue) |
| | | { |
| | | return newArrayList(new Modification(modType, Attributes.create(attrName, attrValue))); |
| | | } |
| | | |
| | | /** |
| | | * Tests to ensure that the use of the Directory Server will properly respect |
| | |
| | | } |
| | | |
| | | |
| | | // Try to modify the entry to add a description. |
| | | List<Modification> mods = new ArrayList<>(1); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("description", "foo"))); |
| | | |
| | | ModifyOperation modifyOperation = |
| | | new ModifyOperationBasis(conn, nextOperationID(), nextMessageID(), |
| | | controls, e.getName(), mods); |
| | | modifyOperation.run(); |
| | | List<Modification> mods = newModifications(REPLACE, "description", "foo"); |
| | | ModifyOperation modifyOperation = runModifyOperation(conn, e, controls, mods); |
| | | assertProxyPrivilege(modifyOperation.getResultCode(), hasProxyPrivilege); |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private ModifyOperation runModifyOperation(InternalClientConnection conn, Entry e, List<Control> controls, |
| | | List<Modification> mods) |
| | | { |
| | | ModifyOperation op = |
| | | new ModifyOperationBasis(conn, nextOperationID(), nextMessageID(), controls, e.getName(), mods); |
| | | op.run(); |
| | | return op; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | // We won't use an internal connection here because these are not notified |
| | | // of dynamic changes to authentication info. |
| | | try (Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort())) |
| | | try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort())) |
| | | { |
| | | TestCaseUtils.configureSocket(s); |
| | | LDAPReader r = new LDAPReader(s); |
| | | LDAPWriter w = new LDAPWriter(s); |
| | | |
| | | BindRequestProtocolOp bindRequest = new BindRequestProtocolOp( |
| | | ByteString.valueOfUtf8("cn=Test User,o=test"), 3, |
| | | ByteString.valueOfUtf8("password")); |
| | | LDAPMessage message = new LDAPMessage(1, bindRequest); |
| | | w.writeMessage(message); |
| | | |
| | | message = r.readMessage(); |
| | | BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp(); |
| | | assertEquals(bindResponse.getResultCode(), 0); |
| | | conn.bind("cn=Test User,o=test", "password"); |
| | | |
| | | CopyOnWriteArraySet<ClientConnection> connections = DirectoryServer |
| | | .getAuthenticatedUsers().get(DN.valueOf("cn=Test User,o=test")); |
| | |
| | | |
| | | // Modify the user entry to add the CONFIG_READ privilege and verify that |
| | | // the client connection reflects that. |
| | | List<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.ADD, Attributes.create( |
| | | "ds-privilege-name", "config-read"))); |
| | | ModifyOperation modifyOperation = rootConnection.processModify( |
| | | DN.valueOf("cn=Test User,o=test"), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest("cn=Test User,o=test") |
| | | .addModification(ADD, "ds-privilege-name", "config-read"); |
| | | ModifyOperation modifyOperation = rootConnection.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertTrue(testConnection.hasPrivilege(Privilege.CONFIG_READ, null)); |
| | | |
| | | // Take the privilege away from the user and verify that it is recognized |
| | | // immediately. |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.DELETE, Attributes.create( |
| | | "ds-privilege-name", "config-read"))); |
| | | modifyOperation = rootConnection.processModify( |
| | | DN.valueOf("cn=Test User,o=test"), mods); |
| | | modifyRequest = newModifyRequest("cn=Test User,o=test") |
| | | .addModification(DELETE, "ds-privilege-name", "config-read"); |
| | | modifyOperation = rootConnection.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | assertFalse(testConnection.hasPrivilege(Privilege.CONFIG_READ, null)); |
| | | |
| | |
| | | // Update the set of root privileges to include proxied auth. |
| | | InternalClientConnection internalRootConn = getRootConnection(); |
| | | |
| | | List<Modification> mods = new ArrayList<>(); |
| | | mods.add(new Modification(ModificationType.ADD, |
| | | Attributes.create("ds-cfg-default-root-privilege-name", |
| | | "proxied-auth"))); |
| | | ModifyOperation modifyOperation = internalRootConn.processModify(DN.valueOf("cn=Root DNs,cn=config"), mods); |
| | | ModifyRequest modifyRequest = newModifyRequest("cn=Root DNs,cn=config") |
| | | .addModification(ADD, "ds-cfg-default-root-privilege-name", "proxied-auth"); |
| | | ModifyOperation modifyOperation = internalRootConn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | |
| | | |
| | | |
| | | // Update the set of root privileges to revoke proxied auth. |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.DELETE, |
| | | Attributes.create("ds-cfg-default-root-privilege-name", |
| | | "proxied-auth"))); |
| | | modifyOperation = internalRootConn.processModify(DN.valueOf("cn=Root DNs,cn=config"), mods); |
| | | modifyRequest = newModifyRequest("cn=Root DNs,cn=config") |
| | | .addModification(DELETE, "ds-cfg-default-root-privilege-name", "proxied-auth"); |
| | | modifyOperation = internalRootConn.processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.workflowelement.localbackend; |
| | | |
| | | import java.util.ArrayList; |
| | | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.opends.server.DirectoryServerTestCase; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.SearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Modification; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * This set of tests test the LocalBackendWorkflowElement. |
| | | */ |
| | | /** This set of tests test the LocalBackendWorkflowElement. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class LocalBackendWorkflowElementTest extends DirectoryServerTestCase |
| | | { |
| | |
| | | |
| | | // Add a new suffix in the backend and create a base entry for the new suffix |
| | | String backendConfigDN = "ds-cfg-backend-id=userRoot," + DN_BACKEND_BASE; |
| | | modifyAttribute(backendConfigDN, ModificationType.ADD, backendBaseDNName, suffix2); |
| | | modifyAttribute(backendConfigDN, ADD, backendBaseDNName, suffix2); |
| | | addBaseEntry(suffix2, "workflow suffix"); |
| | | |
| | | // Both old and new suffix should be accessible. |
| | |
| | | searchEntry(suffix2, ResultCode.SUCCESS); |
| | | |
| | | // Remove the new suffix... |
| | | modifyAttribute(backendConfigDN, ModificationType.DELETE, backendBaseDNName, suffix2); |
| | | modifyAttribute(backendConfigDN, DELETE, backendBaseDNName, suffix2); |
| | | |
| | | // ...and check that the removed suffix is no more accessible. |
| | | searchEntry(suffix, ResultCode.SUCCESS); |
| | | searchEntry(suffix2, ResultCode.NO_SUCH_OBJECT); |
| | | |
| | | // Replace the suffix with suffix2 in the backend |
| | | modifyAttribute(backendConfigDN, ModificationType.REPLACE, backendBaseDNName, suffix2); |
| | | modifyAttribute(backendConfigDN, REPLACE, backendBaseDNName, suffix2); |
| | | |
| | | // Now none of the suffixes are accessible: this means the entries |
| | | // under the old suffix are not moved to the new suffix. |
| | |
| | | searchEntry(suffix2, ResultCode.SUCCESS); |
| | | |
| | | // Reset the configuration with previous suffix |
| | | modifyAttribute(backendConfigDN, ModificationType.REPLACE, backendBaseDNName, suffix); |
| | | modifyAttribute(backendConfigDN, REPLACE, backendBaseDNName, suffix); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param baseDN the request base DN string |
| | | * @param modType the modification type (add/delete/replace) |
| | | * @param attributeName the name of the attribute to add/delete/replace |
| | | * @param attributeValue the value of the attribute to add/delete/replace |
| | | * @param attrName the name of the attribute to add/delete/replace |
| | | * @param attrValue the value of the attribute to add/delete/replace |
| | | */ |
| | | private void modifyAttribute(String baseDN, ModificationType modType, String attributeName, String attributeValue) |
| | | private void modifyAttribute(String baseDN, ModificationType modType, String attrName, String attrValue) |
| | | throws Exception |
| | | { |
| | | ArrayList<Modification> mods = new ArrayList<>(); |
| | | Attribute attributeToModify = Attributes.create(attributeName, attributeValue); |
| | | mods.add(new Modification(modType, attributeToModify)); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(DN.valueOf(baseDN), mods); |
| | | ModifyRequest modifyRequest = Requests.newModifyRequest(baseDN) |
| | | .addModification(modType, attrName, attrValue); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |