1 //---------------------------------------------------------- 2 // Copyright (c) Microsoft Corporation. All rights reserved. 3 //------------------------------------------------------------ 4 5 namespace System.ServiceModel.Security 6 { 7 using System.Globalization; 8 using System.ServiceModel.Channels; 9 using System.ServiceModel; 10 using System.ServiceModel.Description; 11 using System.Xml; 12 13 using DictionaryManager = System.IdentityModel.DictionaryManager; 14 using ISecurityElement = System.IdentityModel.ISecurityElement; 15 16 abstract class SecurityHeader : MessageHeader 17 { 18 readonly string actor; 19 readonly SecurityAlgorithmSuite algorithmSuite; 20 bool encryptedKeyContainsReferenceList = true; 21 Message message; 22 readonly bool mustUnderstand; 23 readonly bool relay; 24 bool requireMessageProtection = true; 25 bool processingStarted; 26 bool maintainSignatureConfirmationState; 27 readonly SecurityStandardsManager standardsManager; 28 MessageDirection transferDirection; 29 SecurityHeaderLayout layout = SecurityHeaderLayout.Strict; 30 SecurityHeader(Message message, string actor, bool mustUnderstand, bool relay, SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, MessageDirection transferDirection)31 public SecurityHeader(Message message, 32 string actor, bool mustUnderstand, bool relay, 33 SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite, 34 MessageDirection transferDirection) 35 { 36 if (message == null) 37 { 38 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message"); 39 } 40 if (actor == null) 41 { 42 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("actor"); 43 } 44 if (standardsManager == null) 45 { 46 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("standardsManager"); 47 } 48 if (algorithmSuite == null) 49 { 50 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("algorithmSuite"); 51 } 52 53 this.message = message; 54 this.actor = actor; 55 this.mustUnderstand = mustUnderstand; 56 this.relay = relay; 57 this.standardsManager = standardsManager; 58 this.algorithmSuite = algorithmSuite; 59 this.transferDirection = transferDirection; 60 } 61 62 public override string Actor 63 { 64 get { return this.actor; } 65 } 66 67 public SecurityAlgorithmSuite AlgorithmSuite 68 { 69 get { return this.algorithmSuite; } 70 } 71 72 public bool EncryptedKeyContainsReferenceList 73 { 74 get { return this.encryptedKeyContainsReferenceList; } 75 set 76 { 77 ThrowIfProcessingStarted(); 78 this.encryptedKeyContainsReferenceList = value; 79 } 80 } 81 82 public bool RequireMessageProtection 83 { 84 get { return this.requireMessageProtection; } 85 set 86 { 87 ThrowIfProcessingStarted(); 88 this.requireMessageProtection = value; 89 } 90 } 91 92 public bool MaintainSignatureConfirmationState 93 { 94 get { return this.maintainSignatureConfirmationState; } 95 set 96 { 97 ThrowIfProcessingStarted(); 98 this.maintainSignatureConfirmationState = value; 99 } 100 } 101 102 protected Message Message 103 { 104 get { return this.message; } 105 set { this.message = value; } 106 } 107 108 public override bool MustUnderstand 109 { 110 get { return this.mustUnderstand; } 111 } 112 113 public override bool Relay 114 { 115 get { return this.relay; } 116 } 117 118 public SecurityHeaderLayout Layout 119 { 120 get 121 { 122 return this.layout; 123 } 124 set 125 { 126 ThrowIfProcessingStarted(); 127 this.layout = value; 128 } 129 } 130 131 public SecurityStandardsManager StandardsManager 132 { 133 get { return this.standardsManager; } 134 } 135 136 public MessageDirection MessageDirection 137 { 138 get { return this.transferDirection; } 139 } 140 141 protected MessageVersion Version 142 { 143 get { return this.message.Version; } 144 } 145 SetProcessingStarted()146 protected void SetProcessingStarted() 147 { 148 this.processingStarted = true; 149 } 150 ThrowIfProcessingStarted()151 protected void ThrowIfProcessingStarted() 152 { 153 if (this.processingStarted) 154 { 155 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OperationCannotBeDoneAfterProcessingIsStarted))); 156 } 157 } 158 ToString()159 public override string ToString() 160 { 161 return string.Format(CultureInfo.InvariantCulture, "{0}(Actor = '{1}')", GetType().Name, this.Actor); 162 } 163 } 164 } 165