001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.server.core.trigger; 021 022 023import java.util.Map; 024 025import org.apache.directory.api.ldap.model.constants.SchemaConstants; 026import org.apache.directory.api.ldap.model.entry.Entry; 027import org.apache.directory.api.ldap.model.exception.LdapException; 028import org.apache.directory.api.ldap.model.name.Dn; 029import org.apache.directory.api.ldap.trigger.StoredProcedureParameter; 030import org.apache.directory.server.core.api.CoreSession; 031import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext; 032import org.apache.directory.server.core.api.interceptor.context.OperationContext; 033 034 035public class DeleteStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector 036{ 037 private Dn deletedEntryName; 038 private Entry deletedEntry; 039 040 041 public DeleteStoredProcedureParameterInjector( OperationContext opContext, Dn deletedEntryName ) 042 throws LdapException 043 { 044 super( opContext ); 045 this.deletedEntryName = deletedEntryName; 046 this.deletedEntry = getDeletedEntry( opContext ); 047 Map<Class<?>, MicroInjector> injectors = super.getInjectors(); 048 injectors.put( StoredProcedureParameter.Delete_NAME.class, nameInjector ); 049 injectors.put( StoredProcedureParameter.Delete_DELETED_ENTRY.class, deletedEntryInjector ); 050 } 051 052 MicroInjector nameInjector = new MicroInjector() 053 { 054 public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException 055 { 056 // Return a safe copy constructed with user provided name. 057 return opContext.getSession().getDirectoryService().getDnFactory().create( deletedEntryName.getName() ); 058 } 059 }; 060 061 MicroInjector deletedEntryInjector = new MicroInjector() 062 { 063 public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException 064 { 065 return deletedEntry; 066 } 067 }; 068 069 070 private Entry getDeletedEntry( OperationContext opContext ) throws LdapException 071 { 072 /** 073 * Using LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS here to exclude operational attributes 074 * especially subentry related ones like "triggerExecutionSubentries". 075 */ 076 CoreSession session = opContext.getSession(); 077 LookupOperationContext lookupContext = new LookupOperationContext( session, deletedEntryName, 078 SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY ); 079 lookupContext.setPartition( opContext.getPartition() ); 080 lookupContext.setTransaction( opContext.getTransaction() ); 081 082 return session.getDirectoryService().getPartitionNexus().lookup( lookupContext ); 083 } 084}