You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2013/04/17 00:26:53 UTC
svn commit: r1468645 - in /directory/shared/trunk/ldap/extras:
codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/
codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/
codec/src/test/java/org/apache/d...
Author: elecharny
Date: Tue Apr 16 22:26:53 2013
New Revision: 1468645
URL: http://svn.apache.org/r1468645
Log:
First drop of code for the PwdModify extended operation codec (not finished yet)
Added:
directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequest.java
directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequestImpl.java
directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponse.java
directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponseImpl.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestConstants.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestContainer.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecoder.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecorator.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestStatesEnum.java
directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java
Added: directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequest.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequest.java (added)
+++ directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequest.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,60 @@
+/*
+ * 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.api.ldap.extras.extended;
+
+
+import org.apache.directory.api.ldap.model.message.ExtendedRequest;
+
+
+/**
+ * The RFC 3062 PwdModify request :
+ *
+ * <pre>
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * userIdentity [0] OCTET STRING OPTIONAL
+ * oldPasswd [1] OCTET STRING OPTIONAL
+ * newPasswd [2] OCTET STRING OPTIONAL }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface PwdModifyRequest extends ExtendedRequest<PwdModifyResponse>
+{
+ /** The OID for the pwdModify extended operation request. */
+ String EXTENSION_OID = "1.3.6.1.4.1.4203.1.11.1";
+
+
+ /**
+ * @return the userIdentity
+ */
+ byte[] getUserIdentity();
+
+
+ /**
+ * @return the oldPassword
+ */
+ byte[] getOldPassword();
+
+
+ /**
+ * @return the newPassword
+ */
+ byte[] getNewPassword();
+}
Added: directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequestImpl.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequestImpl.java (added)
+++ directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyRequestImpl.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,135 @@
+/*
+ * 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.api.ldap.extras.extended;
+
+
+import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest;
+
+
+/**
+ * The RFC 3062 PwdModify request :
+ *
+ * <pre>
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * userIdentity [0] OCTET STRING OPTIONAL
+ * oldPasswd [1] OCTET STRING OPTIONAL
+ * newPasswd [2] OCTET STRING OPTIONAL }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PwdModifyRequestImpl extends AbstractExtendedRequest<PwdModifyResponse> implements PwdModifyRequest
+{
+ /** The user identity */
+ private byte[] userIdentity;
+
+ /** The previous password */
+ private byte[] oldPassword;
+
+ /** The new password */
+ private byte[] newPassword;
+
+
+ /**
+ * Create a new instance of the PwdModifyRequest extended operation
+ */
+ public PwdModifyRequestImpl()
+ {
+ }
+
+
+ /**
+ * Create a new instance of the PwdModifyRequest extended operation
+ *
+ * @param messageId The message ID
+ */
+ public PwdModifyRequestImpl( int messageId )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getUserIdentity()
+ {
+ return userIdentity;
+ }
+
+
+ /**
+ * @param userIdentity the userIdentity to set
+ */
+ public void setUserIdentity( byte[] userIdentity )
+ {
+ this.userIdentity = userIdentity;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getOldPassword()
+ {
+ return oldPassword;
+ }
+
+
+ /**
+ * @param oldPassword the oldPassword to set
+ */
+ public void setOldPassword( byte[] oldPassword )
+ {
+ this.oldPassword = oldPassword;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getNewPassword()
+ {
+ return newPassword;
+ }
+
+
+ /**
+ * @param newPassword the newPassword to set
+ */
+ public void setNewPassword( byte[] newPassword )
+ {
+ this.newPassword = newPassword;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PwdModifyResponse getResultResponse()
+ {
+ if ( response == null )
+ {
+ response = new PwdModifyResponseImpl();
+ }
+
+ return response;
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponse.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponse.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponse.java (added)
+++ directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponse.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.api.ldap.extras.extended;
+
+
+import org.apache.directory.api.ldap.model.message.ExtendedResponse;
+
+
+/**
+ * The RFC 3062 PwdModify response :
+ *
+ * <pre>
+ * PasswdModifyResponseValue ::= SEQUENCE {
+ * genPasswd [0] OCTET STRING OPTIONAL }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface PwdModifyResponse extends ExtendedResponse
+{
+ /** The OID for the PwdModify extended operation response. */
+ String EXTENSION_OID = PwdModifyRequest.EXTENSION_OID;
+
+
+ /**
+ * Get the generated password
+ *
+ * @return The generated password or null
+ */
+ byte[] getGenPassword();
+}
Added: directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponseImpl.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponseImpl.java (added)
+++ directory/shared/trunk/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/PwdModifyResponseImpl.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,115 @@
+/*
+ * 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.api.ldap.extras.extended;
+
+
+import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
+import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
+
+
+/**
+ * The RFC 3062 PwdModify response :
+ *
+ * <pre>
+ * PasswdModifyResponseValue ::= SEQUENCE {
+ * genPasswd [0] OCTET STRING OPTIONAL }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PwdModifyResponseImpl extends ExtendedResponseImpl implements PwdModifyResponse
+{
+ /** The generated password */
+ private byte[] genPassword;
+
+
+ /**
+ * Create a new instance for the PwdModify response
+ * @param messageId The Message ID
+ * @param rcode The result code
+ */
+ public PwdModifyResponseImpl( int messageId, ResultCodeEnum rcode )
+ {
+ super( messageId, EXTENSION_OID );
+
+ switch ( rcode )
+ {
+ case SUCCESS:
+ break;
+
+ case OPERATIONS_ERROR:
+ break;
+
+ case INSUFFICIENT_ACCESS_RIGHTS:
+ break;
+
+ default:
+ throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
+ ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
+ }
+
+ super.getLdapResult().setMatchedDn( null );
+ super.getLdapResult().setResultCode( rcode );
+ }
+
+
+ /**
+ * Instantiates a new password Modify response.
+ *
+ * @param messageId the message id
+ */
+ public PwdModifyResponseImpl( int messageId )
+ {
+ super( messageId, EXTENSION_OID );
+ super.getLdapResult().setMatchedDn( null );
+ super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+ }
+
+
+ /**
+ * Instantiates a new password Modify response.
+ */
+ public PwdModifyResponseImpl()
+ {
+ super( EXTENSION_OID );
+ super.getLdapResult().setMatchedDn( null );
+ super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getGenPassword()
+ {
+ return genPassword;
+ }
+
+
+ /**
+ * Set the generated Password
+ * @param genPassword The generated password
+ */
+ public void setGenPassword( byte[] genPassword )
+ {
+ this.genPassword = genPassword;
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,129 @@
+/*
+ * 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.api.ldap.extras.extended.ads_impl.pwdModify;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.AbstractAsn1Object;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.TLV;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.ldap.extras.extended.PwdModifyRequest;
+
+
+/**
+ * An extended operation to proceed a pwdModify operation, as described
+ * in RFC 3062
+ *
+ * <pre>
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * userIdentity [0] OCTET STRING OPTIONAL
+ * oldPasswd [1] OCTET STRING OPTIONAL
+ * newPasswd [2] OCTET STRING OPTIONAL }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PasswordModifyRequest extends AbstractAsn1Object
+{
+ private PwdModifyRequest pwdModifyRequest;
+
+
+ public PasswordModifyRequest( PwdModifyRequest pwdModifyRequest )
+ {
+ this.pwdModifyRequest = pwdModifyRequest;
+ }
+
+ /** stores the length of the request*/
+ private int requestLength = 0;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int computeLength()
+ {
+ if ( pwdModifyRequest.getUserIdentity() != null )
+ {
+ int len = pwdModifyRequest.getUserIdentity().length;
+ requestLength = 1 + BerValue.getNbBytes( len ) + len;
+ }
+
+ if ( pwdModifyRequest.getOldPassword() != null )
+ {
+ int len = pwdModifyRequest.getOldPassword().length;
+ requestLength = 1 + BerValue.getNbBytes( len ) + len;
+ }
+
+ if ( pwdModifyRequest.getNewPassword() != null )
+ {
+ int len = pwdModifyRequest.getNewPassword().length;
+ requestLength = 1 + BerValue.getNbBytes( len ) + len;
+ }
+
+ return 1 + BerValue.getNbBytes( requestLength ) + requestLength;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ByteBuffer encode() throws EncoderException
+ {
+ ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+
+ bb.put( UniversalTag.SEQUENCE.getValue() );
+ bb.put( BerValue.getBytes( requestLength ) );
+
+ if ( pwdModifyRequest.getUserIdentity() != null )
+ {
+ byte[] userIdentity = pwdModifyRequest.getUserIdentity();
+ bb.put( ( byte ) PasswordModifyRequestConstants.USER_IDENTITY_TAG );
+ bb.put( TLV.getBytes( userIdentity.length ) );
+ bb.put( userIdentity );
+ }
+
+ if ( pwdModifyRequest.getOldPassword() != null )
+ {
+ byte[] oldPassword = pwdModifyRequest.getOldPassword();
+ bb.put( ( byte ) PasswordModifyRequestConstants.OLD_PASSWORD_TAG );
+ bb.put( TLV.getBytes( oldPassword.length ) );
+ bb.put( oldPassword );
+ }
+
+ if ( pwdModifyRequest.getNewPassword() != null )
+ {
+ byte[] newPassword = pwdModifyRequest.getNewPassword();
+ bb.put( ( byte ) PasswordModifyRequestConstants.NEW_PASSWORD_TAG );
+ bb.put( TLV.getBytes( newPassword.length ) );
+ bb.put( newPassword );
+ }
+
+ return bb;
+ }
+
+
+ public PwdModifyRequest getPwdModifyRequest()
+ {
+ return pwdModifyRequest;
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestConstants.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestConstants.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestConstants.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestConstants.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.api.ldap.extras.extended.ads_impl.pwdModify;
+
+
+/**
+ * PasswordModifyRequest extended operation constants
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class PasswordModifyRequestConstants
+{
+ /** This is the TAG used for the userIdentity. It's a contextual primitive Tag */
+ public static final int USER_IDENTITY_TAG = 0x80;
+
+ /** This is the TAG used for the userIdentity. It's a contextual primitive Tag */
+ public static final int OLD_PASSWORD_TAG = 0x81;
+
+ /** This is the TAG used for the userIdentity. It's a contextual primitive Tag */
+ public static final int NEW_PASSWORD_TAG = 0x82;
+
+
+ /**
+ * Private constructor.
+ */
+ private PasswordModifyRequestConstants()
+ {
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestContainer.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestContainer.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestContainer.java Tue Apr 16 22:26:53 2013
@@ -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.api.ldap.extras.extended.ads_impl.pwdModify;
+
+
+import org.apache.directory.api.asn1.ber.AbstractContainer;
+
+
+/**
+ * A container for certificate generation request codec.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PasswordModifyRequestContainer extends AbstractContainer
+{
+ /** PasswordModifyRequest decorator*/
+ private PasswordModifyRequestDecorator pwdModifyRequest;
+
+
+ /**
+ * Creates a new PasswordModifyContainer object. We will store one
+ * grammar, it's enough ...
+ */
+ public PasswordModifyRequestContainer()
+ {
+ super();
+ stateStack = new int[1];
+ grammar = PasswordModifyRequestGrammar.getInstance();
+ setTransition( PasswordModifyRequestStatesEnum.START_STATE );
+ }
+
+
+ /**
+ * @return Returns the PwdModifyRequest instance.
+ */
+ public PasswordModifyRequestDecorator getPasswordModifyRequest()
+ {
+ return pwdModifyRequest;
+ }
+
+
+ /**
+ * Set a PasswordModifyRequest Object into the container. It will be completed by
+ * the ldapDecoder.
+ *
+ * @param pwdModifyRequest the PasswordModifyRequest to set.
+ */
+ public void setPasswordModifyRequest( PasswordModifyRequestDecorator pwdModifyRequest )
+ {
+ this.pwdModifyRequest = pwdModifyRequest;
+ }
+
+
+ /**
+ * Clean the container for the next decoding.
+ */
+ public void clean()
+ {
+ super.clean();
+ pwdModifyRequest = null;
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecoder.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecoder.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecoder.java Tue Apr 16 22:26:53 2013
@@ -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.api.ldap.extras.extended.ads_impl.pwdModify;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.Asn1Object;
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.ber.Asn1Decoder;
+
+
+/**
+ *
+ * A decoder for PasswordModifyRequest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PasswordModifyRequestDecoder extends Asn1Decoder
+{
+ /** The decoder */
+ private static final Asn1Decoder decoder = new Asn1Decoder();
+
+
+ /**
+ * Decode a PDU which must contain a PwdModifyRequest extended operation.
+ * Note that the stream of bytes much contain a full PDU, not a partial one.
+ *
+ * @param stream The bytes to be decoded
+ * @return a PwdModifyRequest object
+ * @throws org.apache.directory.api.asn1.DecoderException If the decoding failed
+ */
+ public Asn1Object decode( byte[] stream ) throws DecoderException
+ {
+ ByteBuffer bb = ByteBuffer.wrap( stream );
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+ decoder.decode( bb, container );
+ PasswordModifyRequestDecorator passwordModifyRequestDecorator = container.getPasswordModifyRequest();
+
+ // Clean the container for the next decoding
+ container.clean();
+
+ return passwordModifyRequestDecorator.getPasswordModifyRequest();
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecorator.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecorator.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestDecorator.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,156 @@
+/*
+ * 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.api.ldap.extras.extended.ads_impl.pwdModify;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.ExtendedRequestDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.extras.extended.PwdModifyRequest;
+import org.apache.directory.api.ldap.extras.extended.PwdModifyResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A Decorator for PasswordModify extended request.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PasswordModifyRequestDecorator
+ extends ExtendedRequestDecorator<PwdModifyRequest, PwdModifyResponse>
+ implements PwdModifyRequest
+{
+ private static final Logger LOG = LoggerFactory.getLogger( PasswordModifyRequestDecorator.class );
+
+ private PasswordModifyRequest passwordModifyRequest;
+
+
+ public PasswordModifyRequestDecorator( LdapApiService codec, PwdModifyRequest decoratedMessage )
+ {
+ super( codec, decoratedMessage );
+ passwordModifyRequest = new PasswordModifyRequest( decoratedMessage );
+ }
+
+
+ public PasswordModifyRequest getPasswordModifyRequest()
+ {
+ return passwordModifyRequest;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setRequestValue( byte[] requestValue )
+ {
+ PasswordModifyRequestDecoder decoder = new PasswordModifyRequestDecoder();
+
+ try
+ {
+ passwordModifyRequest = ( PasswordModifyRequest ) decoder.decode( requestValue );
+
+ if ( requestValue != null )
+ {
+ this.requestValue = new byte[requestValue.length];
+ System.arraycopy( requestValue, 0, this.requestValue, 0, requestValue.length );
+ }
+ else
+ {
+ this.requestValue = null;
+ }
+ }
+ catch ( DecoderException e )
+ {
+ LOG.error( I18n.err( I18n.ERR_04165 ), e );
+ throw new RuntimeException( e );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public byte[] getRequestValue()
+ {
+ if ( requestValue == null )
+ {
+ try
+ {
+ requestValue = passwordModifyRequest.encode().array();
+ }
+ catch ( EncoderException e )
+ {
+ LOG.error( I18n.err( I18n.ERR_04167 ), e );
+ throw new RuntimeException( e );
+ }
+ }
+
+ if ( requestValue == null )
+ {
+ return null;
+ }
+
+ final byte[] copy = new byte[requestValue.length];
+ System.arraycopy( requestValue, 0, copy, 0, requestValue.length );
+ return copy;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PwdModifyResponse getResultResponse()
+ {
+ return getDecorated().getResultResponse();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getUserIdentity()
+ {
+ return getDecorated().getUserIdentity();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getOldPassword()
+ {
+ return getDecorated().getOldPassword();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getNewPassword()
+ {
+ return getDecorated().getNewPassword();
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,233 @@
+/*
+ * 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.api.ldap.extras.extended.ads_impl.pwdModify;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.api.asn1.ber.grammar.Grammar;
+import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
+import org.apache.directory.api.ldap.extras.extended.PwdModifyRequestImpl;
+import org.apache.directory.api.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the PasswordModify extended operation's ASN.1 grammer.
+ * All the actions are declared in this class. As it is a singleton,
+ * these declaration are only done once. The grammar is :
+ *
+ * <pre>
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * userIdentity [0] OCTET STRING OPTIONAL
+ * oldPasswd [1] OCTET STRING OPTIONAL
+ * newPasswd [2] OCTET STRING OPTIONAL }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+
+public class PasswordModifyRequestGrammar extends AbstractGrammar<PasswordModifyRequestContainer>
+{
+
+ /** logger */
+ private static final Logger LOG = LoggerFactory.getLogger( PasswordModifyRequestGrammar.class );
+
+ /** Speedup for logs */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. PasswdModifyRequestGrammar is a singleton */
+ private static Grammar<PasswordModifyRequestContainer> instance = new PasswordModifyRequestGrammar();
+
+
+ @SuppressWarnings("unchecked")
+ public PasswordModifyRequestGrammar()
+ {
+ setName( PasswordModifyRequestGrammar.class.getName() );
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[PasswordModifyRequestStatesEnum.LAST_PASSWORD_MODIFY_REQUEST_STATE
+ .ordinal()][256];
+
+ /**
+ * Transition from init state to PasswordModify Request Value
+ *
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * ...
+ *
+ * Creates the PasswdModifyRequest object
+ */
+ super.transitions[PasswordModifyRequestStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
+ new GrammarTransition<PasswordModifyRequestContainer>(
+ PasswordModifyRequestStatesEnum.START_STATE,
+ PasswordModifyRequestStatesEnum.PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE,
+ UniversalTag.SEQUENCE.getValue(), new GrammarAction<PasswordModifyRequestContainer>(
+ "Init PasswordModifyRequest" )
+ {
+ public void action( PasswordModifyRequestContainer container )
+ {
+ PasswordModifyRequestDecorator passwordModifyRequest = new PasswordModifyRequestDecorator(
+ LdapApiServiceFactory.getSingleton(), new PwdModifyRequestImpl() );
+ container.setPasswordModifyRequest( passwordModifyRequest );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+
+ /**
+ * Transition from PasswordModify Request Value to userIdentity
+ *
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * userIdentity [0] OCTET STRING OPTIONAL
+ * ...
+ *
+ * Set the userIdentity into the PasswdModifyRequest instance.
+ */
+ super.transitions[PasswordModifyRequestStatesEnum.PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE.ordinal()][PasswordModifyRequestConstants.USER_IDENTITY_TAG] =
+ new GrammarTransition<PasswordModifyRequestContainer>(
+ PasswordModifyRequestStatesEnum.PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE,
+ PasswordModifyRequestStatesEnum.USER_IDENTITY_STATE,
+ PasswordModifyRequestConstants.USER_IDENTITY_TAG,
+ new GrammarAction<PasswordModifyRequestContainer>( "Set PasswordModifyRequest user identity" )
+ {
+ public void action( PasswordModifyRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] userIdentity = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "UserIdentity = " + Strings.dumpBytes( userIdentity ) );
+ }
+
+ if ( userIdentity == null )
+ {
+ userIdentity = Strings.EMPTY_BYTES;
+ }
+
+ ( ( PwdModifyRequestImpl ) container.getPasswordModifyRequest().getDecorated() )
+ .setUserIdentity( userIdentity );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+
+ /**
+ * Transition from PasswordModify Request Value to oldPassword
+ *
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * ...
+ * oldPassword [1] OCTET STRING OPTIONAL
+ * ...
+ *
+ * Set the oldPassword into the PasswdModifyRequest instance.
+ */
+ super.transitions[PasswordModifyRequestStatesEnum.PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE.ordinal()][PasswordModifyRequestConstants.OLD_PASSWORD_TAG] =
+ new GrammarTransition<PasswordModifyRequestContainer>(
+ PasswordModifyRequestStatesEnum.PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE,
+ PasswordModifyRequestStatesEnum.OLD_PASSWORD_STATE,
+ PasswordModifyRequestConstants.OLD_PASSWORD_TAG,
+ new GrammarAction<PasswordModifyRequestContainer>( "Set PasswordModifyRequest oldPassword" )
+ {
+ public void action( PasswordModifyRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] oldPassword = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "OldPassword = " + Strings.dumpBytes( oldPassword ) );
+ }
+
+ if ( oldPassword == null )
+ {
+ oldPassword = Strings.EMPTY_BYTES;
+ }
+
+ ( ( PwdModifyRequestImpl ) container.getPasswordModifyRequest().getDecorated() )
+ .setOldPassword( oldPassword );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+
+ /**
+ * Transition from PasswordModify Request Value to newPassword
+ *
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * ...
+ * newPassword [2] OCTET STRING OPTIONAL
+ * }
+ *
+ * Set the newPassword into the PasswdModifyRequest instance.
+ */
+ super.transitions[PasswordModifyRequestStatesEnum.PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE.ordinal()][PasswordModifyRequestConstants.NEW_PASSWORD_TAG] =
+ new GrammarTransition<PasswordModifyRequestContainer>(
+ PasswordModifyRequestStatesEnum.PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE,
+ PasswordModifyRequestStatesEnum.NEW_PASSWORD_STATE,
+ PasswordModifyRequestConstants.NEW_PASSWORD_TAG,
+ new GrammarAction<PasswordModifyRequestContainer>( "Set PasswordModifyRequest newPassword" )
+ {
+ public void action( PasswordModifyRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] newPassword = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "NewPassword = " + Strings.dumpBytes( newPassword ) );
+ }
+
+ if ( newPassword == null )
+ {
+ newPassword = Strings.EMPTY_BYTES;
+ }
+
+ ( ( PwdModifyRequestImpl ) container.getPasswordModifyRequest().getDecorated() )
+ .setNewPassword( newPassword );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+ }
+
+
+ /**
+ * This class is a singleton.
+ *
+ * @return An instance on this grammar
+ */
+ public static Grammar<PasswordModifyRequestContainer> getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestStatesEnum.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestStatesEnum.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestStatesEnum.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.api.ldap.extras.extended.ads_impl.pwdModify;
+
+
+import org.apache.directory.api.asn1.ber.grammar.Grammar;
+import org.apache.directory.api.asn1.ber.grammar.States;
+
+
+/**
+ * This class store the PasswordModifyRequest's grammar constants. It is also used
+ * for debugging purposes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum PasswordModifyRequestStatesEnum implements States
+{
+
+ /** The END_STATE */
+ END_STATE,
+
+ /** start state*/
+ START_STATE,
+
+ /** sequence*/
+ PASSWORD_MODIFY_REQUEST_SEQUENCE_STATE,
+
+ /** the UserIdentity */
+ USER_IDENTITY_STATE,
+
+ /** the old password */
+ OLD_PASSWORD_STATE,
+
+ /** the new password*/
+ NEW_PASSWORD_STATE,
+
+ /** Last state */
+ LAST_PASSWORD_MODIFY_REQUEST_STATE;
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( Grammar<PasswordModifyRequestContainer> grammar )
+ {
+ return "PASSWORD_MODIFY_GRAMMER";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "PASSWORD_MODIFY_GRAMMER";
+ }
+
+
+ /**
+ * Get the string representing the state
+ *
+ * @param state The state number
+ * @return The String representing the state
+ */
+ public String getState( int state )
+ {
+ return ( ( state == END_STATE.ordinal() ) ? "PASSWORD_MODIFY_GRAMMER" : this.name() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEndState()
+ {
+ return this == END_STATE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public PasswordModifyRequestStatesEnum getStartState()
+ {
+ return START_STATE;
+ }
+}
Added: directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java?rev=1468645&view=auto
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java (added)
+++ directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java Tue Apr 16 22:26:53 2013
@@ -0,0 +1,391 @@
+/*
+ * 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.api.ldap.extras.extended.ads_impl;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdown;
+import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer;
+import org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyRequestContainer;
+import org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyRequestDecorator;
+import org.apache.directory.api.util.Strings;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Test the PasswordModifyRequest codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class PasswordModifyRequestTest
+{
+ /**
+ * Test the decoding of a PasswordModifyRequest
+ */
+ @Test
+ public void testDecodePasswordModifyRequestSuccess()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x08 );
+ bb.put( new byte[]
+ { 0x30, 0x06, // GracefulShutdown ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // timeOffline INTEGER (0..720) DEFAULT 0,
+ ( byte ) 0x80,
+ 0x01,
+ 0x01 // delay INTEGER (0..86400) DEFAULT
+ // 0
+ // }
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ GracefulShutdownContainer container = new GracefulShutdownContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
+ assertEquals( 1, gracefulShutdown.getTimeOffline() );
+ assertEquals( 1, gracefulShutdown.getDelay() );
+
+ // Check the length
+ assertEquals( 0x08, gracefulShutdown.computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = gracefulShutdown.encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with nothing in it
+ */
+ @Test
+ public void testDecodePasswordModifyRequestEmpty()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x02 );
+ bb.put( new byte[]
+ { 0x30, 0x00, // PasswordModifyRequest ::= SEQUENCE {
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNull( pwdModifyRequestDecorator.getNewPassword() );
+
+ // Check the length
+ assertEquals( 0x02, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with an empty user identity
+ */
+ @Test
+ public void testDecodePasswordModifyRequestUserIdentityNull()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x04 );
+ bb.put( new byte[]
+ { 0x30, 0x02, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x80,
+ 0x00 // userIdentity [0] OCTET STRING OPTIONAL
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( 0, pwdModifyRequestDecorator.getUserIdentity().length );
+ assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNull( pwdModifyRequestDecorator.getNewPassword() );
+
+ // Check the length
+ assertEquals( 0x04, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with a user identity
+ */
+ @Test
+ public void testDecodePasswordModifyRequestUserIdentityValue()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x08 );
+ bb.put( new byte[]
+ { 0x30, 0x06, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x80,
+ 0x04, // userIdentity [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd'
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
+ assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNull( pwdModifyRequestDecorator.getNewPassword() );
+
+ // Check the length
+ assertEquals( 0x08, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with an empty user identity
+ */
+ @Test
+ public void testDecodePasswordModifyRequestOldPasswordNull()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x04 );
+ bb.put( new byte[]
+ { 0x30, 0x02, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x81,
+ 0x00 // oldPassword [1] OCTET STRING OPTIONAL
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( 0, pwdModifyRequestDecorator.getOldPassword().length );
+ assertNull( pwdModifyRequestDecorator.getNewPassword() );
+
+ // Check the length
+ assertEquals( 0x04, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with an oldPassword
+ */
+ @Test
+ public void testDecodePasswordModifyRequestOldPasswordValue()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x08 );
+ bb.put( new byte[]
+ { 0x30, 0x06, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x81,
+ 0x04, // oldPassword [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd'
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getOldPassword() ) );
+ assertNull( pwdModifyRequestDecorator.getNewPassword() );
+
+ // Check the length
+ assertEquals( 0x08, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+}