directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: rev 56327 - incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder
Date Tue, 02 Nov 2004 02:38:01 GMT
Author: erodriguez
Date: Mon Nov  1 18:38:00 2004
New Revision: 56327

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java
Log:
Infrastructure for return error messages to clients.

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java
Mon Nov  1 18:38:00 2004
@@ -0,0 +1,65 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.kerberos.messages.*;
+import org.bouncycastle.asn1.*;
+
+import java.io.*;
+
+public class ErrorMessageEncoder extends KerberosMessageEncoder {
+	
+	public OutputStream encode(ErrorMessage message, OutputStream os) throws IOException {
+		
+		ASN1OutputStream aos = new ASN1OutputStream(os);
+		
+		DERSequence errorReply = encodeErrorMessageSequence(message);
+		aos.writeObject(new DERApplicationSpecific(message.getMessageType().getOrdinal(), errorReply));
+		
+		aos.close();
+		
+		return aos;
+	}
+	
+	private DERSequence encodeErrorMessageSequence(ErrorMessage message) {
+		
+		ASN1EncodableVector vector = new ASN1EncodableVector();
+		
+		vector.add(new DERTaggedObject(0, new DERInteger(message.getProtocolVersionNumber())));
+		vector.add(new DERTaggedObject(1, new DERInteger(message.getMessageType().getOrdinal())));
+		if (message.getClientTime() != null)
+			vector.add(new DERTaggedObject(2, encodeKerberosTime(message.getClientTime())));
+		if (message.getClientMicroSecond() != null)
+			vector.add(new DERTaggedObject(3, new DERInteger(message.getClientMicroSecond().intValue())));
+		vector.add(new DERTaggedObject(4, encodeKerberosTime(message.getServerTime())));
+		vector.add(new DERTaggedObject(5, new DERInteger(message.getServerMicroSecond())));
+		vector.add(new DERTaggedObject(6, new DERInteger(message.getErrorCode())));
+		if (message.getClientPrincipal() != null)
+			vector.add(new DERTaggedObject(7, encodeRealm(message.getClientPrincipal().getRealm())));
+		if (message.getClientPrincipal() != null)
+			vector.add(new DERTaggedObject(8, encodePrincipalName(message.getClientPrincipal())));
+		vector.add(new DERTaggedObject(9, encodeRealm(message.getServerPrincipal().getRealm())));
+		vector.add(new DERTaggedObject(10, encodePrincipalName(message.getServerPrincipal())));
+		if (message.getExplanatoryText() != null)
+			vector.add(new DERTaggedObject(11, new DERGeneralString(message.getExplanatoryText())));
+		if (message.getExplanatoryData() != null)
+			vector.add(new DERTaggedObject(12, new DEROctetString(message.getExplanatoryData())));
+		
+		return new DERSequence(vector);
+	}
+}
+

Mime
View raw message