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 2018/01/25 22:41:49 UTC

[directory-ldap-api] branch master updated: Added the EndTransaction extended request and response

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new 8655468  Added the EndTransaction extended request and response
8655468 is described below

commit 8655468c953c20e44c223e2112e164083160bd61
Author: Emmanuel Lécharny <el...@symas.com>
AuthorDate: Thu Jan 25 23:41:35 2018 +0100

    Added the EndTransaction extended request and response
---
 ldap/extras/codec-api/pom.xml                      |   1 +
 .../endTransaction/EndTransactionRequest.java      |  77 ++++++++
 .../endTransaction/EndTransactionRequestImpl.java  | 155 +++++++++++++++
 .../endTransaction/EndTransactionResponse.java     |  70 +++++++
 .../endTransaction/EndTransactionResponseImpl.java | 215 +++++++++++++++++++++
 .../extended/endTransaction/UpdateControls.java    | 191 ++++++++++++++++++
 6 files changed, 709 insertions(+)

diff --git a/ldap/extras/codec-api/pom.xml b/ldap/extras/codec-api/pom.xml
index 6db0e3d..be2101e 100644
--- a/ldap/extras/codec-api/pom.xml
+++ b/ldap/extras/codec-api/pom.xml
@@ -75,6 +75,7 @@
               org.apache.directory.api.ldap.extras.controls.vlv;version=${project.version};-noimport:=true,
               org.apache.directory.api.ldap.extras.extended.cancel;version=${project.version};-noimport:=true,
               org.apache.directory.api.ldap.extras.extended.certGeneration;version=${project.version};-noimport:=true,
