You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2007/06/12 06:05:01 UTC
svn commit: r546375 -
/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/
Author: erodriguez
Date: Mon Jun 11 21:05:00 2007
New Revision: 546375
URL: http://svn.apache.org/viewvc?view=rev&rev=546375
Log:
Added codec support for the client-side of Change Password.
Added:
directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java (with props)
directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorDecoder.java (with props)
directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyDecoder.java (with props)
directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordRequestEncoder.java (with props)
Modified:
directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorEncoder.java
directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyEncoder.java
Added: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java?view=auto&rev=546375
==============================================================================
--- directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java (added)
+++ directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java Mon Jun 11 21:05:00 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.changepw.io;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.directory.server.changepw.value.ChangePasswordData;
+import org.apache.directory.server.kerberos.shared.io.encoder.PrincipalNameEncoder;
+import org.apache.directory.server.kerberos.shared.messages.value.PrincipalName;
+import org.apache.directory.shared.asn1.der.ASN1OutputStream;
+import org.apache.directory.shared.asn1.der.DERGeneralString;
+import org.apache.directory.shared.asn1.der.DEROctetString;
+import org.apache.directory.shared.asn1.der.DERSequence;
+import org.apache.directory.shared.asn1.der.DERTaggedObject;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ChangePasswordDataEncoder
+{
+ /**
+ * Encodes a {@link ChangePasswordData} into a {@link ByteBuffer}.
+ *
+ * @param data
+ * @param out
+ * @throws IOException
+ */
+ public void encode( ChangePasswordData data, ByteBuffer out ) throws IOException
+ {
+ ASN1OutputStream aos = new ASN1OutputStream( out );
+
+ DERSequence sequence = encodeDataSequence( data );
+ aos.writeObject( sequence );
+
+ aos.close();
+ }
+
+
+ private DERSequence encodeDataSequence( ChangePasswordData data )
+ {
+ DERSequence sequence = new DERSequence();
+ sequence.add( new DERTaggedObject( 0, new DEROctetString( data.getPassword() ) ) );
+
+ PrincipalName name = data.getPrincipalName();
+ KerberosPrincipal principal = new KerberosPrincipal( name.getNameComponent(), name.getNameType() );
+ sequence.add( new DERTaggedObject( 1, PrincipalNameEncoder.encode( principal ) ) );
+
+ sequence.add( new DERTaggedObject( 2, DERGeneralString.valueOf( data.getRealm() ) ) );
+
+ return sequence;
+ }
+}
Propchange: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordDataEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorDecoder.java?view=auto&rev=546375
==============================================================================
--- directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorDecoder.java (added)
+++ directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorDecoder.java Mon Jun 11 21:05:00 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.changepw.io;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.changepw.messages.ChangePasswordError;
+import org.apache.directory.server.changepw.messages.ChangePasswordErrorModifier;
+import org.apache.directory.server.kerberos.shared.io.decoder.ErrorMessageDecoder;
+import org.apache.directory.server.kerberos.shared.messages.ErrorMessage;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ChangePasswordErrorDecoder
+{
+ private static final int HEADER_LENGTH = 6;
+
+
+ /**
+ * Decodes a {@link ByteBuffer} into a {@link ChangePasswordError}.
+ *
+ * @param buf
+ * @return The {@link ChangePasswordError}.
+ * @throws IOException
+ */
+ public ChangePasswordError decode( ByteBuffer buf ) throws IOException
+ {
+ ChangePasswordErrorModifier modifier = new ChangePasswordErrorModifier();
+
+ short messageLength = buf.getShort();
+ modifier.setMessageLength( messageLength );
+
+ modifier.setProtocolVersionNumber( buf.getShort() );
+
+ /*
+ * TODO - No condition to set on modifier.
+ */
+ buf.getShort();
+
+ int errorLength = messageLength - HEADER_LENGTH;
+
+ byte[] errorBytes = new byte[errorLength];
+
+ buf.get( errorBytes );
+
+ ErrorMessageDecoder errorDecoder = new ErrorMessageDecoder();
+ ErrorMessage errorMessage = errorDecoder.decode( buf );
+
+ modifier.setErrorMessage( errorMessage );
+
+ return modifier.getChangePasswordError();
+ }
+}
Propchange: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorDecoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorEncoder.java?view=diff&rev=546375&r1=546374&r2=546375
==============================================================================
--- directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorEncoder.java (original)
+++ directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordErrorEncoder.java Mon Jun 11 21:05:00 2007
@@ -35,6 +35,9 @@
*/
public class ChangePasswordErrorEncoder
{
+ private static final int HEADER_LENGTH = 6;
+
+
/**
* Encodes a {@link ChangePasswordError} into a {@link ByteBuffer}.
*
@@ -49,9 +52,7 @@
ErrorMessageEncoder errorEncoder = new ErrorMessageEncoder();
byte[] errorBytes = errorEncoder.encode( errorMessage );
- short headerLength = 6;
-
- short messageLength = ( short ) ( headerLength + errorBytes.length );
+ short messageLength = ( short ) ( HEADER_LENGTH + errorBytes.length );
buf.putShort( messageLength );
short protocolVersion = 1;
Added: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyDecoder.java?view=auto&rev=546375
==============================================================================
--- directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyDecoder.java (added)
+++ directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyDecoder.java Mon Jun 11 21:05:00 2007
@@ -0,0 +1,79 @@
+/*
+ * 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.changepw.io;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.changepw.messages.ChangePasswordReply;
+import org.apache.directory.server.changepw.messages.ChangePasswordReplyModifier;
+import org.apache.directory.server.kerberos.shared.io.decoder.ApplicationReplyDecoder;
+import org.apache.directory.server.kerberos.shared.io.decoder.PrivateMessageDecoder;
+import org.apache.directory.server.kerberos.shared.messages.application.ApplicationReply;
+import org.apache.directory.server.kerberos.shared.messages.application.PrivateMessage;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ChangePasswordReplyDecoder
+{
+ private static final int HEADER_LENGTH = 6;
+
+
+ /**
+ * Decodes a {@link ByteBuffer} into a {@link ChangePasswordReply}.
+ *
+ * @param buf
+ * @return The {@link ChangePasswordReply}.
+ * @throws IOException
+ */
+ public ChangePasswordReply decode( ByteBuffer buf ) throws IOException
+ {
+ ChangePasswordReplyModifier modifier = new ChangePasswordReplyModifier();
+
+ short messageLength = buf.getShort();
+ short protocolVersion = buf.getShort();
+ short encodedAppReplyLength = buf.getShort();
+
+ modifier.setMessageLength( messageLength );
+ modifier.setProtocolVersionNumber( protocolVersion );
+ modifier.setAuthHeaderLength( encodedAppReplyLength );
+
+ byte[] encodedAppReply = new byte[encodedAppReplyLength];
+ buf.get( encodedAppReply );
+
+ ApplicationReplyDecoder appDecoder = new ApplicationReplyDecoder();
+ ApplicationReply applicationReply = appDecoder.decode( encodedAppReply );
+ modifier.setApplicationReply( applicationReply );
+
+ int privateBytesLength = messageLength - HEADER_LENGTH - encodedAppReplyLength;
+ byte[] encodedPrivateMessage = new byte[privateBytesLength];
+ buf.get( encodedPrivateMessage );
+
+ PrivateMessageDecoder privateDecoder = new PrivateMessageDecoder();
+ PrivateMessage privateMessage = privateDecoder.decode( encodedPrivateMessage );
+ modifier.setPrivateMessage( privateMessage );
+
+ return modifier.getChangePasswordReply();
+ }
+}
Propchange: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyDecoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyEncoder.java?view=diff&rev=546375&r1=546374&r2=546375
==============================================================================
--- directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyEncoder.java (original)
+++ directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordReplyEncoder.java Mon Jun 11 21:05:00 2007
@@ -37,6 +37,9 @@
*/
public class ChangePasswordReplyEncoder
{
+ private static final int HEADER_LENGTH = 6;
+
+
/**
* Encodes a {@link ChangePasswordReply} into a {@link ByteBuffer}.
*
@@ -56,9 +59,7 @@
PrivateMessageEncoder privateEncoder = new PrivateMessageEncoder();
byte[] privateBytes = privateEncoder.encode( privateMessage );
- short headerLength = 6;
-
- short messageLength = ( short ) ( headerLength + encodedAppReply.length + privateBytes.length );
+ short messageLength = ( short ) ( HEADER_LENGTH + encodedAppReply.length + privateBytes.length );
short protocolVersion = 1;
Added: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordRequestEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordRequestEncoder.java?view=auto&rev=546375
==============================================================================
--- directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordRequestEncoder.java (added)
+++ directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordRequestEncoder.java Mon Jun 11 21:05:00 2007
@@ -0,0 +1,72 @@
+/*
+ * 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.changepw.io;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.changepw.messages.ChangePasswordRequest;
+import org.apache.directory.server.kerberos.shared.io.encoder.ApplicationRequestEncoder;
+import org.apache.directory.server.kerberos.shared.io.encoder.PrivateMessageEncoder;
+import org.apache.directory.server.kerberos.shared.messages.ApplicationRequest;
+import org.apache.directory.server.kerberos.shared.messages.application.PrivateMessage;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ChangePasswordRequestEncoder
+{
+ private static final int HEADER_LENGTH = 6;
+
+
+ /**
+ * Encodes a {@link ChangePasswordRequest} into a {@link ByteBuffer}.
+ *
+ * @param buf
+ * @param message
+ * @throws IOException
+ */
+ public void encode( ByteBuffer buf, ChangePasswordRequest message ) throws IOException
+ {
+ // Build application request bytes
+ ApplicationRequest appRequest = message.getAuthHeader();
+ ApplicationRequestEncoder appEncoder = new ApplicationRequestEncoder();
+ byte[] encodedAppRequest = appEncoder.encode( appRequest );
+
+ // Build private message bytes
+ PrivateMessage privateMessage = message.getPrivateMessage();
+ PrivateMessageEncoder privateEncoder = new PrivateMessageEncoder();
+ byte[] privateBytes = privateEncoder.encode( privateMessage );
+
+ short messageLength = ( short ) ( HEADER_LENGTH + encodedAppRequest.length + privateBytes.length );
+
+ short protocolVersion = 1;
+
+ buf.putShort( messageLength );
+ buf.putShort( protocolVersion );
+ buf.putShort( ( short ) encodedAppRequest.length );
+
+ buf.put( encodedAppRequest );
+ buf.put( privateBytes );
+ }
+}
Propchange: directory/apacheds/trunk/protocol-changepw/src/main/java/org/apache/directory/server/changepw/io/ChangePasswordRequestEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native