Commit 1477cc9f authored by Shawn McKinney's avatar Shawn McKinney
Browse files

cleanup modrdn. Add options to move dn, newrdn. Add props for relax and managedsa controls

parent 383e867b
......@@ -40,5 +40,8 @@ trust.store.onclasspath=true
# Set to true to send relax control on adds/updates (for testing lloadd):
relax.control=false
# Set to true to send managedsa control on updates:
managedsa.control=false
# This property is required and must be valid DN (format) but isn't used:
config.root=ou=NotUsed,o=empty
......@@ -219,6 +219,8 @@
<name>${name}</name>
<password>${password}</password>
<newpassword>${newpassword}</newpassword>
<newrdn>${newrdn}</newrdn>
<newdn>${newdn}</newdn>
</propertiesSystem>
<jMeterProcessJVMSettings>
<xms>1024</xms>
......
/* Copyright (c) 2022 by Symas Corporation. */
package com.symas;
import org.apache.commons.lang.StringUtils;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.directory.fortress.core.model.User;
......@@ -51,10 +52,9 @@ public class AddUser extends LoadBase
}
if ( modrdn > 0 && count > modrdn && ( count % modrdn ) == 0 )
{
String oldUserId = user.getUserId();
String newUserId = user.getUserId() + "-modrdn";
warn( "MODRDN[" + count + "]: old userId: " + user.getUserId() + ", new userId: " + newUserId );
outUser = userImpl.modRdn( user, user.getUserId(), false );
String szNewRdn = StringUtils.isNotEmpty( newrdn) ? newrdn : user.getUserId();
warn( "MODRDN[" + count + "]: userId: " + user.getUserId() + " newUserId: " + szNewRdn + " newDn: " + newdn );
outUser = userImpl.modRdn( user, szNewRdn, newdn );
assertNotNull( outUser );
}
if ( verify )
......
......@@ -9,4 +9,7 @@ public class Ids
public static final boolean IS_RELAX_CONTROL = StringUtils.isNotEmpty( Config.getInstance().getProperty( "relax.control" ) )
? Config.getInstance().getBoolean( "relax.control" )
: false;
public static final boolean IS_MANAGE_CONTROL = StringUtils.isNotEmpty( Config.getInstance().getProperty( "managedsa.control" ) )
? Config.getInstance().getBoolean( "managedsa.control" )
: false;
}
......@@ -38,6 +38,8 @@ public abstract class LoadBase extends AbstractJavaSamplerClient
protected String name;
protected String password;
protected String newpassword;
protected String newrdn;
protected String newdn;
protected boolean verify = false;
protected boolean output = false;
protected boolean update = false;
......@@ -277,6 +279,8 @@ public abstract class LoadBase extends AbstractJavaSamplerClient
{
newpassword = samplerContext.getParameter( "newpassword" );
}
newrdn = System.getProperty( "newrdn" );
newdn = System.getProperty( "newdn" );
filename = "operations" + '-' + "thread" + getThreadId() + '-' + hostname + '-' + qualifier + ".txt";
open();
}
......
/* Copyright (c) 2022 by Symas Corporation. */
package com.symas;
import org.apache.commons.lang.StringUtils;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.fortress.core.GlobalIds;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.directory.fortress.core.model.User;
......@@ -34,28 +37,12 @@ public class ModUser extends LoadBase
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
write( "threadid: " + getThreadId() + ", userId: " + userId );
User outUser;
boolean isModRdn = false;
if ( modrdn > 0 && count > modrdn && ( count % modrdn ) == 0 )
{
isModRdn = true;
warn( "MODRDN[" + count + "]: userId: " + user.getUserId() );
outUser = userImpl.modRdn( user, user.getUserId(), false );
String szNewRdn = StringUtils.isNotEmpty( newrdn) ? newrdn : user.getUserId();
warn( "MODRDN[" + count + "]: userId: " + user.getUserId() + " newUserId: " + szNewRdn + " newDn: " + newdn );
outUser = userImpl.modRdn( user, szNewRdn, newdn );
assertNotNull( outUser );
user.setDescription( "moved rdn: " + user.getUserId() + ": " + timestamp);
user.setCn( user.getUserId() + "mod1");
user.setPhone("867-5309");
outUser = userImpl.update( user );
outUser = userImpl.modRdn( user, user.getUserId(), true );
if ( duplicate > 0 && count > duplicate && ( count % duplicate ) == 0 )
{
warn("DUPLICATE ModRdn[" + count + "]: " + user.getUserId());
outUser = userImpl.modRdn( user, user.getUserId(), true );
}
user.setDescription( "moved dn: " + user.getUserId() + ": " + timestamp);
user.setCn( user.getUserId() + "mod2");
user.setEmail(user.getUserId() + "@foo.com");
user.setPhone("1-800-123-4567");
outUser = userImpl.update2( user );
}
else
{
......@@ -67,7 +54,7 @@ public class ModUser extends LoadBase
}
// This tests replication, ability to handle conflicts:
if ( !isModRdn && duplicate > 0 && count > duplicate && ( count % duplicate ) == 0 )
if ( duplicate > 0 && count > duplicate && ( count % duplicate ) == 0 )
{
warn( "DUPLICATE Mod[" + count + "]: " + user.getUserId() );
user.setDescription( "mod twice: " + user.getUserId() + ": " + timestamp);
......
......@@ -261,86 +261,16 @@ final class UserImpl extends LdapDataProvider
if ( mods.size() > 0 )
{
ld = getAdminConnection();
modify2( ld, userDn, mods, entity, Ids.IS_RELAX_CONTROL );
// modify( ld, userDn, mods, entity, Ids.IS_RELAX_CONTROL );
entity.setDn( userDn );
}
entity.setDn( userDn );
}
catch ( LdapException e )
{
String error = "update userId [" + entity.getUserId() + "] caught LDAPException=" + e;
throw new UpdateException( GlobalErrIds.USER_UPDATE_FAILED, error, e );
}
finally
{
closeAdminConnection( ld );
}
return entity;
}
User update2( User entity ) throws UpdateException
{
LdapConnection ld = null;
//String userDn = getDn( entity.getUserId() );
String userDn = SchemaConstants.UID_AT + "=" + entity.getUserId() + "," + "ou=people2,dc=example,dc=com";
try
{
List<Modification> mods = new ArrayList<Modification>();
if ( StringUtils.isNotEmpty( entity.getCn() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.CN_AT,
entity.getCn() ) );
}
if ( StringUtils.isNotEmpty( entity.getSn() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.SN_AT,
entity.getSn() ) );
}
if ( StringUtils.isNotEmpty( entity.getOu() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.OU_AT,
entity.getOu() ) );
}
if ( StringUtils.isNotEmpty( entity.getPassword() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants
.USER_PASSWORD_AT, entity.getPassword() ) );
}
if ( StringUtils.isNotEmpty( entity.getDescription() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants
.DESCRIPTION_AT, entity.getDescription() ) );
}
if ( StringUtils.isNotEmpty( entity.getEmployeeType() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, EMPLOYEE_TYPE, entity
.getEmployeeType() ) );
}
if ( StringUtils.isNotEmpty( entity.getDisplayName() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DISPLAY_NAME_AT, entity.getDisplayName() ) );
}
if ( StringUtils.isNotEmpty( entity.getTitle() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.TITLE_AT,
entity.getTitle() ) );
}
loadAddress( entity.getAddress(), mods );
// These are multi-valued attributes, use the util function to load:
loadAttrs( entity.getPhones(), mods, SchemaConstants.TELEPHONE_NUMBER_AT );
loadAttrs( entity.getMobiles(), mods, MOBILE );
loadAttrs( entity.getEmails(), mods, SchemaConstants.MAIL_AT );
if ( ArrayUtils.isNotEmpty( entity.getJpegPhoto() ) )
{
mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, JPEGPHOTO, entity
.getJpegPhoto() ) );
}
if ( mods.size() > 0 )
{
ld = getAdminConnection();
modify2( ld, userDn, mods, entity, Ids.IS_RELAX_CONTROL );
Control setControl = null;
if ( Ids.IS_MANAGE_CONTROL )
{
setControl = new ManageDsaITImpl();
}
else if ( Ids.IS_RELAX_CONTROL )
{
setControl = new RelaxControlImpl();
}
modify( ld, userDn, mods, setControl );
entity.setDn( userDn );
}
entity.setDn( userDn );
......@@ -357,22 +287,41 @@ final class UserImpl extends LdapDataProvider
return entity;
}
protected void modify2( LdapConnection connection, String dn, List<Modification> mods,
FortEntity entity, boolean setRelaxControl ) throws LdapException
/**
* Update exiting ldap entry to the directory. Add audit context.
*
* @param connection handle to ldap connection.
* @param dn contains distinguished node of entry.
* @param mods contains data to modify.
* @param setControl add specified control to the request
* @throws LdapException in the event system error occurs.
*/
protected void modify( LdapConnection connection, String dn, List<Modification> mods, Control setControl ) throws LdapException
{
ModifyRequest modRequest = new ModifyRequestImpl();
// TODO: find a better way:
for( Modification mod : mods )
{
modRequest.addModification( mod );
}
modRequest.addControl( new ManageDsaITImpl());
if ( setControl != null )
{
modRequest.addControl( setControl );
}
modRequest.setName( new Dn( dn ) );
ModifyResponse response = connection.modify( modRequest );
ResultCodeEnum.processResponse(response);
}
User modRdn( User entity, String newUserId, boolean isMove ) throws UpdateException
/**
* Modifies RDN and optionally moves to new parent DN
* @param entity Contains the old userId
* @param szNewUserId contains the new userid (they can be the same)
* @param szNewDn If movedn, cotains the rdn of parent entry, e.g. ou=People2
* @return
* @throws UpdateException
*/
User modRdn( User entity, String szNewUserId, String szNewDn ) throws UpdateException
{
LdapConnection ld = null;
try
......@@ -380,22 +329,25 @@ final class UserImpl extends LdapDataProvider
ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
Dn oldDn = new Dn( getDn( entity.getUserId() ) );
modDnRequest.setName( oldDn );
Rdn newRdn = new Rdn( "uid=" + newUserId );
Rdn newRdn = new Rdn( SchemaConstants.UID_AT + "=" + szNewUserId );
modDnRequest.setNewRdn( newRdn );
modDnRequest.setDeleteOldRdn(true);
if(isMove)
if(StringUtils.isNotEmpty( szNewDn ))
{
Dn newDn = new Dn( "ou=people2, dc=example,dc=com" );
Dn newDn = new Dn( szNewDn + "," + getRootDn( GlobalIds.HOME, GlobalIds.SUFFIX ) );
modDnRequest.setNewSuperior( newDn );
}
modDnRequest.addControl( new ManageDsaITImpl());
if ( Ids.IS_MANAGE_CONTROL )
{
modDnRequest.addControl( new ManageDsaITImpl());
}
ld = getAdminConnection();
ModifyDnResponse response = ld.modifyDn(modDnRequest);
ResultCodeEnum.processResponse(response);
}
catch ( LdapException e )
{
String error = "modRdn userId [" + entity.getUserId() + "], newUserId [" + newUserId + "], isMove: " + isMove + ", caught LDAPException=" + e;
String error = "modRdn userId [" + entity.getUserId() + "], newUserId [" + szNewUserId + "], newDn: " + szNewDn + ", caught LDAPException=" + e;
throw new UpdateException( GlobalErrIds.USER_UPDATE_FAILED, error, e );
}
finally
......@@ -405,6 +357,7 @@ final class UserImpl extends LdapDataProvider
return entity;
}
/**
* @param user
* @throws RemoveException
......@@ -922,6 +875,11 @@ final class UserImpl extends LdapDataProvider
return SchemaConstants.UID_AT + "=" + userId + "," + getRootDn( GlobalIds.HOME, GlobalIds.USER_ROOT );
}
static String getNewDn( String userId, String newRdn )
{
return SchemaConstants.UID_AT + "=" + userId + "," + newRdn + "," + getRootDn( GlobalIds.HOME, GlobalIds.SUFFIX );
}
/**
* The Fortress User entity attributes are stored within standard LDAP object classes along with custom auxiliary
* object classes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment