directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1032434 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/options/ test/java/org/apache/directory/shared/kerberos/codec/options/
Date Mon, 08 Nov 2010 01:01:34 GMT
Author: elecharny
Date: Mon Nov  8 01:01:33 2010
New Revision: 1032434

URL: http://svn.apache.org/viewvc?rev=1032434&view=rev
Log:
o Added the Options and KdcOptions classes
o Added some tests

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/KdcOptions.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/Options.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/options/
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/options/OptionsTest.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/KdcOptions.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/KdcOptions.java?rev=1032434&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/KdcOptions.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/KdcOptions.java
Mon Nov  8 01:01:33 2010
@@ -0,0 +1,225 @@
+/*
+ *  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.kerberos.codec.options;
+
+
+/**
+ * The list of possible KDC options.
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KdcOptions extends Options
+{
+    /**
+     * KDC option - reserved.
+     */
+    public static final int RESERVED = 0;
+
+    /**
+     * KDC option - forwardable.
+     */
+    public static final int FORWARDABLE = 1;
+
+    /**
+     * KDC option - forwarded.
+     */
+    public static final int FORWARDED = 2;
+
+    /**
+     * KDC option - proxiable.
+     */
+    public static final int PROXIABLE = 3;
+
+    /**
+     * KDC option - proxy.
+     */
+    public static final int PROXY = 4;
+
+    /**
+     * KDC option - allow postdate.
+     */
+    public static final int ALLOW_POSTDATE = 5;
+
+    /**
+     * KDC option - postdated.
+     */
+    public static final int POSTDATED = 6;
+
+    /**
+     * KDC option - unused7.
+     */
+    public static final int UNUSED7 = 7;
+
+    /**
+     * KDC option - renewable.
+     */
+    public static final int RENEWABLE = 8;
+
+    /**
+     * KDC option - unused9.
+     */
+    public static final int UNUSED9 = 9;
+
+    /**
+     * KDC option - unused10.
+     */
+    public static final int UNUSED10 = 10;
+
+    /**
+     * KDC option - unused11.
+     */
+    public static final int UNUSED11 = 11;
+
+    /**
+     * KDC option - unused12.
+     */
+    public static final int UNUSED12 = 12;
+
+    /**
+     * KDC option - unused13.
+     */
+    public static final int UNUSED13 = 13;
+
+    /**
+     * KDC option - disable transisted checked.
+     */
+    public static final int DISABLE_TRANSISTED_CHECKED = 26;
+
+    /**
+     * KDC option - renewable is ok.
+     */
+    public static final int RENEWABLE_OK = 27;
+
+    /**
+     * KDC option - encrypted key in skey.
+     */
+    public static final int ENC_TKT_IN_SKEY = 28;
+
+    /**
+     * KDC option - renew.
+     */
+    public static final int RENEW = 30;
+
+    /**
+     * KDC option - validate.
+     */
+    public static final int VALIDATE = 31;
+
+    /**
+     * KDC option - maximum value.
+     */
+    public static final int MAX_VALUE = 32;
+
+
+    /**
+     * Creates a new instance of KdcOptions.
+     */
+    public KdcOptions()
+    {
+        super( MAX_VALUE );
+    }
+
+
+    /**
+     * Creates a new instance of KdcOptions.
+     *
+     * @param bytes The list of all the bits as a byte[]
+     */
+    public KdcOptions( byte[] bytes )
+    {
+        super( MAX_VALUE );
+        setBytes( bytes );
+    }
+
+
+    /**
+     * Converts the object to a printable string.
+     */
+    public String toString()
+    {
+        StringBuilder result = new StringBuilder();
+
+        if ( get( ALLOW_POSTDATE ) )
+        {
+            result.append( "ALLOW_POSTDATE " );
+        }
+
+        if ( get( DISABLE_TRANSISTED_CHECKED ) )
+        {
+            result.append( "DISABLE_TRANSISTED_CHECKED " );
+        }
+
+        if ( get( ENC_TKT_IN_SKEY ) )
+        {
+            result.append( "ENC_TKT_IN_SKEY " );
+        }
+
+        if ( get( FORWARDABLE ) )
+        {
+            result.append( "FORWARDABLE " );
+        }
+
+        if ( get( FORWARDED ) )
+        {
+            result.append( "FORWARDED " );
+        }
+
+        if ( get( POSTDATED ) )
+        {
+            result.append( "POSTDATED " );
+        }
+
+        if ( get( PROXIABLE ) )
+        {
+            result.append( "PROXIABLE " );
+        }
+
+        if ( get( PROXY ) )
+        {
+            result.append( "PROXY " );
+        }
+
+        if ( get( RENEW ) )
+        {
+            result.append( "RENEW " );
+        }
+
+        if ( get( RENEWABLE ) )
+        {
+            result.append( "RENEWABLE " );
+        }
+
+        if ( get( RENEWABLE_OK ) )
+        {
+            result.append( "RENEWABLE_OK " );
+        }
+
+        if ( get( RESERVED ) )
+        {
+            result.append( "RESERVED " );
+        }
+
+        if ( get( VALIDATE ) )
+        {
+            result.append( "VALIDATE " );
+        }
+
+        return result.toString().trim();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/Options.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/Options.java?rev=1032434&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/Options.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/options/Options.java
Mon Nov  8 01:01:33 2010
@@ -0,0 +1,161 @@
+/*
+ *  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.kerberos.codec.options;
+
+
+import java.util.BitSet;
+
+
+/**
+ * A base class to manage Kerberos BitSet elements.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class Options
+{
+    /** The Bits storage */
+    private BitSet options;
+    
+    /** The size for the BitSet */
+    private int maxSize;
+
+
+    /**
+     * Creates a new BitSet with a specific number of bits.
+     * @param maxSize The number of bits to allocate
+     */
+    protected Options( int maxSize )
+    {
+        this.maxSize = maxSize;
+        options = new BitSet( maxSize );
+    }
+
+
+    /**
+     * Returns whether the option at a given index matches the option in this {@link Options}.
+     *
+     * @param options The set of possible options
+     * @param option The Option we are looking for
+     * @return true if two options are the same.
+     */
+    public boolean match( Options options, int option )
+    {
+        return options.get( option ) == this.get( option );
+    }
+
+
+    /**
+     * Returns the value of the option at the given index.
+     *
+     * @param index The position in the BitSet for the option we are looking for
+     * @return true if the option at the given index is set.
+     */
+    public boolean get( int index )
+    {
+        if ( index >= maxSize )
+        {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        
+        return options.get( index );
+    }
+
+
+    /**
+     * Sets the option at a given index.
+     *
+     * @param index The position of the Option w want to set
+     */
+    public void set( int index )
+    {
+        if ( ( index < 0 ) || ( index > options.size() ) )
+        {
+            return;
+        }
+        
+        options.set( index );
+    }
+
+
+    /**
+     * Clears (sets false) the option at a given index.
+     *
+     * @param index The position of the Option we want to clear
+     */
+    public void clear( int index )
+    {
+        if ( ( index < 0 ) || ( index > options.size() ) )
+        {
+            return;
+        }
+        
+        options.clear( index );
+    }
+
+
+    /**
+     * Byte-reversing methods are an anomaly of the BouncyCastle
+     * DERBitString endianness. These methods can be removed if the
+     * Apache Directory Snickers codecs operate differently.
+     * 
+     * @return The raw {@link Options} bytes.
+     */
+    public byte[] getBytes()
+    {
+        byte[] bytes = new byte[maxSize / 8];
+
+        for ( int i = 0; i < maxSize; i++ )
+        {
+            if ( options.get( i ) )
+            {
+                bytes[bytes.length - i / 8 - 1] |= 1 << ( i % 8 );
+            }
+        }
+        return bytes;
+    }
+
+
+    protected void setBytes( byte[] bytes )
+    {
+        for ( int i = 0; i < bytes.length * 8; i++ )
+        {
+            if ( ( bytes[bytes.length - i / 8 - 1] & ( 1 << ( i % 8 ) ) ) >
0 )
+            {
+                options.set( i);
+            }
+        }
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        for ( int i = maxSize - 1; i >= 0; i-- )
+        {
+            sb.append( options.get( i ) ? "1" : "0" );
+        }
+        
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/options/OptionsTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/options/OptionsTest.java?rev=1032434&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/options/OptionsTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/options/OptionsTest.java
Mon Nov  8 01:01:33 2010
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.options;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+/**
+ * Test the Options class
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class OptionsTest
+{
+    private class MyOptions extends Options
+    {
+        private MyOptions()
+        {
+            super( 22 );
+        }
+    }
+    
+    @Test
+    public void testAddBytes()
+    {
+        MyOptions myOptions = new MyOptions(); 
+        
+        // Set the bits 10-0100 1010-1100 0000-0110
+        myOptions.setBytes( new byte[]{ (byte)0x24, (byte)0xAC, 0x06} );
+
+        assertEquals( "1001001010110000000110", myOptions.toString() );
+        assertTrue( myOptions.get( 21 ) );
+        assertFalse( myOptions.get( 20 ) );
+        
+        try
+        {
+            myOptions.get( 22 );
+            fail();
+        }
+        catch ( ArrayIndexOutOfBoundsException e )
+        {
+            assertTrue( true );
+        }
+    }
+}



Mime
View raw message