1 /******************************************************************************
3 * Copyright (c) 2003 Novell Inc. www.novell.com
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 *******************************************************************************/
24 // Novell.Directory.Ldap.Rfc2251.RfcBindResponse.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using Novell.Directory.Ldap;
34 using Novell.Directory.Ldap.Asn1;
36 namespace Novell.Directory.Ldap.Rfc2251
39 /// <summary> Represents and Ldap Bind Response.
42 /// BindResponse ::= [APPLICATION 1] SEQUENCE {
44 /// COMPONENTS OF LdapResult,
45 /// serverSaslCreds [7] OCTET STRING OPTIONAL }
48 public class RfcBindResponse:Asn1Sequence, RfcResponse
50 /// <summary> Returns the OPTIONAL serverSaslCreds of a BindResponse if it exists
53 virtual public Asn1OctetString ServerSaslCreds
58 return (Asn1OctetString) ((Asn1Tagged) get_Renamed(4)).taggedValue();
62 // could be referral or serverSaslCreds
63 Asn1Object obj = get_Renamed(3);
64 if (obj is Asn1Tagged)
65 return (Asn1OctetString) ((Asn1Tagged) obj).taggedValue();
73 //*************************************************************************
74 // Constructors for BindResponse
75 //*************************************************************************
77 /// <summary> The only time a client will create a BindResponse is when it is
78 /// decoding it from an InputStream
80 /// Note: If serverSaslCreds is included in the BindResponse, it does not
81 /// need to be decoded since it is already an OCTET STRING.
83 [CLSCompliantAttribute(false)]
84 public RfcBindResponse(Asn1Decoder dec, System.IO.Stream in_Renamed, int len):base(dec, in_Renamed, len)
87 // Decode optional referral from Asn1OctetString to Referral.
90 Asn1Tagged obj = (Asn1Tagged) get_Renamed(3);
91 Asn1Identifier id = obj.getIdentifier();
92 if (id.Tag == RfcLdapResult.REFERRAL)
94 sbyte[] content = ((Asn1OctetString) obj.taggedValue()).byteValue();
95 System.IO.MemoryStream bais = new System.IO.MemoryStream(SupportClass.ToByteArray(content));
96 set_Renamed(3, new RfcReferral(dec, bais, content.Length));
101 //*************************************************************************
103 //*************************************************************************
105 /// <summary> </summary>
106 public Asn1Enumerated getResultCode()
108 return (Asn1Enumerated) get_Renamed(0);
111 /// <summary> </summary>
112 public RfcLdapDN getMatchedDN()
114 return new RfcLdapDN(((Asn1OctetString) get_Renamed(1)).byteValue());
117 /// <summary> </summary>
118 public RfcLdapString getErrorMessage()
120 return new RfcLdapString(((Asn1OctetString) get_Renamed(2)).byteValue());
123 /// <summary> </summary>
124 public RfcReferral getReferral()
128 Asn1Object obj = get_Renamed(3);
129 if (obj is RfcReferral)
130 return (RfcReferral) obj;
135 /// <summary> Override getIdentifier to return an application-wide id.</summary>
136 public override Asn1Identifier getIdentifier()
138 return new Asn1Identifier(Asn1Identifier.APPLICATION, true, LdapMessage.BIND_RESPONSE);