| 1 |
/****************************************************************************** |
| 2 |
* The MIT License |
| 3 |
* Copyright (c) 2003 Novell Inc. www.novell.com |
| 4 |
* |
| 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: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice shall be included in |
| 13 |
* all copies or substantial portions of the Software. |
| 14 |
* |
| 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 |
| 21 |
* SOFTWARE. |
| 22 |
*******************************************************************************/ |
| 23 |
// |
| 24 |
// Novell.Directory.Ldap.Rfc2251.RfcBindResponse.cs |
| 25 |
// |
| 26 |
// Author: |
| 27 |
// Sunil Kumar ([email protected]) |
| 28 |
// |
| 29 |
// (C) 2003 Novell, Inc (http://www.novell.com) |
| 30 |
// |
| 31 |
|
| 32 |
using System; |
| 33 |
using Novell.Directory.Ldap; |
| 34 |
using Novell.Directory.Ldap.Asn1; |
| 35 |
|
| 36 |
namespace Novell.Directory.Ldap.Rfc2251 |
| 37 |
{ |
| 38 |
|
| 39 |
/// <summary> Represents and Ldap Bind Response. |
| 40 |
/// |
| 41 |
/// <pre> |
| 42 |
/// BindResponse ::= [APPLICATION 1] SEQUENCE { |
| 43 |
/// |
| 44 |
/// COMPONENTS OF LdapResult, |
| 45 |
/// serverSaslCreds [7] OCTET STRING OPTIONAL } |
| 46 |
/// </pre> |
| 47 |
/// </summary> |
| 48 |
public class RfcBindResponse:Asn1Sequence, RfcResponse |
| 49 |
{ |
| 50 |
/// <summary> Returns the OPTIONAL serverSaslCreds of a BindResponse if it exists |
| 51 |
/// otherwise null. |
| 52 |
/// </summary> |
| 53 |
virtual public Asn1OctetString ServerSaslCreds |
| 54 |
{ |
| 55 |
get |
| 56 |
{ |
| 57 |
if (size() == 5) |
| 58 |
return (Asn1OctetString) ((Asn1Tagged) get_Renamed(4)).taggedValue(); |
| 59 |
|
| 60 |
if (size() == 4) |
| 61 |
{ |
| 62 |
// could be referral or serverSaslCreds |
| 63 |
Asn1Object obj = get_Renamed(3); |
| 64 |
if (obj is Asn1Tagged) |
| 65 |
return (Asn1OctetString) ((Asn1Tagged) obj).taggedValue(); |
| 66 |
} |
| 67 |
|
| 68 |
return null; |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
//************************************************************************* |
| 74 |
// Constructors for BindResponse |
| 75 |
//************************************************************************* |
| 76 |
|
| 77 |
/// <summary> The only time a client will create a BindResponse is when it is |
| 78 |
/// decoding it from an InputStream |
| 79 |
/// |
| 80 |
/// Note: If serverSaslCreds is included in the BindResponse, it does not |
| 81 |
/// need to be decoded since it is already an OCTET STRING. |
| 82 |
/// </summary> |
| 83 |
[CLSCompliantAttribute(false)] |
| 84 |
public RfcBindResponse(Asn1Decoder dec, System.IO.Stream in_Renamed, int len):base(dec, in_Renamed, len) |
| 85 |
{ |
| 86 |
|
| 87 |
// Decode optional referral from Asn1OctetString to Referral. |
| 88 |
if (size() > 3) |
| 89 |
{ |
| 90 |
Asn1Tagged obj = (Asn1Tagged) get_Renamed(3); |
| 91 |
Asn1Identifier id = obj.getIdentifier(); |
| 92 |
if (id.Tag == RfcLdapResult.REFERRAL) |
| 93 |
{ |
| 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)); |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
//************************************************************************* |
| 102 |
// Accessors |
| 103 |
//************************************************************************* |
| 104 |
|
| 105 |
/// <summary> </summary> |
| 106 |
public Asn1Enumerated getResultCode() |
| 107 |
{ |
| 108 |
return (Asn1Enumerated) get_Renamed(0); |
| 109 |
} |
| 110 |
|
| 111 |
/// <summary> </summary> |
| 112 |
public RfcLdapDN getMatchedDN() |
| 113 |
{ |
| 114 |
return new RfcLdapDN(((Asn1OctetString) get_Renamed(1)).byteValue()); |
| 115 |
} |
| 116 |
|
| 117 |
/// <summary> </summary> |
| 118 |
public RfcLdapString getErrorMessage() |
| 119 |
{ |
| 120 |
return new RfcLdapString(((Asn1OctetString) get_Renamed(2)).byteValue()); |
| 121 |
} |
| 122 |
|
| 123 |
/// <summary> </summary> |
| 124 |
public RfcReferral getReferral() |
| 125 |
{ |
| 126 |
if (size() > 3) |
| 127 |
{ |
| 128 |
Asn1Object obj = get_Renamed(3); |
| 129 |
if (obj is RfcReferral) |
| 130 |
return (RfcReferral) obj; |
| 131 |
} |
| 132 |
return null; |
| 133 |
} |
| 134 |
|
| 135 |
/// <summary> Override getIdentifier to return an application-wide id.</summary> |
| 136 |
public override Asn1Identifier getIdentifier() |
| 137 |
{ |
| 138 |
return new Asn1Identifier(Asn1Identifier.APPLICATION, true, LdapMessage.BIND_RESPONSE); |
| 139 |
} |
| 140 |
} |
| 141 |
} |