| | | 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; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF |
| | | 9 | | { |
| | | 10 | | public class WSFederationHttpBinding : WSHttpBindingBase |
| | | 11 | | { |
| | 0 | 12 | | private static readonly MessageSecurityVersion s_wSMessageSecurityVersion = MessageSecurityVersion.WSSecurity11W |
| | | 13 | | private Uri _privacyNoticeAt; |
| | | 14 | | private int _privacyNoticeVersion; |
| | 2 | 15 | | private WSFederationHttpSecurity _security = new WSFederationHttpSecurity(); |
| | | 16 | | |
| | | 17 | | public WSFederationHttpBinding() |
| | 0 | 18 | | : base() |
| | | 19 | | { |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | public WSFederationHttpBinding(WSFederationHttpSecurityMode securityMode) |
| | 0 | 23 | | : this(securityMode, false) |
| | | 24 | | { |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | public WSFederationHttpBinding(WSFederationHttpSecurityMode securityMode, bool reliableSessionEnabled) |
| | 2 | 28 | | : base(reliableSessionEnabled) |
| | | 29 | | { |
| | 2 | 30 | | _security.Mode = securityMode; |
| | 2 | 31 | | } |
| | | 32 | | |
| | | 33 | | |
| | | 34 | | internal WSFederationHttpBinding(WSFederationHttpSecurity security, PrivacyNoticeBindingElement privacy, bool re |
| | 0 | 35 | | : base(reliableSessionEnabled) |
| | | 36 | | { |
| | 0 | 37 | | _security = security; |
| | 0 | 38 | | if (null != privacy) |
| | | 39 | | { |
| | 0 | 40 | | _privacyNoticeAt = privacy.Url; |
| | 0 | 41 | | _privacyNoticeVersion = privacy.Version; |
| | | 42 | | } |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | [DefaultValue(null)] |
| | | 46 | | public Uri PrivacyNoticeAt |
| | | 47 | | { |
| | 50 | 48 | | get { return _privacyNoticeAt; } |
| | 0 | 49 | | set { _privacyNoticeAt = value; } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | [DefaultValue(0)] |
| | | 53 | | public int PrivacyNoticeVersion |
| | | 54 | | { |
| | 0 | 55 | | get { return _privacyNoticeVersion; } |
| | 0 | 56 | | set { _privacyNoticeVersion = value; } |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | public WSFederationHttpSecurity Security |
| | | 60 | | { |
| | 54 | 61 | | get { return _security; } |
| | | 62 | | set |
| | | 63 | | { |
| | 0 | 64 | | if (value == null) |
| | 0 | 65 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 0 | 66 | | _security = value; |
| | 0 | 67 | | } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | private PrivacyNoticeBindingElement CreatePrivacyPolicy() |
| | | 71 | | { |
| | 50 | 72 | | PrivacyNoticeBindingElement privacy = null; |
| | | 73 | | |
| | 50 | 74 | | if (PrivacyNoticeAt != null) |
| | | 75 | | { |
| | 0 | 76 | | privacy = new PrivacyNoticeBindingElement(); |
| | 0 | 77 | | privacy.Url = PrivacyNoticeAt; |
| | 0 | 78 | | privacy.Version = _privacyNoticeVersion; |
| | | 79 | | } |
| | | 80 | | |
| | 50 | 81 | | return privacy; |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | protected override TransportBindingElement GetTransport() |
| | | 85 | | { |
| | 107 | 86 | | if (_security.Mode == WSFederationHttpSecurityMode.None || _security.Mode == WSFederationHttpSecurityMode.Me |
| | | 87 | | { |
| | 0 | 88 | | return HttpTransport; |
| | | 89 | | } |
| | | 90 | | else |
| | | 91 | | { |
| | 107 | 92 | | return HttpsTransport; |
| | | 93 | | } |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | internal static bool GetSecurityModeFromTransport(TransportBindingElement transport, HttpTransportSecurity trans |
| | | 97 | | { |
| | 0 | 98 | | mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message | WSFederationHttpSecurityMo |
| | 0 | 99 | | if (transport is HttpsTransportBindingElement) |
| | | 100 | | { |
| | 0 | 101 | | mode = WSFederationHttpSecurityMode.TransportWithMessageCredential; |
| | | 102 | | } |
| | 0 | 103 | | else if (transport is HttpTransportBindingElement) |
| | | 104 | | { |
| | 0 | 105 | | mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message; |
| | | 106 | | } |
| | | 107 | | else |
| | | 108 | | { |
| | 0 | 109 | | return false; |
| | | 110 | | } |
| | 0 | 111 | | return true; |
| | | 112 | | } |
| | | 113 | | |
| | | 114 | | protected override SecurityBindingElement CreateMessageSecurity() |
| | | 115 | | { |
| | | 116 | | // return security.CreateMessageSecurity(this.ReliableSession.Enabled, WSMessageSecurityVersion); |
| | | 117 | | //TODO : For reliable session |
| | 0 | 118 | | return _security.CreateMessageSecurity(false, s_wSMessageSecurityVersion); |
| | | 119 | | } |
| | | 120 | | |
| | | 121 | | public override BindingElementCollection CreateBindingElements() |
| | | 122 | | { // return collection of BindingElements |
| | | 123 | | |
| | 50 | 124 | | BindingElementCollection bindingElements = base.CreateBindingElements(); |
| | | 125 | | // order of BindingElements is important |
| | | 126 | | |
| | 50 | 127 | | PrivacyNoticeBindingElement privacy = CreatePrivacyPolicy(); |
| | 50 | 128 | | if (privacy != null) |
| | | 129 | | { |
| | | 130 | | // This must go first. |
| | 0 | 131 | | bindingElements.Insert(0, privacy); |
| | | 132 | | } |
| | | 133 | | |
| | 50 | 134 | | return bindingElements; |
| | | 135 | | } |
| | | 136 | | |
| | | 137 | | } |
| | | 138 | | } |