You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/04/23 08:43:57 UTC
svn commit: r937166 - in /directory/apacheds/trunk/core-api: pom.xml
src/main/java/org/apache/directory/server/core/EntryToResponseCursor.java
src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
Author: kayyagari
Date: Fri Apr 23 06:43:57 2010
New Revision: 937166
URL: http://svn.apache.org/viewvc?rev=937166&view=rev
Log:
o added a new LdapConnection implementation based on CoreSession
o a new cursor to convert Entry objects to SearchResponse objects
o added dependency on ldap-client-api
Added:
directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/EntryToResponseCursor.java
directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
Modified:
directory/apacheds/trunk/core-api/pom.xml
Modified: directory/apacheds/trunk/core-api/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/pom.xml?rev=937166&r1=937165&r2=937166&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/pom.xml (original)
+++ directory/apacheds/trunk/core-api/pom.xml Fri Apr 23 06:43:57 2010
@@ -53,6 +53,12 @@
<groupId>${groupId}</groupId>
<version>${version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.directory.client.ldap</groupId>
+ <artifactId>ldap-client-api</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ </dependency>
</dependencies>
<build>
Added: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/EntryToResponseCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/EntryToResponseCursor.java?rev=937166&view=auto
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/EntryToResponseCursor.java (added)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/EntryToResponseCursor.java Fri Apr 23 06:43:57 2010
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.server.core;
+
+
+import java.util.Iterator;
+
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
+import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.filtering.EntryFilteringCursor;
+import org.apache.directory.shared.ldap.cursor.ClosureMonitor;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+
+
+/**
+ * A cursor to get SearchResponseS after setting the underlying cursor's ServerEntry object in SearchResultEnty object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryToResponseCursor<SearchResponse> implements Cursor<SearchResponse>
+{
+
+ /** the underlying cursor */
+ private EntryFilteringCursor wrapped;
+
+
+ public EntryToResponseCursor( EntryFilteringCursor wrapped )
+ {
+ this.wrapped = wrapped;
+ }
+
+
+ public Iterator<SearchResponse> iterator()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public void after( SearchResponse resp ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public void afterLast() throws Exception
+ {
+ wrapped.afterLast();
+ }
+
+
+ public boolean available()
+ {
+ return wrapped.available();
+ }
+
+
+ public void before( SearchResponse resp ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public void beforeFirst() throws Exception
+ {
+ wrapped.beforeFirst();
+ }
+
+
+ public void close() throws Exception
+ {
+ wrapped.close();
+ }
+
+
+ public void close( Exception e ) throws Exception
+ {
+ wrapped.close( e );
+ }
+
+
+ public boolean first() throws Exception
+ {
+ return wrapped.first();
+ }
+
+
+ public SearchResponse get() throws Exception
+ {
+ ClonedServerEntry entry = wrapped.get();
+ SearchResultEntry se = new SearchResultEntry();
+ se.setEntry( entry );
+
+ return ( SearchResponse ) se;
+ }
+
+
+ public boolean isClosed() throws Exception
+ {
+ return wrapped.isClosed();
+ }
+
+
+ public boolean isElementReused()
+ {
+ return wrapped.isElementReused();
+ }
+
+
+ public boolean last() throws Exception
+ {
+ return wrapped.last();
+ }
+
+
+ public boolean next() throws Exception
+ {
+ return wrapped.next();
+ }
+
+
+ public boolean previous() throws Exception
+ {
+ return wrapped.previous();
+ }
+
+
+ public void setClosureMonitor( ClosureMonitor monitor )
+ {
+ wrapped.setClosureMonitor( monitor );
+ }
+
+}
Added: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java?rev=937166&view=auto
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java (added)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java Fri Apr 23 06:43:57 2010
@@ -0,0 +1,894 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.server.core;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.exception.LdapException;
+import org.apache.directory.ldap.client.api.message.AbandonRequest;
+import org.apache.directory.ldap.client.api.message.AddRequest;
+import org.apache.directory.ldap.client.api.message.AddResponse;
+import org.apache.directory.ldap.client.api.message.BindRequest;
+import org.apache.directory.ldap.client.api.message.BindResponse;
+import org.apache.directory.ldap.client.api.message.CompareRequest;
+import org.apache.directory.ldap.client.api.message.CompareResponse;
+import org.apache.directory.ldap.client.api.message.DeleteRequest;
+import org.apache.directory.ldap.client.api.message.DeleteResponse;
+import org.apache.directory.ldap.client.api.message.ExtendedRequest;
+import org.apache.directory.ldap.client.api.message.ExtendedResponse;
+import org.apache.directory.ldap.client.api.message.LdapResult;
+import org.apache.directory.ldap.client.api.message.ModifyDnRequest;
+import org.apache.directory.ldap.client.api.message.ModifyDnResponse;
+import org.apache.directory.ldap.client.api.message.ModifyRequest;
+import org.apache.directory.ldap.client.api.message.ModifyResponse;
+import org.apache.directory.ldap.client.api.message.SearchRequest;
+import org.apache.directory.ldap.client.api.message.SearchResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
+import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.filtering.EntryFilteringCursor;
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.entry.DefaultServerEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.ServerEntry;
+import org.apache.directory.shared.ldap.entry.ServerModification;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.filter.FilterParser;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.AddRequestImpl;
+import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.message.CompareRequestImpl;
+import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
+import org.apache.directory.shared.ldap.message.ModifyDnRequestImpl;
+import org.apache.directory.shared.ldap.message.ModifyRequestImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.message.SearchRequestImpl;
+import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalModifyDnRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalModifyRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchRequest;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.name.RDN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+
+
+
+
+/**
+ * An implementation of LdapConnection based on the CoreSession.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapCoreSessionConnection implements LdapConnection
+{
+
+ /** the CoreSession object */
+ private CoreSession session;
+
+ /** the SchemaManager */
+ private SchemaManager sm;
+
+
+ public LdapCoreSessionConnection()
+ {
+
+ }
+
+
+ public LdapCoreSessionConnection( CoreSession session )
+ {
+ this.session = session;
+ this.sm = session.getDirectoryService().getSchemaManager();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean close() throws IOException
+ {
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean connect() throws LdapException, IOException
+ {
+ return true;
+ }
+
+
+ private LdapResult getDefaultResult()
+ {
+ LdapResult result = new LdapResult();
+ result.setResultCode( ResultCodeEnum.SUCCESS );
+ return result;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public AddResponse add( AddRequest addRequest ) throws LdapException
+ {
+ InternalAddRequest iadd = new AddRequestImpl( addRequest.getMessageId() );
+ iadd.setEntry( addRequest.getEntry() );
+
+ AddResponse resp = new AddResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ session.add( iadd );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public AddResponse add( Entry entry ) throws LdapException
+ {
+ AddResponse resp = new AddResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ ServerEntry se;
+ if ( entry instanceof ServerEntry )
+ {
+ se = ( ServerEntry ) entry;
+ }
+ else
+ {
+ se = new DefaultServerEntry( sm, entry );
+ }
+
+ session.add( se );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompareResponse compare( CompareRequest compareRequest ) throws LdapException
+ {
+ CompareResponse resp = new CompareResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ InternalCompareRequest icompare = new CompareRequestImpl( compareRequest.getMessageId() );
+
+ Object obj = compareRequest.getValue();
+ if ( obj instanceof byte[] )
+ {
+ icompare.setAssertionValue( ( byte[] ) obj );
+ }
+ else
+ {
+ icompare.setAssertionValue( ( String ) obj );
+ }
+
+ icompare.setAttributeId( compareRequest.getAttrName() );
+ icompare.setName( compareRequest.getEntryDn() );
+
+ session.compare( icompare );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompareResponse compare( DN dn, String attributeName, byte[] value ) throws LdapException
+ {
+ CompareResponse resp = new CompareResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ session.compare( dn, attributeName, value );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompareResponse compare( DN dn, String attributeName, String value ) throws LdapException
+ {
+ CompareResponse resp = new CompareResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ session.compare( dn, attributeName, value );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompareResponse compare( String dn, String attributeName, byte[] value ) throws LdapException
+ {
+ CompareResponse resp = new CompareResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ session.compare( new DN( dn ), attributeName, value );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompareResponse compare( String dn, String attributeName, String value ) throws LdapException
+ {
+ CompareResponse resp = new CompareResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ session.compare( new DN( dn ), attributeName, value );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompareResponse compare( DN dn, String attributeName, Value<?> value ) throws LdapException
+ {
+ CompareResponse resp = new CompareResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ session.compare( dn, attributeName, value.get() );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompareResponse compare( String dn, String attributeName, Value<?> value ) throws LdapException
+ {
+ CompareResponse resp = new CompareResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ session.compare( new DN( dn ), attributeName, value.get() );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public DeleteResponse delete( DeleteRequest deleteRequest ) throws LdapException
+ {
+ DeleteResponse resp = new DeleteResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ InternalDeleteRequest idelete = new DeleteRequestImpl( deleteRequest.getMessageId() );
+ idelete.setName( deleteRequest.getTargetDn() );
+ session.delete( idelete );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public DeleteResponse delete( DN dn ) throws LdapException
+ {
+ DeleteResponse resp = new DeleteResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.delete( dn );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public DeleteResponse delete( String dn ) throws LdapException
+ {
+ DeleteResponse resp = new DeleteResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.delete( new DN( dn ) );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean doesFutureExistFor( Integer messageId )
+ {
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public SchemaManager getSchemaManager()
+ {
+ return sm;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<String> getSupportedControls() throws LdapException
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAuthenticated()
+ {
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isConnected()
+ {
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isControlSupported( String controlOID ) throws LdapException
+ {
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void loadSchema() throws LdapException
+ {
+ // do nothing, cause we already have SchemaManager in the session's DirectoryService
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public SearchResponse lookup( String dn, String... attributes ) throws LdapException
+ {
+ SearchResultEntry resp = null;
+ try
+ {
+ ClonedServerEntry entry = session.lookup( new DN( dn ), attributes );
+ resp = new SearchResultEntry();
+ resp.setEntry( entry );
+ }
+ catch ( Exception e )
+ {
+ // do nothing
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public SearchResponse lookup( String dn ) throws LdapException
+ {
+ SearchResultEntry resp = null;
+ try
+ {
+ ClonedServerEntry entry = session.lookup( new DN( dn ) );
+ resp = new SearchResultEntry();
+ resp.setEntry( entry );
+ }
+ catch ( Exception e )
+ {
+ // do nothing
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyResponse modify( Entry entry, ModificationOperation modOp ) throws LdapException
+ {
+ ModifyResponse resp = new ModifyResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ List<Modification> mods = new ArrayList<Modification>();
+ Iterator<EntryAttribute> itr = entry.iterator();
+ while ( itr.hasNext() )
+ {
+ mods.add( new ServerModification( modOp, itr.next() ) );
+ }
+ session.modify( entry.getDn(), mods );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyResponse modify( ModifyRequest modRequest ) throws LdapException
+ {
+ ModifyResponse resp = new ModifyResponse();
+ resp.setLdapResult( getDefaultResult() );
+
+ try
+ {
+ InternalModifyRequest iModReq = new ModifyRequestImpl( modRequest.getMessageId() );
+ iModReq.setName( modRequest.getDn() );
+
+ Iterator<Modification> itr = modRequest.getMods().iterator();
+ while ( itr.hasNext() )
+ {
+ iModReq.addModification( itr.next() );
+ }
+
+ session.modify( iModReq );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyDnResponse modifyDn( ModifyDnRequest modDnRequest ) throws LdapException
+ {
+ ModifyDnResponse resp = new ModifyDnResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ InternalModifyDnRequest iModDnReq = new ModifyDnRequestImpl( modDnRequest.getMessageId() );
+ iModDnReq.setDeleteOldRdn( modDnRequest.isDeleteOldRdn() );
+ iModDnReq.setName( modDnRequest.getEntryDn() );
+ iModDnReq.setNewRdn( modDnRequest.getNewRdn() );
+ iModDnReq.setNewSuperior( modDnRequest.getNewSuperior() );
+
+ session.move( iModDnReq );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyDnResponse move( DN entryDn, DN newSuperiorDn ) throws LdapException
+ {
+ ModifyDnResponse resp = new ModifyDnResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.move( entryDn, newSuperiorDn );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyDnResponse move( String entryDn, String newSuperiorDn ) throws LdapException
+ {
+ ModifyDnResponse resp = new ModifyDnResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.move( new DN( entryDn ), new DN( newSuperiorDn ) );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyDnResponse rename( DN entryDn, RDN newRdn, boolean deleteOldRdn ) throws LdapException
+ {
+ ModifyDnResponse resp = new ModifyDnResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.rename( entryDn, newRdn, deleteOldRdn );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyDnResponse rename( DN entryDn, RDN newRdn ) throws LdapException
+ {
+ ModifyDnResponse resp = new ModifyDnResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.rename( entryDn, newRdn, false );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyDnResponse rename( String entryDn, String newRdn, boolean deleteOldRdn ) throws LdapException
+ {
+ ModifyDnResponse resp = new ModifyDnResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.rename( new DN( entryDn ), new RDN( newRdn ), deleteOldRdn );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModifyDnResponse rename( String entryDn, String newRdn ) throws LdapException
+ {
+ ModifyDnResponse resp = new ModifyDnResponse();
+ resp.setLdapResult( getDefaultResult() );
+ try
+ {
+ session.rename( new DN( entryDn ), new RDN( newRdn ), false );
+ }
+ catch ( Exception e )
+ {
+ resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
+ }
+
+ return resp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Cursor<SearchResponse> search( SearchRequest searchRequest ) throws LdapException
+ {
+ try
+ {
+ InternalSearchRequest iSearchReq = new SearchRequestImpl( searchRequest.getMessageId() );
+ iSearchReq.setBase( new DN( searchRequest.getBaseDn() ) );
+ iSearchReq.setDerefAliases( searchRequest.getDerefAliases() );
+ iSearchReq.setFilter( FilterParser.parse( searchRequest.getFilter() ) );
+ iSearchReq.setScope( searchRequest.getScope() );
+ iSearchReq.setSizeLimit( searchRequest.getSizeLimit() );
+ iSearchReq.setTimeLimit( searchRequest.getTimeLimit() );
+ iSearchReq.setTypesOnly( searchRequest.getTypesOnly() );
+
+ EntryFilteringCursor entryCursor = session.search( iSearchReq );
+ entryCursor.beforeFirst();
+ return new EntryToResponseCursor<SearchResponse>( entryCursor );
+ }
+ catch ( Exception e )
+ {
+ throw new LdapException( e );
+ }
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Cursor<SearchResponse> search( String baseDn, String filter, SearchScope scope, String... attributes )
+ throws LdapException
+ {
+ // generate some random operation number
+ SearchRequest searchRequest = new SearchRequest();
+ searchRequest.setMessageId( ( int ) System.currentTimeMillis() );
+ searchRequest.setBaseDn( baseDn );
+ searchRequest.setFilter( filter );
+ searchRequest.setScope( scope );
+ searchRequest.addAttributes( attributes );
+ searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );
+
+ return search( searchRequest );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void unBind() throws Exception
+ {
+ session.unbind();
+ }
+
+
+ // unsupported operations
+
+ /**
+ * {@inheritDoc}
+ */
+ public ExtendedResponse extended( String oid ) throws LdapException
+ {
+ throw new UnsupportedOperationException(
+ "extended operations are not supported on CoreSession based connection" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ExtendedResponse extended( ExtendedRequest extendedRequest ) throws LdapException
+ {
+ return extended( ( String ) null );
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ExtendedResponse extended( OID oid, byte[] value ) throws LdapException
+ {
+ return extended( ( String ) null );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ExtendedResponse extended( OID oid ) throws LdapException
+ {
+ return extended( ( String ) null );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ExtendedResponse extended( String oid, byte[] value ) throws LdapException
+ {
+ return extended( ( String ) null );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setTimeOut( long timeOut )
+ {
+ throw new UnsupportedOperationException( "setting timeout is not supported on CoreSession" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void abandon( AbandonRequest abandonRequest )
+ {
+ throw new UnsupportedOperationException( "abandon operation is not supported" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void abandon( int messageId )
+ {
+ abandon( null );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public BindResponse bind() throws LdapException, IOException
+ {
+ throw new UnsupportedOperationException(
+ "bind operation is not supported cause this connection's session is already bound" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public BindResponse bind( BindRequest bindRequest ) throws LdapException, IOException
+ {
+ return bind();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public BindResponse bind( DN name, String credentials ) throws LdapException, IOException
+ {
+ return bind();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public BindResponse bind( String name, String credentials ) throws LdapException, IOException
+ {
+ return bind();
+ }
+
+}