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     */
020    package org.apache.directory.server.core;
021    
022    
023    import java.net.SocketAddress;
024    import java.util.ArrayList;
025    import java.util.List;
026    import java.util.Set;
027    
028    import org.apache.directory.server.constants.ServerDNConstants;
029    import org.apache.directory.server.core.changelog.LogChange;
030    import org.apache.directory.server.core.entry.ClonedServerEntry;
031    import org.apache.directory.server.core.filtering.EntryFilteringCursor;
032    import org.apache.directory.server.core.interceptor.context.AbstractOperationContext;
033    import org.apache.directory.server.core.interceptor.context.AddOperationContext;
034    import org.apache.directory.server.core.interceptor.context.CompareOperationContext;
035    import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
036    import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
037    import org.apache.directory.server.core.interceptor.context.ListOperationContext;
038    import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
039    import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
040    import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
041    import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
042    import org.apache.directory.server.core.interceptor.context.OperationContext;
043    import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
044    import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
045    import org.apache.directory.server.core.interceptor.context.UnbindOperationContext;
046    import org.apache.directory.server.i18n.I18n;
047    import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
048    import org.apache.directory.shared.ldap.entry.BinaryValue;
049    import org.apache.directory.shared.ldap.entry.StringValue;
050    import org.apache.directory.shared.ldap.entry.Modification;
051    import org.apache.directory.shared.ldap.entry.ServerEntry;
052    import org.apache.directory.shared.ldap.entry.ServerModification;
053    import org.apache.directory.shared.ldap.entry.Value;
054    import org.apache.directory.shared.ldap.exception.LdapException;
055    import org.apache.directory.shared.ldap.filter.ExprNode;
056    import org.apache.directory.shared.ldap.filter.FilterParser;
057    import org.apache.directory.shared.ldap.filter.SearchScope;
058    import org.apache.directory.shared.ldap.message.AliasDerefMode;
059    import org.apache.directory.shared.ldap.message.control.Control;
060    import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
061    import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
062    import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
063    import org.apache.directory.shared.ldap.message.internal.InternalModifyDnRequest;
064    import org.apache.directory.shared.ldap.message.internal.InternalModifyRequest;
065    import org.apache.directory.shared.ldap.message.internal.InternalSearchRequest;
066    import org.apache.directory.shared.ldap.message.internal.InternalUnbindRequest;
067    import org.apache.directory.shared.ldap.name.DN;
068    import org.apache.directory.shared.ldap.name.RDN;
069    import org.apache.directory.shared.ldap.schema.AttributeType;
070    import org.apache.directory.shared.ldap.schema.AttributeTypeOptions;
071    import org.apache.directory.shared.ldap.util.StringTools;
072    
073    
074    /**
075     * The default CoreSession implementation.
076     * 
077     * TODO - has not been completed yet
078     * TODO - need to supply controls and other parameters to setup opContexts
079     *
080     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
081     * @version $Rev$, $Date$
082     */
083    public class MockCoreSession implements CoreSession
084    {
085        private DirectoryService directoryService;
086        private final LdapPrincipal authenticatedPrincipal;
087        private LdapPrincipal authorizedPrincipal;
088        
089        
090        public MockCoreSession( LdapPrincipal principal, DirectoryService directoryService )
091        {
092            this.directoryService = directoryService;
093            this.authenticatedPrincipal = principal;
094        }
095    
096        
097        /**
098         * Set the ignoreRefferal flag for the current operationContext.
099         *
100         * @param opContext The current operationContext
101         * @param ignoreReferral The flag 
102         */
103        private void setReferralHandling( AbstractOperationContext opContext, boolean ignoreReferral )
104        {
105            if ( ignoreReferral )
106            {
107                opContext.ignoreReferral();
108            }
109            else
110            {
111                opContext.throwReferral();
112            }
113        }
114        
115        
116        /**
117         * {@inheritDoc} 
118         */
119        public void add( ServerEntry entry ) throws Exception
120        {
121            add( entry, LogChange.TRUE );
122        }
123    
124    
125        /**
126         * {@inheritDoc} 
127         */
128        public void add( ServerEntry entry, boolean ignoreReferral ) throws Exception
129        {
130            add( entry, ignoreReferral, LogChange.TRUE );
131        }
132    
133    
134        /**
135         * {@inheritDoc} 
136         */
137        public void add( ServerEntry entry, LogChange log ) throws Exception
138        {
139            AddOperationContext opContext = new AddOperationContext( this, entry );
140    
141            opContext.setLogChange( log );
142            
143            OperationManager operationManager = directoryService.getOperationManager();
144            operationManager.add( opContext );
145        }
146    
147    
148        /**
149         * {@inheritDoc} 
150         */
151        public void add( ServerEntry entry, boolean ignoreReferral, LogChange log ) throws Exception
152        {
153            AddOperationContext opContext = new AddOperationContext( this, entry );
154    
155            opContext.setLogChange( log );
156            setReferralHandling( opContext, ignoreReferral );
157            
158            OperationManager operationManager = directoryService.getOperationManager();
159            operationManager.add( opContext );
160        }
161    
162    
163        /**
164         * {@inheritDoc} 
165         */
166        public void add( InternalAddRequest addRequest ) throws Exception
167        {
168            add( addRequest, LogChange.TRUE );
169        }
170    
171        
172        /**
173         * {@inheritDoc} 
174         */
175        public void add( InternalAddRequest addRequest, LogChange log ) throws Exception
176        {
177            AddOperationContext opContext = new AddOperationContext( this, addRequest );
178    
179            opContext.setLogChange( log );
180            
181            OperationManager operationManager = directoryService.getOperationManager();
182            operationManager.add( opContext );
183            addRequest.getResultResponse().addAll( opContext.getResponseControls() );
184        }
185    
186        
187        private Value<?> convertToValue( String oid, Object value ) throws LdapException
188        {
189            Value<?> val = null;
190            
191            AttributeType attributeType = directoryService.getSchemaManager().lookupAttributeTypeRegistry( oid );
192            
193            // make sure we add the request controls to operation
194            if ( attributeType.getSyntax().isHumanReadable() )
195            {
196                if ( value instanceof String )
197                {
198                    val = new StringValue( attributeType, (String)value );
199                }
200                else if ( value instanceof byte[] )
201                {
202                    val = new StringValue( attributeType, StringTools.utf8ToString( (byte[])value ) );
203                }
204                else
205                {
206                    throw new LdapException( I18n.err( I18n.ERR_309, oid ) );
207                }
208            }
209            else
210            {
211                if ( value instanceof String )
212                {
213                    val = new BinaryValue( attributeType, StringTools.getBytesUtf8( (String)value ) );
214                }
215                else if ( value instanceof byte[] )
216                {
217                    val = new BinaryValue( attributeType, (byte[])value );
218                }
219                else
220                {
221                    throw new LdapException( I18n.err( I18n.ERR_309, oid ) );
222                }
223            }
224            
225            return val;
226        }
227    
228        /**
229         * {@inheritDoc}
230         */
231        public boolean compare( DN dn, String oid, Object value ) throws Exception
232        {
233            OperationManager operationManager = directoryService.getOperationManager();
234            
235            return operationManager.compare( 
236                new CompareOperationContext( this, dn, oid, 
237                    convertToValue( oid, value ) ) );
238        }
239    
240    
241        /**
242         * {@inheritDoc}
243         */
244        public boolean compare( DN dn, String oid, Object value, boolean ignoreReferral ) throws Exception
245        {
246            CompareOperationContext opContext =  
247                    new CompareOperationContext( this, dn, oid, 
248                        convertToValue( oid, value ) );
249            
250            setReferralHandling( opContext, ignoreReferral );
251            
252            OperationManager operationManager = directoryService.getOperationManager();
253            return operationManager.compare( opContext );
254        }
255    
256    
257        /**
258         * {@inheritDoc}
259         */
260        public void delete( DN dn ) throws Exception
261        {
262            delete( dn, LogChange.TRUE );
263        }
264    
265    
266        /**
267         * {@inheritDoc}
268         */
269        public void delete( DN dn, LogChange log ) throws Exception
270        {
271            DeleteOperationContext opContext = new DeleteOperationContext( this, dn );
272    
273            opContext.setLogChange( log );
274    
275            OperationManager operationManager = directoryService.getOperationManager();
276            operationManager.delete( opContext );
277        }
278    
279    
280        /**
281         * {@inheritDoc}
282         */
283        public void delete( DN dn, boolean ignoreReferral  ) throws Exception
284        {
285            delete( dn, ignoreReferral, LogChange.TRUE );
286        }
287    
288    
289        /**
290         * {@inheritDoc}
291         */
292        public void delete( DN dn, boolean ignoreReferral, LogChange log ) throws Exception
293        {
294            DeleteOperationContext opContext = new DeleteOperationContext( this, dn );
295            
296            opContext.setLogChange( log );
297            setReferralHandling( opContext, ignoreReferral );
298    
299            OperationManager operationManager = directoryService.getOperationManager();
300            operationManager.delete( opContext );
301        }
302    
303    
304        /* (non-Javadoc)
305         * @see org.apache.directory.server.core.CoreSession#getAuthenticatedPrincipal()
306         */
307        public LdapPrincipal getAuthenticatedPrincipal()
308        {
309            return authenticatedPrincipal;
310        }
311    
312    
313        /* (non-Javadoc)
314         * @see org.apache.directory.server.core.CoreSession#getAuthenticationLevel()
315         */
316        public AuthenticationLevel getAuthenticationLevel()
317        {
318            return getEffectivePrincipal().getAuthenticationLevel();
319        }
320    
321    
322        /* (non-Javadoc)
323         * @see org.apache.directory.server.core.CoreSession#getClientAddress()
324         */
325        public SocketAddress getClientAddress()
326        {
327            // TODO Auto-generated method stub
328            return null;
329        }
330    
331    
332        /* (non-Javadoc)
333         * @see org.apache.directory.server.core.CoreSession#getControls()
334         */
335        public Set<Control> getControls()
336        {
337            // TODO Auto-generated method stub
338            return null;
339        }
340    
341    
342        /* (non-Javadoc)
343         * @see org.apache.directory.server.core.CoreSession#getDirectoryService()
344         */
345        public DirectoryService getDirectoryService()
346        {
347            return directoryService;
348        }
349    
350    
351        /* (non-Javadoc)
352         * @see org.apache.directory.server.core.CoreSession#getEffectivePrincipal()
353         */
354        public LdapPrincipal getEffectivePrincipal()
355        {
356            if ( authorizedPrincipal == null )
357            {
358                return authenticatedPrincipal;
359            }
360            
361            return authorizedPrincipal;
362        }
363    
364    
365        /* (non-Javadoc)
366         * @see org.apache.directory.server.core.CoreSession#getOutstandingOperations()
367         */
368        public Set<OperationContext> getOutstandingOperations()
369        {
370            // TODO Auto-generated method stub
371            return null;
372        }
373    
374    
375        /* (non-Javadoc)
376         * @see org.apache.directory.server.core.CoreSession#getServiceAddress()
377         */
378        public SocketAddress getServiceAddress()
379        {
380            // TODO Auto-generated method stub
381            return null;
382        }
383    
384    
385        /* (non-Javadoc)
386         * @see org.apache.directory.server.core.CoreSession#isConfidential()
387         */
388        public boolean isConfidential()
389        {
390            // TODO Auto-generated method stub
391            return false;
392        }
393    
394    
395        /* (non-Javadoc)
396         * @see org.apache.directory.server.core.CoreSession#isVirtual()
397         */
398        public boolean isVirtual()
399        {
400            // TODO Auto-generated method stub
401            return true;
402        }
403        
404        
405        /**
406         * TODO - perhaps we should just use a flag that is calculated on creation
407         * of this session
408         *  
409         * @see org.apache.directory.server.core.CoreSession#isAdministrator()
410         */
411        public boolean isAdministrator()
412        {
413            String normName = getEffectivePrincipal().getName(); 
414            return normName.equals( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
415        }
416    
417    
418        /**
419         * TODO - this method impl does not check to see if the principal is in 
420         * the administrators group - it only returns true of the principal is
421         * the actual admin user.  need to make it check groups.
422         * 
423         * TODO - perhaps we should just use a flag that is calculated on creation
424         * of this session
425         *  
426         * @see org.apache.directory.server.core.CoreSession#isAnAdministrator()
427         */
428        public boolean isAnAdministrator()
429        {
430            if ( isAdministrator() )
431            {
432                return true;
433            }
434            
435            // TODO fix this so it checks groups
436            return false;
437        }
438    
439    
440        /* (non-Javadoc)
441         * @see org.apache.directory.server.core.CoreSession#list(org.apache.directory.shared.ldap.name.DN, org.apache.directory.shared.ldap.message.AliasDerefMode, java.util.Set)
442         */
443        public EntryFilteringCursor list( DN dn, AliasDerefMode aliasDerefMode,
444            Set<AttributeTypeOptions> returningAttributes ) throws Exception
445        {
446            OperationManager operationManager = directoryService.getOperationManager();
447            
448            ListOperationContext listOperationContext = new ListOperationContext( this, dn, returningAttributes );
449            listOperationContext.setAliasDerefMode( aliasDerefMode );
450            
451            return operationManager.list( listOperationContext );
452        }
453    
454    
455        /* (non-Javadoc)
456         * @see org.apache.directory.server.core.CoreSession#list(org.apache.directory.shared.ldap.name.DN, org.apache.directory.shared.ldap.message.AliasDerefMode, java.util.Set, int, int)
457         */
458        public EntryFilteringCursor list( DN dn, AliasDerefMode aliasDerefMode,
459            Set<AttributeTypeOptions> returningAttributes, long sizeLimit, int timeLimit ) throws Exception
460        {
461            OperationManager operationManager = directoryService.getOperationManager();
462    
463            ListOperationContext listOperationContext = new ListOperationContext( this, dn, returningAttributes );
464            listOperationContext.setSizeLimit( sizeLimit );
465            listOperationContext.setTimeLimit( timeLimit );
466            listOperationContext.setAliasDerefMode( aliasDerefMode );
467         
468            return operationManager.list( listOperationContext );
469        }
470    
471    
472        /**
473         * {@inheritDoc} 
474         */
475        public ClonedServerEntry lookup( DN dn ) throws Exception
476        {
477            OperationManager operationManager = directoryService.getOperationManager();
478            return operationManager.lookup( new LookupOperationContext( this, dn ) );
479        }
480    
481    
482        /**
483         * {@inheritDoc}
484         */
485        public ClonedServerEntry lookup( DN dn, String[] attrId ) throws Exception
486        {
487            OperationManager operationManager = directoryService.getOperationManager();
488            return operationManager.lookup( 
489                new LookupOperationContext( this, dn, attrId ) );
490        }
491    
492    
493        /**
494         * {@inheritDoc}
495         */
496        public void modify( DN dn, List<Modification> mods ) throws Exception
497        {
498            modify( dn, mods, LogChange.TRUE );
499        }
500    
501    
502        /**
503         * {@inheritDoc}
504         */
505        public void modify( DN dn, List<Modification> mods, LogChange log ) throws Exception
506        {
507            if ( mods == null )
508            {
509                return;
510            }
511            
512            List<Modification> serverModifications = new ArrayList<Modification>( mods.size() );
513            
514            for ( Modification mod:mods )
515            {
516                serverModifications.add( new ServerModification( directoryService.getSchemaManager(), mod ) );
517            }
518            
519            ModifyOperationContext opContext = new ModifyOperationContext( this, dn, serverModifications );
520    
521            opContext.setLogChange( log );
522    
523            OperationManager operationManager = directoryService.getOperationManager();
524            operationManager.modify( opContext );
525        }
526    
527    
528        /**
529         * {@inheritDoc}
530         */
531        public void modify( DN dn, List<Modification> mods, boolean ignoreReferral ) throws Exception
532        {
533            modify( dn, mods, ignoreReferral, LogChange.TRUE );
534        }
535    
536    
537        /**
538         * {@inheritDoc}
539         */
540        public void modify( DN dn, List<Modification> mods, boolean ignoreReferral, LogChange log ) throws Exception
541        {
542            if ( mods == null )
543            {
544                return;
545            }
546            
547            List<Modification> serverModifications = new ArrayList<Modification>( mods.size() );
548            
549            for ( Modification mod:mods )
550            {
551                serverModifications.add( new ServerModification( directoryService.getSchemaManager(), mod ) );
552            }
553    
554            ModifyOperationContext opContext = new ModifyOperationContext( this, dn, serverModifications );
555            
556            setReferralHandling( opContext, ignoreReferral );
557            opContext.setLogChange( log );
558    
559            OperationManager operationManager = directoryService.getOperationManager();
560            operationManager.modify( opContext );
561        }
562    
563    
564        /**
565         * {@inheritDoc} 
566         */
567        public void move( DN dn, DN newParent ) throws Exception
568        {
569            move( dn, newParent, LogChange.TRUE );
570        }
571    
572    
573        /**
574         * {@inheritDoc} 
575         */
576        public void move( DN dn, DN newParent, LogChange log ) throws Exception
577        {
578            MoveOperationContext opContext = new MoveOperationContext( this, dn, newParent );
579            
580            opContext.setLogChange( log );
581    
582            OperationManager operationManager = directoryService.getOperationManager();
583            operationManager.move( opContext );
584        }
585    
586    
587        /**
588         * {@inheritDoc} 
589         */
590        public void move( DN dn, DN newParent, boolean ignoreReferral ) throws Exception
591        {
592            move( dn, newParent, ignoreReferral, LogChange.TRUE );
593        }
594    
595    
596        /**
597         * {@inheritDoc} 
598         */
599        public void move( DN dn, DN newParent, boolean ignoreReferral, LogChange log ) throws Exception
600        {
601            OperationManager operationManager = directoryService.getOperationManager();
602            MoveOperationContext opContext = new MoveOperationContext( this, dn, newParent );
603            
604            setReferralHandling( opContext, ignoreReferral );
605            opContext.setLogChange( log );
606    
607            operationManager.move( opContext );
608        }
609    
610    
611        /**
612         * {@inheritDoc} 
613         */
614        public void moveAndRename( DN dn, DN newParent, RDN newRdn, boolean deleteOldRdn ) throws Exception
615        {
616            moveAndRename( dn, newParent, newRdn, deleteOldRdn, LogChange.TRUE );
617        }
618    
619    
620        /**
621         * {@inheritDoc} 
622         */
623        public void moveAndRename( DN dn, DN newParent, RDN newRdn, boolean deleteOldRdn, LogChange log ) throws Exception
624        {
625            MoveAndRenameOperationContext opContext = 
626                new MoveAndRenameOperationContext( this, dn, newParent, newRdn, deleteOldRdn );
627            
628            opContext.setLogChange( log );
629    
630            OperationManager operationManager = directoryService.getOperationManager();
631            operationManager.moveAndRename( opContext );
632        }
633    
634    
635        /**
636         * {@inheritDoc} 
637         */
638        public void moveAndRename( DN dn, DN newParent, RDN newRdn, boolean deleteOldRdn, boolean ignoreReferral ) throws Exception
639        {
640            moveAndRename( dn, newParent, newRdn, deleteOldRdn, ignoreReferral, LogChange.TRUE );
641        }
642    
643    
644        /**
645         * {@inheritDoc} 
646         */
647        public void moveAndRename( DN dn, DN newParent, RDN newRdn, boolean deleteOldRdn, boolean ignoreReferral, LogChange log ) throws Exception
648        {
649            OperationManager operationManager = directoryService.getOperationManager();
650            MoveAndRenameOperationContext opContext = new MoveAndRenameOperationContext( this, dn, newParent, newRdn, deleteOldRdn );
651            
652            opContext.setLogChange( log );
653            setReferralHandling( opContext, ignoreReferral );
654    
655            operationManager.moveAndRename( opContext );
656        }
657    
658    
659        /**
660         * {@inheritDoc}
661         */
662        public void rename( DN dn, RDN newRdn, boolean deleteOldRdn ) throws Exception
663        {
664            rename( dn, newRdn, deleteOldRdn, LogChange.TRUE );
665        }
666    
667    
668        /**
669         * {@inheritDoc}
670         */
671        public void rename( DN dn, RDN newRdn, boolean deleteOldRdn, LogChange log ) throws Exception
672        {
673            RenameOperationContext opContext = new RenameOperationContext( this, dn, newRdn, deleteOldRdn );
674            
675            opContext.setLogChange( log );
676    
677            OperationManager operationManager = directoryService.getOperationManager();
678            operationManager.rename( opContext );
679        }
680    
681    
682        /**
683         * {@inheritDoc}
684         */
685        public void rename( DN dn, RDN newRdn, boolean deleteOldRdn, boolean ignoreReferral ) throws Exception
686        {
687            rename( dn, newRdn, deleteOldRdn, ignoreReferral, LogChange.TRUE );
688        }
689    
690    
691        /**
692         * {@inheritDoc}
693         */
694        public void rename( DN dn, RDN newRdn, boolean deleteOldRdn, boolean ignoreReferral, LogChange log ) throws Exception
695        {
696            OperationManager operationManager = directoryService.getOperationManager();
697            RenameOperationContext opContext = new RenameOperationContext( this, dn, newRdn, deleteOldRdn );
698            
699            opContext.setLogChange( log );
700            setReferralHandling( opContext, ignoreReferral );
701    
702            operationManager.rename( opContext );
703        }
704    
705    
706        /**
707         * {@inheritDoc}
708         */
709        public EntryFilteringCursor search( DN dn, String filter ) throws Exception
710        {
711            return search( dn, filter, true );
712        }
713    
714    
715        /**
716         * {@inheritDoc}
717         */
718        public EntryFilteringCursor search( DN dn, String filter, boolean ignoreReferrals ) throws Exception
719        {
720            OperationManager operationManager = directoryService.getOperationManager();
721            ExprNode filterNode = FilterParser.parse( filter ); 
722            
723            SearchOperationContext searchOperationContext = new SearchOperationContext( this, dn, SearchScope.OBJECT, 
724                filterNode, null );
725            searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
726            setReferralHandling( searchOperationContext, ignoreReferrals );
727    
728            return operationManager.search( searchOperationContext );
729        }
730        
731    
732        /* (non-Javadoc)
733         * @see org.apache.directory.server.core.CoreSession#search(org.apache.directory.shared.ldap.name.DN, org.apache.directory.shared.ldap.filter.SearchScope, org.apache.directory.shared.ldap.filter.ExprNode, org.apache.directory.shared.ldap.message.AliasDerefMode, java.util.Set)
734         */
735        public EntryFilteringCursor search( DN dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
736            Set<AttributeTypeOptions> returningAttributes ) throws Exception
737        {
738            OperationManager operationManager = directoryService.getOperationManager();
739            
740            SearchOperationContext searchOperationContext = new SearchOperationContext( this, dn, scope, 
741                filter, returningAttributes );
742            searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
743    
744            return operationManager.search( searchOperationContext );
745        }
746    
747    
748        /* (non-Javadoc)
749         * @see org.apache.directory.server.core.CoreSession#search(org.apache.directory.shared.ldap.name.DN, org.apache.directory.shared.ldap.filter.SearchScope, org.apache.directory.shared.ldap.filter.ExprNode, org.apache.directory.shared.ldap.message.AliasDerefMode, java.util.Set, int, int)
750         */
751        public EntryFilteringCursor search( DN dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
752            Set<AttributeTypeOptions> returningAttributes, long sizeLimit, int timeLimit ) throws Exception
753        {
754            OperationManager operationManager = directoryService.getOperationManager();
755            
756            SearchOperationContext searchOperationContext = new SearchOperationContext( this, dn, scope, filter, returningAttributes );
757            searchOperationContext.setSizeLimit( sizeLimit );
758            searchOperationContext.setTimeLimit( timeLimit );
759            searchOperationContext.setAliasDerefMode( aliasDerefMode );
760    
761            return operationManager.search( searchOperationContext );
762        }
763    
764    
765        public boolean isAnonymous()
766        {
767            return StringTools.isEmpty( getEffectivePrincipal().getName() );
768        }
769    
770    
771        /**
772         * {@inheritDoc}
773         */
774        public boolean compare( InternalCompareRequest compareRequest ) throws Exception
775        {
776            CompareOperationContext opContext = new CompareOperationContext( this, compareRequest );
777            OperationManager operationManager = directoryService.getOperationManager();
778            boolean result = operationManager.compare( opContext );
779            compareRequest.getResultResponse().addAll( opContext.getResponseControls() );
780            return result;
781        }
782    
783    
784        /**
785         * {@inheritDoc}
786         */
787        public void delete( InternalDeleteRequest deleteRequest ) throws Exception
788        {
789            delete( deleteRequest, LogChange.TRUE );
790        }
791    
792    
793        /**
794         * {@inheritDoc}
795         */
796        public void delete( InternalDeleteRequest deleteRequest, LogChange log ) throws Exception
797        {
798            DeleteOperationContext opContext = new DeleteOperationContext( this, deleteRequest );
799            
800            opContext.setLogChange( log );
801    
802            OperationManager operationManager = directoryService.getOperationManager();
803            operationManager.delete( opContext );
804            deleteRequest.getResultResponse().addAll( opContext.getResponseControls() );
805        }
806    
807    
808        public boolean exists( DN dn ) throws Exception
809        {
810            EntryOperationContext opContext = new EntryOperationContext( this, dn );
811            OperationManager operationManager = directoryService.getOperationManager();
812            return operationManager.hasEntry( opContext );
813        }
814    
815    
816        /**
817         * {@inheritDoc}
818         */
819        public void modify( InternalModifyRequest modifyRequest ) throws Exception
820        {
821            modify( modifyRequest, LogChange.TRUE );
822        }
823    
824    
825        /**
826         * {@inheritDoc}
827         */
828        public void modify( InternalModifyRequest modifyRequest, LogChange log ) throws Exception
829        {
830            ModifyOperationContext opContext = new ModifyOperationContext( this, modifyRequest );
831    
832            opContext.setLogChange( log );
833    
834            OperationManager operationManager = directoryService.getOperationManager();
835            operationManager.modify( opContext );
836            modifyRequest.getResultResponse().addAll( opContext.getResponseControls() );
837        }
838    
839    
840        /**
841         * {@inheritDoc} 
842         */
843        public void move( InternalModifyDnRequest modifyDnRequest ) throws Exception
844        {
845            move( modifyDnRequest, LogChange.TRUE );
846        }
847    
848    
849        /**
850         * {@inheritDoc} 
851         */
852        public void move( InternalModifyDnRequest modifyDnRequest, LogChange log ) throws Exception
853        {
854            MoveOperationContext opContext = new MoveOperationContext( this, modifyDnRequest );
855            
856            opContext.setLogChange( log );
857    
858            OperationManager operationManager = directoryService.getOperationManager();
859            operationManager.move( opContext );
860            modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
861        }
862    
863    
864        /**
865         * {@inheritDoc} 
866         */
867        public void moveAndRename( InternalModifyDnRequest modifyDnRequest ) throws Exception
868        {
869            moveAndRename( modifyDnRequest, LogChange.TRUE );
870        }
871    
872    
873        /**
874         * {@inheritDoc} 
875         */
876        public void moveAndRename( InternalModifyDnRequest modifyDnRequest, LogChange log ) throws Exception
877        {
878            MoveAndRenameOperationContext opContext = new MoveAndRenameOperationContext( this, modifyDnRequest );
879    
880            opContext.setLogChange( log );
881    
882            OperationManager operationManager = directoryService.getOperationManager();
883            operationManager.moveAndRename( opContext );
884            modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
885        }
886    
887    
888        /**
889         * {@inheritDoc}
890         */
891        public void rename( InternalModifyDnRequest modifyDnRequest ) throws Exception
892        {
893            rename( modifyDnRequest, LogChange.TRUE );
894        }
895    
896    
897        /**
898         * {@inheritDoc}
899         */
900        public void rename( InternalModifyDnRequest modifyDnRequest, LogChange log ) throws Exception
901        {
902            RenameOperationContext opContext = new RenameOperationContext( this, modifyDnRequest );
903    
904            opContext.setLogChange( log );
905    
906            OperationManager operationManager = directoryService.getOperationManager();
907            operationManager.rename( opContext );
908            modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
909        }
910    
911    
912        public EntryFilteringCursor search( InternalSearchRequest searchRequest ) throws Exception
913        {
914            SearchOperationContext opContext = new SearchOperationContext( this, searchRequest );
915            OperationManager operationManager = directoryService.getOperationManager();
916            EntryFilteringCursor cursor = operationManager.search( opContext );
917            searchRequest.getResultResponse().addAll( opContext.getResponseControls() );
918            
919            return cursor;
920        }
921    
922    
923        public void unbind() throws Exception
924        {
925            OperationManager operationManager = directoryService.getOperationManager();
926            operationManager.unbind( new UnbindOperationContext( this ) );
927        }
928    
929    
930        public void unbind( InternalUnbindRequest unbindRequest )
931        {
932            // TODO Auto-generated method stub
933            
934        }
935    
936    
937        /**
938         * @param directoryService the directoryService to set
939         */
940        public void setDirectoryService( DirectoryService directoryService )
941        {
942            this.directoryService = directoryService;
943        }
944    }