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.exception.LdapInvalidDnException; 026import org.apache.directory.api.ldap.model.name.Dn; 027import org.apache.directory.api.ldap.model.name.Rdn; 028import org.apache.directory.api.ldap.trigger.StoredProcedureParameter; 029import org.apache.directory.server.core.api.interceptor.context.OperationContext; 030 031 032public class ModifyDNStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector 033{ 034 private boolean deleteOldRn; 035 private Rdn oldRdn; 036 private Rdn newRdn; 037 private Dn oldSuperiorDn; 038 private Dn newSuperiorDn; 039 private Dn oldDn; 040 private Dn newDn; 041 042 043 public ModifyDNStoredProcedureParameterInjector( OperationContext opContext, boolean deleteOldRn, 044 Rdn oldRDN, Rdn newRdn, Dn oldSuperiorDn, Dn newSuperiorDn, Dn oldDn, Dn newDn ) 045 { 046 super( opContext ); 047 this.deleteOldRn = deleteOldRn; 048 this.oldRdn = oldRDN.clone(); 049 this.newRdn = newRdn.clone(); 050 this.oldSuperiorDn = oldSuperiorDn; 051 this.newSuperiorDn = newSuperiorDn; 052 this.oldDn = oldDn; 053 this.newDn = newDn; 054 055 Map<Class<?>, MicroInjector> injectors = super.getInjectors(); 056 injectors.put( StoredProcedureParameter.ModifyDN_ENTRY.class, entryInjector ); 057 injectors.put( StoredProcedureParameter.ModifyDN_NEW_RDN.class, newrdnInjector ); 058 injectors.put( StoredProcedureParameter.ModifyDN_DELETE_OLD_RDN.class, deleteoldrdnInjector ); 059 injectors.put( StoredProcedureParameter.ModifyDN_NEW_SUPERIOR.class, newSuperiorInjector ); 060 injectors.put( StoredProcedureParameter.ModifyDN_OLD_RDN.class, oldRDNInjector ); 061 injectors.put( StoredProcedureParameter.ModifyDN_OLD_SUPERIOR_DN.class, oldSuperiorDNInjector ); 062 injectors.put( StoredProcedureParameter.ModifyDN_NEW_DN.class, newDNInjector ); 063 064 } 065 066 /** 067 * Injector for 'entry' parameter of ModifyDNRequest as in RFC4511. 068 */ 069 MicroInjector entryInjector = new MicroInjector() 070 { 071 public Object inject( OperationContext opContext, StoredProcedureParameter param ) 072 throws LdapInvalidDnException 073 { 074 // Return a safe copy constructed with user provided name. 075 return opContext.getSession().getDirectoryService().getDnFactory().create( oldDn.getName() ); 076 } 077 }; 078 079 /** 080 * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511. 081 */ 082 MicroInjector newrdnInjector = new MicroInjector() 083 { 084 public Object inject( OperationContext opContext, StoredProcedureParameter param ) 085 throws LdapInvalidDnException 086 { 087 // Return a safe copy constructed with user provided name. 088 return opContext.getSession().getDirectoryService().getDnFactory().create( newRdn.getName() ); 089 } 090 }; 091 092 /** 093 * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511. 094 */ 095 MicroInjector deleteoldrdnInjector = new MicroInjector() 096 { 097 public Object inject( OperationContext opContext, StoredProcedureParameter param ) 098 throws LdapInvalidDnException 099 { 100 // Return a safe copy constructed with user provided name. 101 return deleteOldRn; 102 } 103 }; 104 105 /** 106 * Injector for 'newSuperior' parameter of ModifyDNRequest as in RFC4511. 107 */ 108 MicroInjector newSuperiorInjector = new MicroInjector() 109 { 110 public Object inject( OperationContext opContext, StoredProcedureParameter param ) 111 throws LdapInvalidDnException 112 { 113 // Return a safe copy constructed with user provided name. 114 return opContext.getSession().getDirectoryService().getDnFactory().create( newSuperiorDn.getName() ); 115 } 116 }; 117 118 /** 119 * Extra injector for 'oldRdn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511. 120 */ 121 MicroInjector oldRDNInjector = new MicroInjector() 122 { 123 public Object inject( OperationContext opContext, StoredProcedureParameter param ) 124 throws LdapInvalidDnException 125 { 126 // Return a safe copy constructed with user provided name. 127 return opContext.getSession().getDirectoryService().getDnFactory().create( oldRdn.getName() ); 128 } 129 }; 130 131 /** 132 * Extra injector for 'oldRdn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511. 133 */ 134 MicroInjector oldSuperiorDNInjector = new MicroInjector() 135 { 136 public Object inject( OperationContext opContext, StoredProcedureParameter param ) 137 throws LdapInvalidDnException 138 { 139 // Return a safe copy constructed with user provided name. 140 return opContext.getSession().getDirectoryService().getDnFactory().create( oldSuperiorDn.getName() ); 141 } 142 }; 143 144 /** 145 * Extra injector for 'newDn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511. 146 */ 147 MicroInjector newDNInjector = new MicroInjector() 148 { 149 public Object inject( OperationContext opContext, StoredProcedureParameter param ) 150 throws LdapInvalidDnException 151 { 152 // Return a safe copy constructed with user provided name. 153 return opContext.getSession().getDirectoryService().getDnFactory().create( newDn.getName() ); 154 } 155 }; 156 157}