Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 80847 invoked from network); 26 Nov 2010 14:30:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 Nov 2010 14:30:15 -0000 Received: (qmail 45185 invoked by uid 500); 26 Nov 2010 14:30:15 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 45128 invoked by uid 500); 26 Nov 2010 14:30:15 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 45121 invoked by uid 99); 26 Nov 2010 14:30:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Nov 2010 14:30:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Nov 2010 14:30:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0C5C423888E8; Fri, 26 Nov 2010 14:28:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1039375 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/adIfRelevant/ main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/ main/java/org/apache/directory/sh... Date: Fri, 26 Nov 2010 14:28:37 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101126142838.0C5C423888E8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Fri Nov 26 14:28:37 2010 New Revision: 1039375 URL: http://svn.apache.org/viewvc?rev=1039375&view=rev Log: Added the AdIfRelevant grammar Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adIfRelevant/ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adIfRelevant/AdIfRelevantContainer.java directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdIfRelevant.java directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adIfRelevant/AdIfRelevantContainer.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adIfRelevant/AdIfRelevantContainer.java?rev=1039375&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adIfRelevant/AdIfRelevantContainer.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/adIfRelevant/AdIfRelevantContainer.java Fri Nov 26 14:28:37 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.adIfRelevant; + +import org.apache.directory.shared.kerberos.codec.authorizationData.AuthorizationDataContainer; +import org.apache.directory.shared.kerberos.components.AdIfRelevant; + + +/** + * The AD-IF-RELEVANT container stores the AD-IF-RELEVANT decoded by the Asn1Decoder. + * + * @author Apache Directory Project + */ +public class AdIfRelevantContainer extends AuthorizationDataContainer +{ + /** + * Creates a new AdIfRelevantContainer object. + */ + public AdIfRelevantContainer() + { + super(); + + setAuthorizationData( new AdIfRelevant() ); + } + + + /** + * @return Returns the AD-IF-RELEVANT. + */ + public AdIfRelevant getAdIfRelevant() + { + return (AdIfRelevant)getAuthorizationData(); + } +} Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java?rev=1039375&r1=1039374&r2=1039375&view=diff ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java (original) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/authorizationData/actions/AuthorizationDataInit.java Fri Nov 26 14:28:37 2010 @@ -72,12 +72,16 @@ public class AuthorizationDataInit exten throw new DecoderException( I18n.err( I18n.ERR_04067 ) ); } - AuthorizationData authData = new AuthorizationData(); - authDataContainer.setAuthorizationData( authData ); - - if ( IS_DEBUG ) + if ( authDataContainer.getAuthorizationData() == null ) { - LOG.debug( "AuthorizationData created" ); + AuthorizationData authData = new AuthorizationData(); + authDataContainer.setAuthorizationData( authData ); + + + if ( IS_DEBUG ) + { + LOG.debug( "AuthorizationData created" ); + } } } } Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdIfRelevant.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdIfRelevant.java?rev=1039375&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdIfRelevant.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdIfRelevant.java Fri Nov 26 14:28:37 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-IF-RELEVANT associated to a type. + * + * The ASN.1 grammar is : + *
+ * AD-IF-RELEVANT          ::= AuthorizationData
+ * 
+ * @author Apache Directory Project + */ +public class AdIfRelevant extends AuthorizationData +{ + /** + * Creates a new instance of AD-IF-RELEVANT. + */ + public AdIfRelevant() + { + 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-IF-RELEVANT : {\n" ); + sb.append( tabs ).append( super.toString( " " + tabs) ).append( '\n' ); + + sb.append( tabs + "}\n" ); + + return sb.toString(); + } +} Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java?rev=1039375&r1=1039374&r2=1039375&view=diff ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java (original) +++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AuthorizationData.java Fri Nov 26 14:28:37 2010 @@ -271,16 +271,25 @@ public class AuthorizationData extends A */ public String toString() { + return toString( "" ); + } + + + /** + * @see Object#toString() + */ + public String toString( String tabs ) + { StringBuilder sb = new StringBuilder(); - sb.append( "AuthorizationData : \n" ); + sb.append( tabs ).append( "AuthorizationData : \n" ); for ( AD ad : authorizationData ) { - sb.append( " {\n" ); - sb.append( " adtype: " ).append( ad.adType ).append( '\n' ); - sb.append( " adData: " ).append( StringTools.dumpBytes( ad.adData ) ).append( '\n'); - sb.append( " }\n" ); + sb.append( tabs ).append( " {\n" ); + sb.append( tabs ).append( " adtype: " ).append( ad.adType ).append( '\n' ); + sb.append( tabs ).append( " adData: " ).append( StringTools.dumpBytes( ad.adData ) ).append( '\n'); + sb.append( tabs ).append( " }\n" ); } return sb.toString(); Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java?rev=1039375&view=auto ============================================================================== --- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java (added) +++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/AdIfRelevantDecoderTest.java Fri Nov 26 14:28:37 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.adIfRelevant.AdIfRelevantContainer; +import org.apache.directory.shared.kerberos.codec.types.AuthorizationType; +import org.apache.directory.shared.kerberos.components.AdIfRelevant; +import org.apache.directory.shared.kerberos.components.AuthorizationData; +import org.apache.directory.shared.ldap.util.StringTools; +import org.junit.Test; + +/** + * Test cases for AD-IF-RELEVANT decoder. + * + * @author Apache Directory Project + */ +public class AdIfRelevantDecoderTest +{ + + @Test + public void testAdIfRelevant() + { + 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(); + + AdIfRelevantContainer adIfRelevantContainer = new AdIfRelevantContainer(); + + // Decode the AdIfRelevant PDU + try + { + kerberosDecoder.decode( stream, adIfRelevantContainer ); + } + catch ( DecoderException de ) + { + fail( de.getMessage() ); + } + + AdIfRelevant adIfRelevant = adIfRelevantContainer.getAdIfRelevant(); + + assertNotNull( adIfRelevant.getAuthorizationData().size() ); + assertEquals( 2, adIfRelevant.getAuthorizationData().size() ); + + String[] expected = new String[]{ "abcdef", "ghijkl" }; + int i = 0; + + for ( AuthorizationData.AD ad : adIfRelevant.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( adIfRelevant.computeLength() ); + + try + { + bb = adIfRelevant.encode( bb ); + + // Check the length + assertEquals( 0x24, bb.limit() ); + + String encodedPdu = StringTools.dumpBytes( bb.array() ); + + assertEquals( encodedPdu, decodedPdu ); + } + catch ( EncoderException ee ) + { + fail(); + } + } +}