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 DefaultCoreSession implements CoreSession
084    {
085        private final DirectoryService directoryService;
086        private final LdapPrincipal authenticatedPrincipal;
087        private LdapPrincipal authorizedPrincipal;
088        
089        
090        public DefaultCoreSession( 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            
679            operationManager.rename( opContext );
680        }
681    
682    
683        /**
684         * {@inheritDoc}
685         */
686        public void rename( DN dn, RDN newRdn, boolean deleteOldRdn, boolean ignoreReferral ) throws Exception
687        {
688            rename( dn, newRdn, deleteOldRdn, ignoreReferral, LogChange.TRUE );
689        }
690    
691    
692        /**
693         * {@inheritDoc}
694         */
695        public void rename( DN dn, RDN newRdn, boolean deleteOldRdn, boolean ignoreReferral, LogChange log ) throws Exception
696        {
697            OperationManager operationManager = directoryService.getOperationManager();
698            RenameOperationContext opContext = new RenameOperationContext( this, dn, newRdn, deleteOldRdn );
699            
700            opContext.setLogChange( log );
701            setReferralHandling( opContext, ignoreReferral );
702    
703            operationManager.rename( opContext );
704        }
705    
706    
707        /**
708         * {@inheritDoc}
709         */
710        public EntryFilteringCursor search( DN dn, String filter ) throws Exception
711        {
712            return search( dn, filter, true );
713        }
714    
715    
716        /**
717         * {@inheritDoc}
718         */
719        public EntryFilteringCursor search( DN dn, String filter, boolean ignoreReferrals ) throws Exception
720        {
721            OperationManager operationManager = directoryService.getOperationManager();
722            ExprNode filterNode = FilterParser.parse( filter ); 
723            
724            SearchOperationContext searchOperationContext = new SearchOperationContext( this, dn, SearchScope.OBJECT, 
725                filterNode, null );
726            searchOperationContext.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS ); 
727            setReferralHandling( searchOperationContext, ignoreReferrals );
728    
729            return operationManager.search( searchOperationContext );
730        }
731        
732    
733        /* (non-Javadoc)
734         * @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)
735         */
736        public EntryFilteringCursor search( DN dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
737            Set<AttributeTypeOptions> returningAttributes ) throws Exception
738        {
739            OperationManager operationManager = directoryService.getOperationManager();
740    
741            SearchOperationContext searchOperationContext = new SearchOperationContext( this, dn, scope, filter, 
742                returningAttributes );
743            searchOperationContext.setAliasDerefMode( aliasDerefMode );
744    
745            return operationManager.search( searchOperationContext );
746        }
747    
748    
749        /* (non-Javadoc)
750         * @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)
751         */
752        public EntryFilteringCursor search( DN dn, SearchScope scope, ExprNode filter, AliasDerefMode aliasDerefMode,
753            Set<AttributeTypeOptions> returningAttributes, long sizeLimit, int timeLimit ) throws Exception
754        {
755            OperationManager operationManager = directoryService.getOperationManager();
756    
757            SearchOperationContext searchOperationContext = new SearchOperationContext( this, dn, scope, filter, 
758                returningAttributes );
759            searchOperationContext.setAliasDerefMode( aliasDerefMode );
760            searchOperationContext.setSizeLimit( sizeLimit );
761            searchOperationContext.setTimeLimit( timeLimit );
762            
763            return operationManager.search( searchOperationContext );
764        }
765    
766    
767        public boolean isAnonymous()
768        {
769            return getEffectivePrincipal().getClonedName().isEmpty();
770        }
771    
772    
773        /**
774         * {@inheritDoc}
775         */
776        public boolean compare( InternalCompareRequest compareRequest ) throws Exception
777        {
778            CompareOperationContext opContext = new CompareOperationContext( this, compareRequest );
779            OperationManager operationManager = directoryService.getOperationManager();
780            boolean result = operationManager.compare( opContext );
781            compareRequest.getResultResponse().addAll( opContext.getResponseControls() );
782            return result;
783        }
784    
785    
786        /**
787         * {@inheritDoc}
788         */
789        public void delete( InternalDeleteRequest deleteRequest ) throws Exception
790        {
791            delete( deleteRequest, LogChange.TRUE );
792        }
793    
794    
795        /**
796         * {@inheritDoc}
797         */
798        public void delete( InternalDeleteRequest deleteRequest, LogChange log ) throws Exception
799        {
800            DeleteOperationContext opContext = new DeleteOperationContext( this, deleteRequest );
801            
802            opContext.setLogChange( log );
803    
804            OperationManager operationManager = directoryService.getOperationManager();
805            operationManager.delete( opContext );
806            deleteRequest.getResultResponse().addAll( opContext.getResponseControls() );
807        }
808    
809    
810        public boolean exists( DN dn ) throws Exception
811        {
812            EntryOperationContext opContext = new EntryOperationContext( this, dn );
813            OperationManager operationManager = directoryService.getOperationManager();
814            return operationManager.hasEntry( opContext );
815        }
816    
817    
818        /**
819         * {@inheritDoc}
820         */
821        public void modify( InternalModifyRequest modifyRequest ) throws Exception
822        {
823            modify( modifyRequest, LogChange.TRUE );
824        }
825    
826    
827        /**
828         * {@inheritDoc}
829         */
830        public void modify( InternalModifyRequest modifyRequest, LogChange log ) throws Exception
831        {
832            ModifyOperationContext opContext = new ModifyOperationContext( this, modifyRequest );
833    
834            opContext.setLogChange( log );
835    
836            OperationManager operationManager = directoryService.getOperationManager();
837            operationManager.modify( opContext );
838            modifyRequest.getResultResponse().addAll( opContext.getResponseControls() );
839        }
840    
841    
842        /**
843         * {@inheritDoc} 
844         */
845        public void move( InternalModifyDnRequest modifyDnRequest ) throws Exception
846        {
847            move( modifyDnRequest, LogChange.TRUE );
848        }
849    
850    
851        /**
852         * {@inheritDoc} 
853         */
854        public void move( InternalModifyDnRequest modifyDnRequest, LogChange log ) throws Exception
855        {
856            MoveOperationContext opContext = new MoveOperationContext( this, modifyDnRequest );
857            
858            opContext.setLogChange( log );
859    
860            OperationManager operationManager = directoryService.getOperationManager();
861            operationManager.move( opContext );
862            modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
863        }
864    
865    
866        /**
867         * {@inheritDoc} 
868         */
869        public void moveAndRename( InternalModifyDnRequest modifyDnRequest ) throws Exception
870        {
871            moveAndRename( modifyDnRequest, LogChange.TRUE );
872        }
873    
874    
875        /**
876         * {@inheritDoc} 
877         */
878        public void moveAndRename( InternalModifyDnRequest modifyDnRequest, LogChange log ) throws Exception
879        {
880            MoveAndRenameOperationContext opContext = new MoveAndRenameOperationContext( this, modifyDnRequest );
881    
882            opContext.setLogChange( log );
883    
884            OperationManager operationManager = directoryService.getOperationManager();
885            operationManager.moveAndRename( opContext );
886            modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
887        }
888    
889    
890        /**
891         * {@inheritDoc}
892         */
893        public void rename( InternalModifyDnRequest modifyDnRequest ) throws Exception
894        {
895            rename( modifyDnRequest, LogChange.TRUE );
896        }
897    
898    
899        /**
900         * {@inheritDoc}
901         */
902        public void rename( InternalModifyDnRequest modifyDnRequest, LogChange log ) throws Exception
903        {
904            RenameOperationContext opContext = new RenameOperationContext( this, modifyDnRequest );
905    
906            opContext.setLogChange( log );
907    
908            OperationManager operationManager = directoryService.getOperationManager();
909            operationManager.rename( opContext );
910            modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
911        }
912    
913    
914        public EntryFilteringCursor search( InternalSearchRequest searchRequest ) throws Exception
915        {
916            SearchOperationContext opContext = new SearchOperationContext( this, searchRequest );
917            OperationManager operationManager = directoryService.getOperationManager();
918            EntryFilteringCursor cursor = operationManager.search( opContext );
919            searchRequest.getResultResponse().addAll( opContext.getResponseControls() );
920            
921            return cursor;
922        }
923    
924    
925        public void unbind() throws Exception
926        {
927            OperationManager operationManager = directoryService.getOperationManager();
928            operationManager.unbind( new UnbindOperationContext( this ) );
929        }
930    
931    
932        public void unbind( InternalUnbindRequest unbindRequest )
933        {
934            // TODO Auto-generated method stub
935            
936        }
937    }