You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/06/07 13:06:48 UTC
svn commit: r664318 - in
/directory/apacheds/branches/bigbang/protocol-newldap/src:
main/java/org/apache/directory/server/newldap/
main/java/org/apache/directory/server/newldap/handlers/
test/java/org/apache/directory/server/ldap/ test/java/org/apache/...
Author: akarasulu
Date: Sat Jun 7 04:06:48 2008
New Revision: 664318
URL: http://svn.apache.org/viewvc?rev=664318&view=rev
Log:
adding some newldap protocol handler functionality
Added:
directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolConstants.java
directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolUtils.java
directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAbandonHandler.java
directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAddHandler.java (with props)
directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/
directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/LdapServerSettingsTest.java
- copied, changed from r664302, directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/LdapServerSettingsTest.java
directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/SettingAlternativeHandlersTest.java
- copied, changed from r664302, directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/SettingAlternativeHandlersTest.java
Removed:
directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/LdapServerSettingsTest.java
directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/SettingAlternativeHandlersTest.java
Added: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolConstants.java?rev=664318&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolConstants.java (added)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolConstants.java Sat Jun 7 04:06:48 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.newldap;
+
+import javax.naming.ldap.Control;
+
+
+/**
+ * Constants for LDAP protocol service.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface LdapProtocolConstants
+{
+ Control[] EMPTY_CONTROLS = new Control[0];
+ String OUTSTANDING_KEY = "outstandingRequestsKey";
+ String CORE_SESSION_KEY = "coreSessionKey";
+}
Added: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolUtils.java?rev=664318&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolUtils.java (added)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapProtocolUtils.java Sat Jun 7 04:06:48 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.newldap;
+
+
+import org.apache.directory.server.core.interceptor.context.OperationContext;
+import org.apache.directory.shared.ldap.message.Request;
+import org.apache.directory.shared.ldap.message.Response;
+
+
+/**
+ * Utility methods used by the LDAP protocol service.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapProtocolUtils implements LdapProtocolConstants
+{
+ /**
+ * Extracts request controls from a request to populate into an
+ * OperationContext.
+ *
+ * @param opContext the context to populate with request controls
+ * @param request the request to extract controls from
+ */
+ public static void setRequestControls( OperationContext opContext, Request request ) throws Exception
+ {
+ if ( request.getControls() != null )
+ {
+ request.addAll( request.getControls().values().toArray( EMPTY_CONTROLS ) );
+ }
+ }
+
+
+ /**
+ * Extracts response controls from a an OperationContext to populate into
+ * a Response object.
+ *
+ * @param opContext the context to extract controls from
+ * @param response the response to populate with response controls
+ */
+ public static void setResponseControls( OperationContext opContext, Response response ) throws Exception
+ {
+ opContext.addRequestControls( opContext.getResponseControls() );
+ }
+}
Added: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java?rev=664318&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java (added)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/LdapRequestHandler.java Sat Jun 7 04:06:48 2008
@@ -0,0 +1,121 @@
+/*
+ * 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.newldap.handlers;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.newldap.LdapProtocolConstants;
+import org.apache.directory.server.newldap.LdapServer;
+import org.apache.directory.shared.ldap.message.AbandonableRequest;
+import org.apache.directory.shared.ldap.message.Request;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.handler.demux.MessageHandler;
+
+
+/**
+ * A base class for all handlers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 541827 $
+ */
+public abstract class LdapRequestHandler<T extends Request> implements MessageHandler<T>, LdapProtocolConstants
+{
+ private Object outstandingLock;
+ private LdapServer ldapServer;
+
+
+ public final LdapServer getLdapServer()
+ {
+ return ldapServer;
+ }
+
+
+ public final void setLdapServer( LdapServer provider )
+ {
+ this.ldapServer = provider;
+ }
+
+
+ public final CoreSession getCoreSession( IoSession session )
+ {
+ return ( CoreSession ) session.getAttribute( CORE_SESSION_KEY );
+ }
+
+
+ public final void setCoreSession( IoSession session, CoreSession coreSession )
+ {
+ session.setAttribute( CORE_SESSION_KEY, coreSession );
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public final AbandonableRequest getOutstandingRequest( IoSession session, Integer id )
+ {
+ synchronized( outstandingLock )
+ {
+ Map<Integer, AbandonableRequest> outstanding = ( Map<Integer, AbandonableRequest> ) session.getAttribute( OUTSTANDING_KEY );
+
+ if ( outstanding == null )
+ {
+ return null;
+ }
+
+ return outstanding.get( id );
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public final AbandonableRequest removeOutstandingRequest( IoSession session, Integer id )
+ {
+ synchronized( outstandingLock )
+ {
+ Map<Integer, AbandonableRequest> outstanding = ( Map<Integer, AbandonableRequest> ) session.getAttribute( OUTSTANDING_KEY );
+
+ if ( outstanding == null )
+ {
+ return null;
+ }
+
+ return outstanding.remove( id );
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public void setOutstandingRequest( IoSession session, AbandonableRequest request )
+ {
+ synchronized( outstandingLock )
+ {
+ Map<Integer, AbandonableRequest> outstanding = ( Map<Integer, AbandonableRequest> ) session.getAttribute( OUTSTANDING_KEY );
+
+ if ( outstanding == null )
+ {
+ outstanding = new HashMap<Integer, AbandonableRequest>();
+ session.setAttribute( OUTSTANDING_KEY, outstanding );
+ }
+
+ outstanding.put( request.getMessageId(), request );
+ }
+ }
+}
Added: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAbandonHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAbandonHandler.java?rev=664318&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAbandonHandler.java (added)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAbandonHandler.java Sat Jun 7 04:06:48 2008
@@ -0,0 +1,76 @@
+/*
+ * 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.newldap.handlers;
+
+
+import org.apache.directory.shared.ldap.message.AbandonRequest;
+import org.apache.directory.shared.ldap.message.AbandonableRequest;
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * AbandonRequest handler implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewAbandonHandler extends LdapRequestHandler<AbandonRequest>
+{
+ private static final Logger LOG = LoggerFactory.getLogger( NewAbandonHandler.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+ /* (non-Javadoc)
+ * @see org.apache.mina.handler.demux.MessageHandler#messageReceived(
+ * org.apache.mina.common.IoSession, java.lang.Object)
+ */
+ public void messageReceived( IoSession session, AbandonRequest request ) throws Exception
+ {
+ int abandonedId = request.getAbandoned();
+
+ if ( abandonedId < 0 )
+ {
+ return;
+ }
+
+ AbandonableRequest abandonedRequest = getOutstandingRequest( session, abandonedId );
+
+ if ( abandonedRequest == null )
+ {
+ if ( LOG.isWarnEnabled() )
+ {
+ LOG.warn( "{}: Cannot find outstanding request {} to abandon.", session, request.getAbandoned() );
+ }
+
+ return;
+ }
+
+ abandonedRequest.abandon();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "{}: Request {} was successfully flagged as abandoned.", abandonedRequest );
+ }
+ }
+}
Added: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAddHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAddHandler.java?rev=664318&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAddHandler.java (added)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAddHandler.java Sat Jun 7 04:06:48 2008
@@ -0,0 +1,155 @@
+/*
+ * 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.newldap.handlers;
+
+
+import javax.naming.NamingException;
+import javax.naming.ReferralException;
+
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.entry.ServerEntryUtils;
+import org.apache.directory.server.core.interceptor.context.AddOperationContext;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
+import org.apache.directory.shared.ldap.message.AddRequest;
+import org.apache.directory.shared.ldap.message.LdapResult;
+import org.apache.directory.shared.ldap.message.ReferralImpl;
+import org.apache.directory.shared.ldap.message.Request;
+import org.apache.directory.shared.ldap.message.Response;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.apache.mina.common.IoSession;
+
+import static org.apache.directory.server.newldap.LdapProtocolUtils.*;
+
+
+/**
+ * An LDAP add operation {@link AddRequest} handler.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewAddHandler extends LdapRequestHandler<AddRequest>
+{
+ /* (non-Javadoc)
+ * @see org.apache.mina.handler.demux.MessageHandler#messageReceived(org.apache.mina.common.IoSession,
+ * java.lang.Object)
+ */
+ public void messageReceived( IoSession session, AddRequest request ) throws Exception
+ {
+ LdapResult result = request.getResultResponse().getLdapResult();
+ CoreSession coreSession = getCoreSession( session );
+
+ if ( ! getLdapServer().isAllowAnonymousAccess() )
+ {
+ throw new LdapNoPermissionException( "Anonymous binds have been disabled!" );
+ }
+
+ if ( coreSession == null )
+ {
+ coreSession = getLdapServer().getDirectoryService().getSession();
+ setCoreSession( session, coreSession );
+ }
+
+ try
+ {
+ ServerEntry entry = ServerEntryUtils.toServerEntry( request.getAttributes(), request.getEntry(),
+ coreSession.getDirectoryService().getRegistries() );
+ AddOperationContext opContext = new AddOperationContext( coreSession, entry );
+ setRequestControls( opContext, request );
+ coreSession.getDirectoryService().getOperationManager().add( opContext );
+ setResponseControls( opContext, request.getResultResponse() );
+ }
+ catch( ReferralException e )
+ {
+ ReferralImpl refs = new ReferralImpl();
+ result.setReferral( refs );
+ result.setResultCode( ResultCodeEnum.REFERRAL );
+ result.setErrorMessage( "Encountered referral attempting to handle add request." );
+
+ if ( e.getResolvedName() != null )
+ {
+ result.setMatchedDn( new LdapDN( e.getResolvedName().toString() ) );
+ }
+
+ do
+ {
+ refs.addLdapUrl( ( String ) e.getReferralInfo() );
+ }
+ while ( e.skipReferral() );
+
+ session.write( request.getResultResponse() );
+ }
+ catch ( Throwable t )
+ {
+ ResultCodeEnum resultCode = ResultCodeEnum.OTHER;
+
+ if ( t instanceof LdapException )
+ {
+ resultCode = ( ( LdapException ) t ).getResultCode();
+ }
+ else
+ {
+ resultCode = ResultCodeEnum.getBestEstimate( t, request.getType() );
+ }
+
+ result.setResultCode( resultCode );
+
+ String msg = session + "failed to add entry " + request.getEntry() + ": " + t.getMessage();
+// if ( LOG.isDebugEnabled() )
+// {
+// msg += ":\n" + ExceptionUtils.getStackTrace( t );
+// }
+
+ result.setErrorMessage( msg );
+ result.setErrorMessage( msg );
+
+ boolean setMatchedDn =
+ resultCode == ResultCodeEnum.NO_SUCH_OBJECT ||
+ resultCode == ResultCodeEnum.ALIAS_PROBLEM ||
+ resultCode == ResultCodeEnum.INVALID_DN_SYNTAX ||
+ resultCode == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
+
+ if ( setMatchedDn )
+ {
+ if ( t instanceof NamingException )
+ {
+ NamingException ne = ( NamingException ) t;
+ if ( ne.getResolvedName() != null )
+ {
+ result.setMatchedDn( ( LdapDN ) ne.getResolvedName() );
+ }
+ else
+ {
+// coreSession.getMatchedDn( request.getEntry() );
+ }
+ }
+ else
+ {
+
+ }
+ }
+
+ session.write( request.getResultResponse() );
+ }
+ }
+}
Propchange: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewAddHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/LdapServerSettingsTest.java (from r664302, directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/LdapServerSettingsTest.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/LdapServerSettingsTest.java?p2=directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/LdapServerSettingsTest.java&p1=directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/LdapServerSettingsTest.java&r1=664302&r2=664318&rev=664318&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/LdapServerSettingsTest.java (original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/LdapServerSettingsTest.java Sat Jun 7 04:06:48 2008
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.directory.server.ldap;
+package org.apache.directory.server.newldap;
import org.junit.Test;
Copied: directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/SettingAlternativeHandlersTest.java (from r664302, directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/SettingAlternativeHandlersTest.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/SettingAlternativeHandlersTest.java?p2=directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/SettingAlternativeHandlersTest.java&p1=directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/SettingAlternativeHandlersTest.java&r1=664302&r2=664318&rev=664318&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/ldap/SettingAlternativeHandlersTest.java (original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/test/java/org/apache/directory/server/newldap/SettingAlternativeHandlersTest.java Sat Jun 7 04:06:48 2008
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.directory.server.ldap;
+package org.apache.directory.server.newldap;
import junit.framework.TestCase;