+              org.apache.directory.api.ldap.extras.extended.endTransaction;version=${project.version};-noimport:=true,
               org.apache.directory.api.ldap.extras.extended.gracefulDisconnect;version=${project.version};-noimport:=true,
               org.apache.directory.api.ldap.extras.extended.gracefulShutdown;version=${project.version};-noimport:=true,
               org.apache.directory.api.ldap.extras.extended.pwdModify;version=${project.version};-noimport:=true,
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequest.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequest.java
new file mode 100644
index 0000000..5e159b6
--- /dev/null
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequest.java
@@ -0,0 +1,77 @@
+/*
+ *  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.endTransaction;
+
+
+import org.apache.directory.api.ldap.model.message.ExtendedRequest;
+
+
+/**
+ * The EndTransactionRequest interface. This is for the RFC 5805 End Transaction Request,
+ * which grammar is :
+ * <pre>
+ * ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ *              requestName      [0] LDAPOID,
+ *              requestValue     [1] OCTET STRING OPTIONAL }
+ * </pre>
+ * 
+ * where 'requestName' is 1.3.6.1.1.21.3 and requestValue is a BER encoded value. The 
+ * syntax for this value is :
+ * 
+ * <pre>
+ * txnEndReq ::= SEQUENCE {
+ *         commit         BOOLEAN DEFAULT TRUE,
+ *         identifier     OCTET STRING }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface EndTransactionRequest extends ExtendedRequest
+{
+    /** The OID for the EndTransaction extended operation request. */
+    String EXTENSION_OID = "1.3.6.1.1.21.3";
+    
+    /**
+     * @return <tt>true</tt> if the operation should be committed, <tt>false</tt> otherwise
+     */
+    boolean getCommit();
+    
+    
+    /**
+     * Set the Commit flag for this transaction.
+     * 
+     * @param commit <tt>true</tt> if teh transaction should be committed, <tt>false</tt> if
+     * it should be rollbacked.
+     */
+    void setCommit( boolean commit );
+    
+    
+    /**
+     * @return The transaction ID 
+     */
+    byte[] getTransactionId();
+
+    /**
+     * Set the transaction ID to commit or rollback
+     * 
+     * @param transactionId The transaction ID we got from teh startTransaction response
+     */
+    void setTransactionId( byte[] transactionId );
+}
\ No newline at end of file
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequestImpl.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequestImpl.java
new file mode 100644
index 0000000..16b9203
--- /dev/null
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionRequestImpl.java
@@ -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.api.ldap.extras.extended.endTransaction;
+
+
+import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest;
+import org.apache.directory.api.util.Strings;
+
+
+/**
+ * The EndTransactionRequest implementation. This is for the RFC 5805 End Transaction Request,
+ * which grammar is :
+ * <pre>
+ * ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ *              requestName      [0] LDAPOID,
+ *              requestValue     [1] OCTET STRING OPTIONAL }
+ * </pre>
+ * 
+ * where 'requestName' is 1.3.6.1.1.21.3 and requestValue is a BER encoded value. The 
+ * syntax for this value is :
+ * 
+ * <pre>
+ * txnEndReq ::= SEQUENCE {
+ *         commit         BOOLEAN DEFAULT TRUE,
+ *         identifier     OCTET STRING }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EndTransactionRequestImpl extends AbstractExtendedRequest implements EndTransactionRequest
+{
+    /** The transaction ID received from teh StartTransactionResponse */
+    private byte[] transactionId;
+    
+    /** A flag telling of we should commit or rollback the transaction */
+    private boolean commit = true;
+    
+    /**
+     * Creates a new instance of EndTransactionRequestImpl.
+     *
+     * @param messageId the message id
+     */
+    public EndTransactionRequestImpl( int messageId )
+    {
+        super( messageId );
+        setRequestName( EXTENSION_OID );
+    }
+
+
+    /**
+     * Creates a new instance of EndTransactionRequestImpl.
+     */
+    public EndTransactionRequestImpl()
+    {
+        setRequestName( EXTENSION_OID );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public EndTransactionResponse getResultResponse()
+    {
+        if ( getResponse() == null )
+        {
+            setResponse( new EndTransactionResponseImpl() );
+        }
+
+        return ( EndTransactionResponse ) getResponse();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean getCommit()
+    {
+        return commit;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setCommit( boolean commit )
+    {
+        this.commit = commit;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public byte[] getTransactionId()
+    {
+        return Strings.copy( transactionId );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setTransactionId( byte[] transactionId )
+    {
+        this.transactionId = Strings.copy( transactionId );
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    @Override
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "EndTransactionRequest :" );
+        sb.append( "\n    commit : " ).append( commit );
+
+        sb.append( "\n    transactionId : " );
+
+        if ( transactionId != null )
+        {
+            sb.append( Strings.dumpBytes( transactionId ) );
+        }
+        else
+        {
+            sb.append( "null" );
+        }
+
+        return sb.toString();
+    }
+}
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionResponse.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionResponse.java
new file mode 100644
index 0000000..eac3f1f
--- /dev/null
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionResponse.java
@@ -0,0 +1,70 @@
+/*
+ *  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.endTransaction;
+
+
+import java.util.List;
+
+import org.apache.directory.api.ldap.model.message.ExtendedResponse;
+
+
+/**
+ * The interface for End Transaction Extended Response. It's described in RFC 5805 :
+ * 
+ * <pre>
+ * ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+ *            COMPONENTS OF LDAPResult,
+ *            responseName     [10] LDAPOID OPTIONAL,
+ *            responseValue    [11] OCTET STRING OPTIONAL }
+ * </pre>
+ * 
+ * where the responseName is not present, and the responseValue contains
+ * a BER encoded value, defined by the following grammar :
+ * 
+ * <pre>
+ * txnEndRes ::= SEQUENCE {
+ *         messageID MessageID OPTIONAL,
+ *              -- msgid associated with non-success resultCode
+ *         updatesControls SEQUENCE OF updateControls SEQUENCE {
+ *              messageID MessageID,
+ *                   -- msgid associated with controls
+ *              controls  Controls
+ *         } OPTIONAL
+ *    }
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface EndTransactionResponse extends ExtendedResponse
+{
+    /** The OID for the Start Transaction extended operation response. */
+    String EXTENSION_OID = EndTransactionRequest.EXTENSION_OID;
+    
+    
+    /**
+     * @return The Message ID if failire
+     */
+    int getFailedMessageId();
+    
+    /**
+     * @return the list of <messageId, Controls> processed within the transaction 
+     */
+    List<UpdateControls> getUpdateControls();
+}
\ No newline at end of file
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionResponseImpl.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionResponseImpl.java
new file mode 100644
index 0000000..a0efe68
--- /dev/null
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/EndTransactionResponseImpl.java
@@ -0,0 +1,215 @@
+/*
+ *  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.endTransaction;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
+import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
+
+
+/**
+ * The End Transaction Extended Response implementation. It's described in RFC 5805 :
+ * 
+ * <pre>
+ * ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+ *            COMPONENTS OF LDAPResult,
+ *            responseName     [10] LDAPOID OPTIONAL,
+ *            responseValue    [11] OCTET STRING OPTIONAL }
+ * </pre>
+ * 
+ * where the responseName is not present, and the responseValue contains
+ * a BER encoded value, defined by the following grammar :
+ * 
+ * <pre>
+ * txnEndRes ::= SEQUENCE {
+ *         messageID MessageID OPTIONAL,
+ *              -- msgid associated with non-success resultCode
+ *         updatesControls SEQUENCE OF updateControls SEQUENCE {
+ *              messageID MessageID,
+ *                   -- msgid associated with controls
+ *              controls  Controls
+ *         } OPTIONAL
+ *    }
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EndTransactionResponseImpl extends ExtendedResponseImpl implements EndTransactionResponse
+{
+    /** The faulty Message ID, if any */
+    private int failedMessageId;
+    
+    /** The list of update controls for the message processed in the transaction */
+    private List<UpdateControls> updateControls = new ArrayList<>();
+
+    /**
+     * Create a new EndTransactionResponseImpl object
+     * 
+     * @param failedMessageId The faulty messageId
+     * @param rcode the result code
+     */
+    public EndTransactionResponseImpl( int failedMessageId, ResultCodeEnum resultCode )
+    {
+        super( failedMessageId );
+
+        switch ( resultCode )
+        {
+            case SUCCESS:
+                this.failedMessageId = -1;
+                break;
+
+            default:
+                this.failedMessageId = failedMessageId;
+        }
+
+        super.getLdapResult().setMatchedDn( null );
+        super.getLdapResult().setResultCode( resultCode );
+    }
+
+
+    /**
+     * Create a new EndTransactionResponseImpl instance
+     * 
+     * @param failedMessageId The request's messageId
+     */
+    public EndTransactionResponseImpl( int failedMessageId )
+    {
+        super( failedMessageId );
+        super.getLdapResult().setMatchedDn( null );
+        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+    }
+
+
+    /**
+     * Create a new StartTransactionResponseImpl instance
+     */
+    public EndTransactionResponseImpl()
+    {
+        super( EndTransactionRequest.EXTENSION_OID );
+        super.getLdapResult().setMatchedDn( null );
+        super.getLdapResult().setResultCode( ResultCodeEnum.UNWILLING_TO_PERFORM );
+    }
+
+
+    /**
+     * Gets the OID uniquely identifying this extended response (a.k.a. its
+     * name). It's a null value for the Cancel response
+     * 
+     * @return the OID of the extended response type.
+     */
+    @Override
+    public String getResponseName()
+    {
+        return "";
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int getFailedMessageId()
+    {
+        return failedMessageId;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void setFailedMessageId( int failedMessageId )
+    {
+        this.failedMessageId = failedMessageId;
+    }
+    
+    /**
+     * @return the updateControls
+     */
+    public List<UpdateControls> getUpdateControls()
+    {
+        return updateControls;
+    }
+
+
+    /**
+     * @param updateControls the updateControls to set
+     */
+    public void setUpdateControls( List<UpdateControls> updateControls )
+    {
+        this.updateControls = updateControls;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+
+        hash = hash * 17 + failedMessageId;
+        
+        for ( UpdateControls updateControl : updateControls )
+        {
+            hash = hash * 17 + updateControl.hashCode();
+        }
+
+        return hash;
+    }
+
+
+    /**
+     * @see Object#equals(Object)
+     */
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( obj == this )
+        {
+            return true;
+        }
+
+        if ( !( obj instanceof EndTransactionResponse ) )
+        {
+            return false;
+        }
+        
+        EndTransactionResponse that = ( EndTransactionResponse ) obj;
+        
+        if ( failedMessageId != that.getFailedMessageId() )
+        {
+            return false;
+        }
+        
+        for ( UpdateControls updateControl : updateControls )
+        {
+            if ( !that.getUpdateControls().contains( updateControl ) )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+}
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/UpdateControls.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/UpdateControls.java
new file mode 100644
index 0000000..6962ef9
--- /dev/null
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/endTransaction/UpdateControls.java
@@ -0,0 +1,191 @@
+/*
+ *  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.endTransaction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.ldap.Control;
+
+/**
+ * The interface for End Transaction Extended Response UpdateControl. It's described in RFC 5805 :
+ * 
+ * <pre>
+ * updateControls SEQUENCE {
+ *     messageID MessageID,
+ *               -- msgid associated with controls
+ *     controls  Controls
+ * } OPTIONAL
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UpdateControls
+{
+    /** The message ID for which we want to get back the controls */
+    private int messageId;
+
+    /** The list of controls (may be empty) */
+    private List<Control> controls = new ArrayList<>();
+    
+    /**
+     * A default constructor for the UpdateControls class
+     */
+    public UpdateControls()
+    {
+        // Nothing to do
+    }
+    
+    
+    /**
+     * @return The messageID
+     */
+    public int getMessageId()
+    {
+        return messageId;
+    }
+    
+    
+    /**
+     * @param messageId the messageId to set
+     */
+    public void setMessageId( int messageId )
+    {
+        this.messageId = messageId;
+    }
+   
+   
+    /**
+     * @return The set of controls associated with the messageID
+     */
+    public List<Control> getControls()
+    {
+        return controls;
+    }
+
+
+    /**
+     * @param controls the controls to set
+     */
+    public void setControls( List<Control> controls )
+    {
+        this.controls = controls;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+
+        hash = hash * 17 + messageId;
+        
+        for ( Control control : controls )
+        {
+            hash = hash * 17 + control.hashCode();
+        }
+
+        return hash;
+    }
+
+
+    /**
+     * @see Object#equals(Object)
+     */
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( obj == this )
+        {
+            return true;
+        }
+
+        if ( !( obj instanceof UpdateControls ) )
+        {
+            return false;
+        }
+        
+        UpdateControls that = ( UpdateControls ) obj;
+        
+        if ( messageId != that.getMessageId() )
+        {
+            return false;
+        }
+        
+        if ( controls.size() != that.getControls().size() )
+        {
+            return false;
+        }
+        
+        for ( Control control : controls )
+        {
+            if ( !that.getControls().contains( control ) )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    @Override
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "UpdateControl :" );
+        sb.append( "\n    messageId : " ).append( messageId );
+
+        if ( controls.isEmpty() )
+        {
+            sb.append( "\n    No controls" );
+        }
+        else
+        {
+            sb.append( "\n    Controls: [" );
+            boolean isFirst = true;
+            
+            for ( Control control : controls )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( ", " );
+                }
+                
+                sb.append( control.getID() );
+            }
+            
+            sb.append( ']' );
+        }
+
+        return sb.toString();
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
elecharny@apache.org.