// Check if we have a modified subentry attribute in a Subentry entry
if ( containsSubentryOC && isSubtreeSpecificationModification )
{
Subentry subentry = directoryService.getSubentryCache().removeSubentry( dn );
SubtreeSpecification ssOld = subentry.getSubtreeSpecification();
SubtreeSpecification ssNew;
try
{
ssNew = ssParser.parse( subtreeMod.getAttribute().getString() );
}
catch ( Exception e )
{
String msg = I18n.err( I18n.ERR_71 );
LOG.error( msg, e );
throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg );
}
subentry.setSubtreeSpecification( ssNew );
subentry.setAdministrativeRoles( getSubentryTypes( entry, modifications ) );
directoryService.getSubentryCache().addSubentry( dn, subentry );
next( modifyContext );
// search for all entries selected by the old SS and remove references to subentry
Dn apName = dn.getParent();
Dn oldBaseDn = apName;
oldBaseDn = oldBaseDn.add( ssOld.getBase() );
ExprNode filter = new PresenceNode( OBJECT_CLASS_AT );
SearchControls controls = new SearchControls();
controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
controls.setReturningAttributes( new String[]
{ SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES, SchemaConstants.ALL_USER_ATTRIBUTES } );
SearchOperationContext searchOperationContext = new SearchOperationContext( modifyContext.getSession(),
oldBaseDn, filter, controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
EntryFilteringCursor subentries = nexus.search( searchOperationContext );
try
{
while ( subentries.next() )
{
Entry candidate = subentries.get();
Dn candidateDn = candidate.getDn();
if ( directoryService.getEvaluator().evaluate( ssOld, apName, candidateDn, candidate ) )
{
nexus.modify( new ModifyOperationContext( modifyContext.getSession(), candidateDn,
getOperationalModsForRemove( dn, candidate ) ) );
}
}
subentries.close();
}
catch ( Exception e )
{
throw new LdapOperationErrorException( e.getMessage(), e );
}
finally
{
try
{
subentries.close();
}
catch ( Exception e )
{
LOG.error( I18n.err( I18n.ERR_168 ), e );
}
}
// search for all selected entries by the new SS and add references to subentry
subentry = directoryService.getSubentryCache().getSubentry( dn );
List<Attribute> operationalAttributes = getSubentryOperationalAttributes( dn, subentry );
Dn newBaseDn = apName;
newBaseDn = newBaseDn.add( ssNew.getBase() );
searchOperationContext = new SearchOperationContext( modifyContext.getSession(), newBaseDn, filter,
controls );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );