directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r546747 - in /directory/clients/trunk/kerberos/password/src/main: java/org/apache/directory/client/password/protocol/ resources/
Date Wed, 13 Jun 2007 06:15:57 GMT
Author: erodriguez
Date: Tue Jun 12 23:15:56 2007
New Revision: 546747

URL: http://svn.apache.org/viewvc?view=rev&rev=546747
Log:
o Added MINA handler and codecs for client-side Change Password.
o Added logging support.

Added:
    directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientCodecFactory.java
  (with props)
    directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientDecoder.java
  (with props)
    directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientEncoder.java
  (with props)
    directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientHandler.java
  (with props)
    directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/package-info.java
  (with props)
    directory/clients/trunk/kerberos/password/src/main/resources/
    directory/clients/trunk/kerberos/password/src/main/resources/log4j.properties   (with
props)

Added: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientCodecFactory.java?view=auto&rev=546747
==============================================================================
--- directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientCodecFactory.java
(added)
+++ directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientCodecFactory.java
Tue Jun 12 23:15:56 2007
@@ -0,0 +1,66 @@
+/*
+ *  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.client.password.protocol;
+
+
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PasswordClientCodecFactory implements ProtocolCodecFactory
+{
+    private static final PasswordClientCodecFactory INSTANCE = new PasswordClientCodecFactory();
+
+
+    /**
+     * Returns the singleton {@link PasswordClientCodecFactory}.
+     *
+     * @return The singleton {@link PasswordClientCodecFactory}.
+     */
+    public static PasswordClientCodecFactory getInstance()
+    {
+        return INSTANCE;
+    }
+
+
+    private PasswordClientCodecFactory()
+    {
+        // Private constructor prevents instantiation outside this class.
+    }
+
+
+    public ProtocolEncoder getEncoder()
+    {
+        // Create a new encoder.
+        return new PasswordClientEncoder();
+    }
+
+
+    public ProtocolDecoder getDecoder()
+    {
+        // Create a new decoder.
+        return new PasswordClientDecoder();
+    }
+}

