File: WSDualHttpSecurity.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (101 lines) | stat: -rw-r--r-- 3,657 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel
{
    using System.Runtime;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Configuration;
    using System.ComponentModel;

    public sealed class WSDualHttpSecurity
    {
        static readonly MessageSecurityVersion WSDualMessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;

        internal const WSDualHttpSecurityMode DefaultMode = WSDualHttpSecurityMode.Message;

        WSDualHttpSecurityMode mode;
        MessageSecurityOverHttp messageSecurity;

        public WSDualHttpSecurity()
            : this(DefaultMode, new MessageSecurityOverHttp())
        {
        }

        WSDualHttpSecurity(WSDualHttpSecurityMode mode, MessageSecurityOverHttp messageSecurity)
        {
            Fx.Assert(WSDualHttpSecurityModeHelper.IsDefined(mode), string.Format("Invalid WSDualHttpSecurityMode value: {0}", mode.ToString()));

            this.mode = mode;
            this.messageSecurity = messageSecurity == null ? new MessageSecurityOverHttp() : messageSecurity;
        }

        public WSDualHttpSecurityMode Mode
        {
            get { return this.mode; }
            set
            {
                if (!WSDualHttpSecurityModeHelper.IsDefined(value))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
                }
                this.mode = value;
            }
        }

        public MessageSecurityOverHttp Message
        {
            get { return this.messageSecurity; }
            set
            {
                this.messageSecurity = (value == null) ? new MessageSecurityOverHttp() : value;
            }
        }

        internal SecurityBindingElement CreateMessageSecurity()
        {
            if (this.mode == WSDualHttpSecurityMode.Message)
            {
                return this.messageSecurity.CreateSecurityBindingElement(false, true, WSDualMessageSecurityVersion);
            }
            else
            {
                return null;
            }
        }

        internal static bool TryCreate(SecurityBindingElement sbe, out WSDualHttpSecurity security)
        {
            security = null;
            if (sbe == null)
                security = new WSDualHttpSecurity(WSDualHttpSecurityMode.None, null);
            else
            {
                MessageSecurityOverHttp messageSecurity;
                if (!MessageSecurityOverHttp.TryCreate(sbe, false, true, out messageSecurity))
                    return false;
                security = new WSDualHttpSecurity(WSDualHttpSecurityMode.Message, messageSecurity);
            }
            // the last check: make sure that security binding element match the incoming security
            return SecurityElement.AreBindingsMatching(security.CreateMessageSecurity(), sbe);
        }

        internal bool InternalShouldSerialize()
        {
            return this.ShouldSerializeMode()
                || this.ShouldSerializeMessage();
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeMode()
        {
            return this.Mode != DefaultMode;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeMessage()
        {
            return this.Message.InternalShouldSerialize();
        }
    }
}