| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.ComponentModel; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.Channels |
| | | 7 | | { |
| | | 8 | | public sealed class NetMsmqSecurity |
| | | 9 | | { |
| | | 10 | | internal const NetMsmqSecurityMode DefaultMode = NetMsmqSecurityMode.Transport; |
| | | 11 | | private NetMsmqSecurityMode _mode; |
| | | 12 | | private MsmqTransportSecurity _transportSecurity; |
| | | 13 | | private MessageSecurityOverMsmq _messageSecurity; |
| | | 14 | | |
| | | 15 | | public NetMsmqSecurity() |
| | 0 | 16 | | : this(DefaultMode, null, null) |
| | | 17 | | { |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | internal NetMsmqSecurity(NetMsmqSecurityMode mode) |
| | 0 | 21 | | : this(mode, null, null) |
| | | 22 | | { |
| | 0 | 23 | | } |
| | | 24 | | |
| | 0 | 25 | | private NetMsmqSecurity(NetMsmqSecurityMode mode, MsmqTransportSecurity transportSecurity, MessageSecurityOverMs |
| | | 26 | | { |
| | | 27 | | // Fx.Assert(NetMsmqSecurityModeHelper.IsDefined(mode), string.Format("Invalid NetMsmqSecurityMode value: {0 |
| | | 28 | | |
| | 0 | 29 | | _mode = mode; |
| | 0 | 30 | | _transportSecurity = new MsmqTransportSecurity(); |
| | 0 | 31 | | _messageSecurity = new MessageSecurityOverMsmq(); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | [DefaultValue(DefaultMode)] |
| | | 35 | | public NetMsmqSecurityMode Mode |
| | | 36 | | { |
| | 0 | 37 | | get { return _mode; } |
| | | 38 | | set |
| | | 39 | | { |
| | | 40 | | //if (!NetMsmqSecurityModeHelper.IsDefined(value)) |
| | | 41 | | //{ |
| | | 42 | | // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(v |
| | | 43 | | //} |
| | 0 | 44 | | _mode = value; |
| | 0 | 45 | | } |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | public MsmqTransportSecurity Transport |
| | | 49 | | { |
| | | 50 | | get |
| | | 51 | | { |
| | 0 | 52 | | if (_transportSecurity == null) |
| | 0 | 53 | | _transportSecurity = new MsmqTransportSecurity(); |
| | 0 | 54 | | return _transportSecurity; |
| | | 55 | | } |
| | 0 | 56 | | set { _transportSecurity = value; } |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | public MessageSecurityOverMsmq Message |
| | | 60 | | { |
| | | 61 | | get |
| | | 62 | | { |
| | 0 | 63 | | if (_messageSecurity == null) |
| | 0 | 64 | | _messageSecurity = new MessageSecurityOverMsmq(); |
| | 0 | 65 | | return _messageSecurity; |
| | | 66 | | } |
| | 0 | 67 | | set { _messageSecurity = value; } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | internal void ConfigureTransportSecurity(MsmqBindingElementBase msmq) |
| | | 71 | | { |
| | 0 | 72 | | if (_mode == NetMsmqSecurityMode.Transport || _mode == NetMsmqSecurityMode.Both) |
| | 0 | 73 | | msmq.MsmqTransportSecurity = Transport; |
| | | 74 | | else |
| | 0 | 75 | | msmq.MsmqTransportSecurity.Disable(); |
| | 0 | 76 | | } |
| | | 77 | | |
| | | 78 | | |
| | | 79 | | internal SecurityBindingElement CreateMessageSecurity() |
| | | 80 | | { |
| | 0 | 81 | | return Message.CreateSecurityBindingElement(); |
| | | 82 | | } |
| | | 83 | | } |
| | | 84 | | } |