예제 #1
0
        protected internal override object CreateBehavior()
        {
            ServiceAuthorizationBehavior behavior = new ServiceAuthorizationBehavior();

            behavior.PrincipalPermissionMode = this.PrincipalPermissionMode;
            string roleProviderName = this.RoleProviderName;

            if (!String.IsNullOrEmpty(roleProviderName))
            {
                behavior.RoleProvider = SystemWebHelper.GetRoleProvider(roleProviderName);
                if (behavior.RoleProvider == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
                                                                                  SR.GetString(SR.InvalidRoleProviderSpecifiedInConfig, roleProviderName)));
                }
            }

            behavior.ImpersonateCallerForAllOperations = this.ImpersonateCallerForAllOperations;
            behavior.ImpersonateOnSerializingReply     = this.ImpersonateOnSerializingReply;

            string serviceAuthorizationManagerType = this.ServiceAuthorizationManagerType;

            if (!String.IsNullOrEmpty(serviceAuthorizationManagerType))
            {
                Type type = Type.GetType(serviceAuthorizationManagerType, true);
                if (!typeof(ServiceAuthorizationManager).IsAssignableFrom(type))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
                                                                                  SR.GetString(SR.ConfigInvalidServiceAuthorizationManagerType, serviceAuthorizationManagerType, typeof(ServiceAuthorizationManager))));
                }
                behavior.ServiceAuthorizationManager = (ServiceAuthorizationManager)Activator.CreateInstance(type);
            }
            AuthorizationPolicyTypeElementCollection authorizationPolicies = this.AuthorizationPolicies;

            if (authorizationPolicies.Count > 0)
            {
                List <IAuthorizationPolicy> policies = new List <IAuthorizationPolicy>(authorizationPolicies.Count);
                for (int i = 0; i < authorizationPolicies.Count; ++i)
                {
                    Type type = Type.GetType(authorizationPolicies[i].PolicyType, true);
                    if (!typeof(IAuthorizationPolicy).IsAssignableFrom(type))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
                                                                                      SR.GetString(SR.ConfigInvalidAuthorizationPolicyType, authorizationPolicies[i].PolicyType, typeof(IAuthorizationPolicy))));
                    }
                    policies.Add((IAuthorizationPolicy)Activator.CreateInstance(type));
                }
                behavior.ExternalAuthorizationPolicies = policies.AsReadOnly();
            }
            return(behavior);
        }
        public override void CopyFrom(ServiceModelExtensionElement from)
        {
            base.CopyFrom(from);
            ServiceAuthorizationElement element = (ServiceAuthorizationElement)from;

            this.PrincipalPermissionMode           = element.PrincipalPermissionMode;
            this.RoleProviderName                  = element.RoleProviderName;
            this.ImpersonateCallerForAllOperations = element.ImpersonateCallerForAllOperations;
            this.ServiceAuthorizationManagerType   = element.ServiceAuthorizationManagerType;
            AuthorizationPolicyTypeElementCollection authorizationPolicies = element.AuthorizationPolicies;
            AuthorizationPolicyTypeElementCollection elements2             = this.AuthorizationPolicies;

            for (int i = 0; i < authorizationPolicies.Count; i++)
            {
                elements2.Add(authorizationPolicies[i]);
            }
        }
예제 #3
0
        public override void CopyFrom(ServiceModelExtensionElement from)
        {
            base.CopyFrom(from);

            ServiceAuthorizationElement source = (ServiceAuthorizationElement)from;

#pragma warning suppress 56506 //Microsoft; base.CopyFrom() checks for 'from' being null
            this.PrincipalPermissionMode           = source.PrincipalPermissionMode;
            this.RoleProviderName                  = source.RoleProviderName;
            this.ImpersonateCallerForAllOperations = source.ImpersonateCallerForAllOperations;
            this.ImpersonateOnSerializingReply     = source.ImpersonateOnSerializingReply;
            this.ServiceAuthorizationManagerType   = source.ServiceAuthorizationManagerType;
            AuthorizationPolicyTypeElementCollection srcAuthorizationPolicies = source.AuthorizationPolicies;
            AuthorizationPolicyTypeElementCollection dstAuthorizationPolicies = this.AuthorizationPolicies;
            for (int i = 0; i < srcAuthorizationPolicies.Count; ++i)
            {
                dstAuthorizationPolicies.Add(srcAuthorizationPolicies[i]);
            }
        }