2 // ServiceAuthorizationBehavior.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
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;
36 namespace System.ServiceModel.Description
38 public sealed class ServiceAuthorizationBehavior : IServiceBehavior
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;
47 public ServiceAuthorizationBehavior ()
51 public ReadOnlyCollection<IAuthorizationPolicy> ExternalAuthorizationPolicies {
52 get { return ext_auth_policies; }
53 set { ext_auth_policies = value; }
56 public bool ImpersonateCallerForAllOperations {
57 get { return impersonate; }
58 set { impersonate = value; }
61 public PrincipalPermissionMode PrincipalPermissionMode {
62 get { return perm_mode; }
63 set { perm_mode = value; }
66 public RoleProvider RoleProvider {
67 get { return role_provider; }
68 set { role_provider = value; }
71 public ServiceAuthorizationManager ServiceAuthorizationManager {
72 get { return svc_auth_manager; }
73 set { svc_auth_manager = value; }
76 void IServiceBehavior.AddBindingParameters (
77 ServiceDescription description,
78 ServiceHostBase serviceHostBase,
79 Collection<ServiceEndpoint> endpoints,
80 BindingParameterCollection parameters)
84 void IServiceBehavior.ApplyDispatchBehavior (
85 ServiceDescription description,
86 ServiceHostBase serviceHostBase)
88 foreach (var cdb in serviceHostBase.ChannelDispatchers) {
89 var cd = cdb as ChannelDispatcher;
90 if (cd == null) // non-ChannelDispatcher ChannelDispatcherBase instance.
92 foreach (var ed in cd.Endpoints) {
93 var dr = ed.DispatchRuntime;
94 dr.ExternalAuthorizationPolicies = ExternalAuthorizationPolicies;
95 dr.ImpersonateCallerForAllOperations = ImpersonateCallerForAllOperations;
96 dr.PrincipalPermissionMode = PrincipalPermissionMode;
97 dr.RoleProvider = RoleProvider;
98 dr.ServiceAuthorizationManager = ServiceAuthorizationManager;
104 void IServiceBehavior.Validate (
105 ServiceDescription description,
106 ServiceHostBase serviceHostBase)