Normalize line endings.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Description / ServiceAuthorizationBehavior.cs
1 //
2 // ServiceAuthorizationBehavior.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System.Collections.ObjectModel;
29 using System.IdentityModel.Policy;
30 using System.Runtime.Serialization;
31 using System.ServiceModel;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Dispatcher;
34 using System.Web.Security;
35
36 namespace System.ServiceModel.Description
37 {
38         public sealed class ServiceAuthorizationBehavior : IServiceBehavior
39         {
40                 bool impersonate;
41                 PrincipalPermissionMode perm_mode =
42                         PrincipalPermissionMode.UseWindowsGroups; // funky default value
43                 RoleProvider role_provider;
44                 ServiceAuthorizationManager svc_auth_manager;
45                 ReadOnlyCollection<IAuthorizationPolicy> ext_auth_policies;
46
47                 public ServiceAuthorizationBehavior ()
48                 {
49                 }
50
51                 public ReadOnlyCollection<IAuthorizationPolicy> ExternalAuthorizationPolicies {
52                         get { return ext_auth_policies; }
53                         set { ext_auth_policies = value; }
54                 }
55
56                 public bool ImpersonateCallerForAllOperations {
57                         get { return impersonate; }
58                         set { impersonate = value; }
59                 }
60
61                 public PrincipalPermissionMode PrincipalPermissionMode {
62                         get { return perm_mode; }
63                         set { perm_mode = value; }
64                 }
65
66                 public RoleProvider RoleProvider {
67                         get { return role_provider; }
68                         set { role_provider = value; }
69                 }
70
71                 public ServiceAuthorizationManager ServiceAuthorizationManager {
72                         get { return svc_auth_manager; }
73                         set { svc_auth_manager = value; }
74                 }
75
76                 void IServiceBehavior.AddBindingParameters (
77                         ServiceDescription description,
78                         ServiceHostBase serviceHostBase,
79                         Collection<ServiceEndpoint> endpoints,
80                         BindingParameterCollection parameters)
81                 {
82                 }
83
84                 void IServiceBehavior.ApplyDispatchBehavior (
85                         ServiceDescription description,
86                         ServiceHostBase serviceHostBase)
87                 {
88                         foreach (ChannelDispatcher cd in serviceHostBase.ChannelDispatchers)
89                                 foreach (var ed in cd.Endpoints) {
90                                         var dr = ed.DispatchRuntime;
91                                         dr.ExternalAuthorizationPolicies = ExternalAuthorizationPolicies;
92                                         dr.ImpersonateCallerForAllOperations = ImpersonateCallerForAllOperations;
93                                         dr.PrincipalPermissionMode = PrincipalPermissionMode;
94                                         dr.RoleProvider = RoleProvider;
95                                         dr.ServiceAuthorizationManager = ServiceAuthorizationManager;
96                                 }
97                 }
98
99                 [MonoTODO]
100                 void IServiceBehavior.Validate (
101                         ServiceDescription description,
102                         ServiceHostBase serviceHostBase)
103                 {
104                 }
105         }
106 }