Propchange: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientCodecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientDecoder.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientDecoder.java?view=auto&rev=546747
==============================================================================
--- directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientDecoder.java
(added)
+++ directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientDecoder.java
Tue Jun 12 23:15:56 2007
@@ -0,0 +1,62 @@
+/*
+ *  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.client.password.protocol;
+
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.directory.server.changepw.io.ChangePasswordReplyDecoder;
+import org.apache.directory.server.kerberos.shared.io.decoder.ErrorMessageDecoder;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PasswordClientDecoder extends ProtocolDecoderAdapter
+{
+    private static final byte[] ERROR = new byte[]
+        { ( byte ) 0x7E, ( byte ) 0x78, ( byte ) 0x30, ( byte ) 0x76 };
+
+    private ChangePasswordReplyDecoder replyDecoder = new ChangePasswordReplyDecoder();
+    private ErrorMessageDecoder errorDecoder = new ErrorMessageDecoder();
+
+
+    public void decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out ) throws
IOException
+    {
+        byte[] header = new byte[4];
+        in.get( header );
+        in.rewind();
+
+        if ( Arrays.equals( ERROR, header ) )
+        {
+            out.write( errorDecoder.decode( in.buf() ) );
+        }
+        else
+        {
+            out.write( replyDecoder.decode( in.buf() ) );
+        }
+    }
+}

Propchange: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientEncoder.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientEncoder.java?view=auto&rev=546747
==============================================================================
--- directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientEncoder.java
(added)
+++ directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientEncoder.java
Tue Jun 12 23:15:56 2007
@@ -0,0 +1,52 @@
+/*
+ *  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.client.password.protocol;
+
+
+import java.io.IOException;
+
+import org.apache.directory.server.changepw.io.ChangePasswordRequestEncoder;
+import org.apache.directory.server.changepw.messages.ChangePasswordRequest;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PasswordClientEncoder extends ProtocolEncoderAdapter
+{
+    private ChangePasswordRequestEncoder requestEncoder = new ChangePasswordRequestEncoder();
+
+
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws
IOException
+    {
+        ByteBuffer buf = ByteBuffer.allocate( 1024 );
+
+        requestEncoder.encode( buf.buf(), ( ChangePasswordRequest ) message );
+
+        buf.flip();
+
+        out.write( buf );
+    }
+}

Propchange: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientHandler.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientHandler.java?view=auto&rev=546747
==============================================================================
--- directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientHandler.java
(added)
+++ directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientHandler.java
Tue Jun 12 23:15:56 2007
@@ -0,0 +1,69 @@
+/*
+ *  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.client.password.protocol;
+
+
+import org.apache.directory.server.changepw.messages.ChangePasswordReply;
+import org.apache.directory.server.kerberos.shared.messages.ErrorMessage;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An {@link IoHandler} implementation for a Kerberos client.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PasswordClientHandler extends IoHandlerAdapter
+{
+    private static final Logger log = LoggerFactory.getLogger( PasswordClientHandler.class
);
+
+
+    public void messageReceived( IoSession session, Object message )
+    {
+        if ( message instanceof ChangePasswordReply )
+        {
+            ChangePasswordReply reply = ( ChangePasswordReply ) message;
+            session.setAttribute( "reply", reply );
+        }
+        else
+        {
+            if ( message instanceof ErrorMessage )
+            {
+                ErrorMessage error = ( ErrorMessage ) message;
+                log.debug( error.getExplanatoryText() );
+            }
+        }
+
+        session.close();
+    }
+
+
+    public void exceptionCaught( IoSession session, Throwable cause )
+    {
+        log.error( session.getRemoteAddress() + " EXCEPTION", cause );
+
+        session.close();
+    }
+}

Propchange: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/PasswordClientHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/package-info.java
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/package-info.java?view=auto&rev=546747
==============================================================================
--- directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/package-info.java
(added)
+++ directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/package-info.java
Tue Jun 12 23:15:56 2007
@@ -0,0 +1,31 @@
+/*
+ *  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. 
+ *  
+ */
+
+/**
+ * Provides the {@link IoHandler} and associated {@link ProtocolCodecFactory}
+ * required to implement a Change Password client with the MINA NIO framework.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+
+package org.apache.directory.client.password.protocol;
+
+

Propchange: directory/clients/trunk/kerberos/password/src/main/java/org/apache/directory/client/password/protocol/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/clients/trunk/kerberos/password/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/clients/trunk/kerberos/password/src/main/resources/log4j.properties?view=auto&rev=546747
==============================================================================
--- directory/clients/trunk/kerberos/password/src/main/resources/log4j.properties (added)
+++ directory/clients/trunk/kerberos/password/src/main/resources/log4j.properties Tue Jun
12 23:15:56 2007
@@ -0,0 +1,26 @@
+log4j.rootCategory=WARN, stdout, R
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+
+log4j.appender.R=org.apache.log4j.RollingFileAppender
+log4j.appender.R.File=apacheds-rolling.log
+
+log4j.appender.R.MaxFileSize=1024KB
+# Keep some backup files
+log4j.appender.R.MaxBackupIndex=5
+
+log4j.appender.R.layout=org.apache.log4j.PatternLayout
+log4j.appender.R.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+# with these we'll not get innundated when switching to DEBUG
+log4j.logger.org.apache.directory.shared.ldap.name=WARN
+log4j.logger.org.springframework=WARN
+log4j.logger.org.apache.directory.shared.codec=WARN
+log4j.logger.org.apache.directory.shared.asn1=WARN
+
+
+# client is in debug mode since it is still under heavy development
+log4j.logger.org.apache.directory.client=DEBUG

Propchange: directory/clients/trunk/kerberos/password/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message