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 22:56:01 UTC
svn commit: r1039573 - in
/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos:
KerberosConstants.java components/AdKdcIssued.java
Author: elecharny
Date: Fri Nov 26 21:56:01 2010
New Revision: 1039573
URL: http://svn.apache.org/viewvc?rev=1039573&view=rev
Log:
Added the AD-KDCIssued class and tags
Added:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdKdcIssued.java
Modified:
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java?rev=1039573&r1=1039572&r2=1039573&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/KerberosConstants.java Fri Nov 26 21:56:01 2010
@@ -142,6 +142,12 @@ public class KerberosConstants
public static final int AD_AND_OR_CONDITION_COUNT_TAG = 0xA0;
public static final int AD_AND_OR_ELEMENTS_TAG = 0xA1;
+ /** AD-KDCIssued */
+ public static final int AD_KDC_ISSUED_AD_CHECKSUM_TAG = 0xA0;
+ public static final int AD_KDC_ISSUED_I_REALM_TAG = 0xA1;
+ public static final int AD_KDC_ISSUED_I_SNAME_TAG = 0xA2;
+ public static final int AD_KDC_ISSUED_ELEMENTS_TAG = 0xA3;
+
/** AuthorizationData tags */
public static final int AUTHORIZATION_DATA_ADTYPE_TAG = 0xA0;
public static final int AUTHORIZATION_DATA_ADDATA_TAG = 0xA1;
Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdKdcIssued.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdKdcIssued.java?rev=1039573&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdKdcIssued.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/AdKdcIssued.java Fri Nov 26 21:56:01 2010
@@ -0,0 +1,314 @@
+/*
+ * 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;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The AdKdcIssued structure is used to store a AD-KDCIssued associated to a type.
+ *
+ * The ASN.1 grammar is :
+ * <pre>
+ * AD-KDCIssued ::= SEQUENCE {
+ * ad-checksum [0] Checksum,
+ * i-realm [1] Realm OPTIONAL,
+ * i-sname [2] PrincipalName OPTIONAL,
+ * elements [3] AuthorizationData
+ * }
+ * </pre>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdKdcIssued extends AbstractAsn1Object
+{
+ /** The logger */
+ private static final Logger LOG = LoggerFactory.getLogger( AdKdcIssued.class );
+
+ /** Speedup for logs */
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The checksum */
+ private Checksum adChecksum;
+
+ /** The realm */
+ private String irealm;
+
+ /** The PrincipalName */
+ private PrincipalName isname;
+
+ /** The AuthorizationData */
+ private AuthorizationData elements;
+
+
+ // Storage for computed lengths
+ private transient int adCheksumTagLength;
+ private transient int irealmTagLength;
+ private transient byte[] irealmBytes;
+ private transient int isnameTagLength;
+ private transient int elementsTagLength;
+ private transient int adKdcIssuedSeqLength;
+
+ /**
+ * Creates a new instance of AdKdcIssued
+ */
+ public AdKdcIssued()
+ {
+ }
+
+
+ /**
+ * @return the elements
+ */
+ public AuthorizationData getElements()
+ {
+ return elements;
+ }
+
+
+ /**
+ * @param elements the elements to set
+ */
+ public void setElements( AuthorizationData elements )
+ {
+ this.elements = elements;
+ }
+
+
+
+
+ /**
+ * @return the adChecksum
+ */
+ public Checksum getAdChecksum()
+ {
+ return adChecksum;
+ }
+
+
+ /**
+ * @param adChecksum the adChecksum to set
+ */
+ public void setAdChecksum( Checksum adChecksum )
+ {
+ this.adChecksum = adChecksum;
+ }
+
+
+ /**
+ * @return the irealm
+ */
+ public String getIrealm()
+ {
+ return irealm;
+ }
+
+
+ /**
+ * @param irealm the irealm to set
+ */
+ public void setIrealm( String irealm )
+ {
+ this.irealm = irealm;
+ }
+
+
+ /**
+ * @return the isname
+ */
+ public PrincipalName getIsname()
+ {
+ return isname;
+ }
+
+
+ /**
+ * @param isname the isname to set
+ */
+ public void setIsname( PrincipalName isname )
+ {
+ this.isname = isname;
+ }
+
+
+ /**
+ * Compute the AD-KDCIssued length
+ * <pre>
+ * 0x30 L1 AD-KDCIssued sequence
+ * |
+ * +--> 0xA1 L2 ad-checksum tag
+ * | |
+ * | +--> 0x30 L2-1 ad-checksum value ( Checksum )
+ * |
+ * +--> 0xA2 L3 i-realm tag
+ * | |
+ * | +--> 0x1B L3-1 i-realm value ( KerberosString )
+ * |
+ * +--> 0xA3 L4 i-sname tag
+ * | |
+ * | +--> 0x30 L4-1 i-sname value ( PrincipalName )
+ * |
+ * +--> 0xA4 L5 elements tag
+ * |
+ * +--> 0x30 L5-1 elements (AuthorizationData)
+ * </pre>
+ */
+ @Override
+ public int computeLength()
+ {
+ // Compute the ad-cheksum count length
+ adCheksumTagLength = adChecksum.computeLength();
+ adKdcIssuedSeqLength = 1 + TLV.getNbBytes( adCheksumTagLength ) + adCheksumTagLength;
+
+ // Compute the i-realm length, if any
+ if ( irealm != null )
+ {
+ irealmBytes = irealm.getBytes();
+ irealmTagLength = 1 + TLV.getNbBytes( irealmBytes.length ) + irealmBytes.length;
+ adKdcIssuedSeqLength += 1 + TLV.getNbBytes( irealmTagLength ) + irealmTagLength;
+ }
+
+ // Compute the i-sname length, if any
+ if ( isname != null )
+ {
+ isnameTagLength = isname.computeLength();
+ adKdcIssuedSeqLength += 1 + TLV.getNbBytes( isnameTagLength ) + isnameTagLength;
+ }
+
+ // Compute the elements count length
+ elementsTagLength = elements.computeLength();
+ adKdcIssuedSeqLength += 1 + TLV.getNbBytes( elementsTagLength ) + elementsTagLength;
+
+ // Compute the whole sequence length
+ return 1 + TLV.getNbBytes( adKdcIssuedSeqLength ) + adKdcIssuedSeqLength;
+ }
+
+
+ /**
+ * Encode the AD-KDCIssued message to a PDU.
+ *
+ * @param buffer The buffer where to put the PDU. It should have been allocated
+ * before, with the right size.
+ * @return The constructed PDU.
+ */
+ @Override
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if ( buffer == null )
+ {
+ throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+ }
+
+ try
+ {
+ // The AD-KDCIssued SEQ Tag
+ buffer.put( UniversalTag.SEQUENCE.getValue() );
+ buffer.put( TLV.getBytes( adKdcIssuedSeqLength ) );
+
+ // the ad-checksum
+ buffer.put( ( byte ) KerberosConstants.AD_KDC_ISSUED_AD_CHECKSUM_TAG );
+ buffer.put( (byte)adCheksumTagLength );
+ adChecksum.encode( buffer );
+
+ // the i-realm, if any
+ if ( irealm != null )
+ {
+ buffer.put( ( byte ) KerberosConstants.AD_KDC_ISSUED_I_REALM_TAG );
+ buffer.put( (byte)irealmTagLength );
+ buffer.put( UniversalTag.GENERAL_STRING.getValue() );
+ buffer.put( (byte)irealmBytes.length );
+ buffer.put( irealmBytes );
+ }
+
+ // the i-sname, if any
+ if ( isname != null )
+ {
+ buffer.put( ( byte ) KerberosConstants.AD_KDC_ISSUED_I_SNAME_TAG );
+ buffer.put( (byte)isnameTagLength );
+ isname.encode( buffer );
+ }
+
+ // the elements
+ buffer.put( ( byte ) KerberosConstants.AD_AND_OR_ELEMENTS_TAG );
+ buffer.put( (byte)elementsTagLength );
+ elements.encode( buffer );
+ }
+ catch ( BufferOverflowException boe )
+ {
+ LOG.error( I18n.err( I18n.ERR_139, 1 + TLV.getNbBytes( adKdcIssuedSeqLength )
+ + adKdcIssuedSeqLength, buffer.capacity() ) );
+ throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "AD-KDCIssued encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+ LOG.debug( "AD-KDCIssued initial value : {}", toString() );
+ }
+
+ return buffer;
+ }
+
+
+ /**
+ * @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-KDCIssued : {\n" );
+ sb.append( tabs ).append( " ad-cheksum: " ).append( adChecksum.toString( tabs + " " ) ).append( '\n' );
+
+ if ( irealm != null )
+ {
+ sb.append( tabs ).append( " i-realm: " ).append( irealm ).append( '\n' );
+ }
+
+
+ if ( isname != null )
+ {
+ sb.append( tabs ).append( " i-sname: " ).append( isname.toString() ).append( '\n' );
+ }
+
+ sb.append( tabs + " elements:" ).append( elements.toString( tabs + " " ) ).append( '\n' );
+ sb.append( tabs + "}\n" );
+
+ return sb.toString();
+ }
+}