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 2010/11/26 15:37:33 UTC
svn commit: r1039383 - in /directory/apacheds/trunk/kerberos-codec/src:
main/java/org/apache/directory/shared/kerberos/codec/adMandatoryForKdc/
main/java/org/apache/directory/shared/kerberos/components/
test/java/org/apache/directory/shared/kerberos/co...
Author: elecharny
Date: Fri Nov 26 14:37:32 2010
New Revision: 1039383
URL: http://svn.apache.org/viewvc?rev=1039383&view=rev
Log:
Added the AdMandatoryForKdc grammar and test
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adMandatoryForKdc/
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adMandatoryForKdc/AdMandatoryForKdcContainer.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdMandatoryForKdc.java
directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adMandatoryForKdc/AdMandatoryForKdcContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adMandatoryForKdc/AdMandatoryForKdcContainer.java?rev=1039383&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adMandatoryForKdc/AdMandatoryForKdcContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adMandatoryForKdc/AdMandatoryForKdcContainer.java Fri Nov 26 14:37:32 2010
@@ -0,0 +1,51 @@
+/*
+ * 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.adMandatoryForKdc;
+
+import org.apache.directory.shared.kerberos.codec.authorizationData.AuthorizationDataContainer;
+import org.apache.directory.shared.kerberos.components.AdMandatoryForKdc;
+
+
+/**
+ * The AD-MANDATORY-FOR-KDC container stores the AD-MANDATORY-FOR-KDC decoded by the Asn1Decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdMandatoryForKdcContainer extends AuthorizationDataContainer
+{
+ /**
+ * Creates a new AdMandatoryForKdcContainer object.
+ */
+ public AdMandatoryForKdcContainer()
+ {
+ super();
+
+ setAuthorizationData( new AdMandatoryForKdc() );
+ }
+
+
+ /**
+ * @return Returns the AD-MANDATORY-FOR-KDC.
+ */
+ public AdMandatoryForKdc getAdMandatoryForKdc()
+ {
+ return (AdMandatoryForKdc)getAuthorizationData();
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdMandatoryForKdc.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdMandatoryForKdc.java?rev=1039383&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdMandatoryForKdc.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdMandatoryForKdc.java Fri Nov 26 14:37:32 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.components;
+
+
+
+
+/**
+ * The Checksum structure is used to store a AD-MANDATORY-FOR-KDC associated to a type.
+ *
+ * The ASN.1 grammar is :
+ * <pre>
+ * AD-MANDATORY-FOR-KDC ::= AuthorizationData
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdMandatoryForKdc extends AuthorizationData
+{
+ /**
+ * Creates a new instance of AD-MANDATORY-FOR-KDC.
+ */
+ public AdMandatoryForKdc()
+ {
+ super();
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return toString( "" );
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString( String tabs )
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( tabs ).append( "AD-MANDATORY-FOR-KDC : {\n" );
+ sb.append( tabs ).append( super.toString( " " + tabs) ).append( '\n' );
+
+ sb.append( tabs + "}\n" );
+
+ return sb.toString();
+ }
+}
Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java?rev=1039383&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdMandatoryForKdcDecoderTest.java Fri Nov 26 14:37:32 2010
@@ -0,0 +1,120 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.adMandatoryForKdc.AdMandatoryForKdcContainer;
+import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
+import org.apache.directory.shared.kerberos.components.AdMandatoryForKdc;
+import org.apache.directory.shared.kerberos.components.AuthorizationData;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for AD-MANDATORY-FOR-KDC decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdMandatoryForKdcDecoderTest
+{
+
+ @Test
+ public void testAdMandatoryForKdc()
+ {
+ Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x24 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x22,
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03, // ad-type
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x08, // ad-data
+ 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
+ 0x30, 0x0F,
+ (byte)0xA0, 0x03, // ad-type
+ 0x02, 0x01, 0x02,
+ (byte)0xA1, 0x08, // ad-data
+ 0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l'
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( stream.array() );
+ stream.flip();
+
+ AdMandatoryForKdcContainer adMandatoryForKdcContainer = new AdMandatoryForKdcContainer();
+
+ // Decode the AdMandatoryForKdc PDU
+ try
+ {
+ kerberosDecoder.decode( stream, adMandatoryForKdcContainer );
+ }
+ catch ( DecoderException de )
+ {
+ fail( de.getMessage() );
+ }
+
+ AdMandatoryForKdc adMandatoryForKdc = adMandatoryForKdcContainer.getAdMandatoryForKdc();
+
+ assertNotNull( adMandatoryForKdc.getAuthorizationData().size() );
+ assertEquals( 2, adMandatoryForKdc.getAuthorizationData().size() );
+
+ String[] expected = new String[]{ "abcdef", "ghijkl" };
+ int i = 0;
+
+ for ( AuthorizationData.AD ad : adMandatoryForKdc.getAuthorizationData() )
+ {
+ assertEquals( AuthorizationType.AD_INTENDED_FOR_SERVER, ad.getAdType() );
+ assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i++] ), ad.getAdData() ) );
+
+ }
+
+ // Check the encoding
+ ByteBuffer bb = ByteBuffer.allocate( adMandatoryForKdc.computeLength() );
+
+ try
+ {
+ bb = adMandatoryForKdc.encode( bb );
+
+ // Check the length
+ assertEquals( 0x24, bb.limit() );
+
+ String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ fail();
+ }
+ }
+}