directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r440173 - /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
Date Mon, 04 Sep 2006 20:31:24 GMT
Author: elecharny
Date: Mon Sep  4 13:31:23 2006
New Revision: 440173

URL: http://svn.apache.org/viewvc?view=rev&rev=440173
Log:
Added the SaslCredential BER decorator

Added:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java?view=auto&rev=440173
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
(added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/SaslCredentialsAsn1Ber.java
Mon Sep  4 13:31:23 2006
@@ -0,0 +1,100 @@
+/*
+ *  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.shared.ldap.codec.asn1ber.messages.bind;
+
+import org.apache.directory.shared.asn1.ber.Decoder;
+import org.apache.directory.shared.asn1.ber.Encoder;
+import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.ldap.messages.bind.AuthenticationOperation;
+import org.apache.directory.shared.ldap.messages.bind.SaslCredentialsDecorator;
+import org.apache.directory.shared.ldap.utils.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * The SaslCredentials decorator for ASN.1 Ber
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SaslCredentialsAsn1Ber extends SaslCredentialsDecorator implements Encoder,
Decoder
+{
+    /** The logger */
+    private static Logger log = LoggerFactory.getLogger( SaslCredentialsAsn1Ber.class );
+
+    /** A speedup for logger */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** The mechanism length */
+    private transient int mechanismLength;
+    
+    private transient byte[] mechanismBytes;
+
+    /** The credentials length */
+    private transient int credentialsLength;
+
+    /**
+     * Creates a new instance of SaslCredentialsAsn1Ber. 
+     *
+     * @param authentication The authentication object to decorate.
+     */
+    public SaslCredentialsAsn1Ber( AuthenticationOperation authentication )
+    {
+        super( authentication );
+    }
+    
+    /**
+     * Compute the Sasl authentication length 
+     * 
+     * Sasl authentication : 
+     * 0xA3 L1 
+     *   0x04 L2 mechanism 
+     *   [0x04 L3 credentials] 
+     * 
+     * L2 = Length(mechanism) 
+     * L3 = Length(credentials) 
+     * L1 = L2 + L3 
+     * 
+     * Length(Sasl authentication) = 
+     *   Length(0xA3) + Length(L1) + 
+     *   Length(0x04) + Length(L2) + Length(mechanism) 
+     *   [+ Length(0x04) + Length(L3) + Length(credentials)]
+     */
+    public int computeLength()
+    {
+        mechanismBytes = StringTools.getBytesUtf8( getMechanism() );
+        
+        mechanismLength = 1 + Length.getNbBytes( mechanismBytes.length ) + mechanismBytes.length;
+        
+        credentialsLength = ( ( getCredentials() == null ) ?
+            0 :
+            1 + Length.getNbBytes( getCredentials().length ) + getCredentials().length );
+
+        int saslLength = 1 + Length.getNbBytes( mechanismLength + credentialsLength ) + mechanismLength
+            + credentialsLength;
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "SASL Authentication length : {}", saslLength );
+        }
+
+        return saslLength;
+    }
+}



Mime
View raw message