internal void ApplyConfiguration(UserNamePasswordServiceCredential userName) { if (userName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("userName"); } userName.UserNamePasswordValidationMode = this.UserNamePasswordValidationMode; userName.IncludeWindowsGroups = this.IncludeWindowsGroups; userName.CacheLogonTokens = this.CacheLogonTokens; userName.MaxCachedLogonTokens = this.MaxCachedLogonTokens; userName.CachedLogonTokenLifetime = this.CachedLogonTokenLifetime; if (base.ElementInformation.Properties["membershipProviderName"].ValueOrigin != PropertyValueOrigin.Default) { userName.MembershipProvider = SystemWebHelper.GetMembershipProvider(this.MembershipProviderName); if (userName.MembershipProvider == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("InvalidMembershipProviderSpecifiedInConfig", new object[] { this.MembershipProviderName }))); } } else if (userName.UserNamePasswordValidationMode == System.ServiceModel.Security.UserNamePasswordValidationMode.MembershipProvider) { userName.MembershipProvider = SystemWebHelper.GetMembershipProvider(); } if (!string.IsNullOrEmpty(this.CustomUserNamePasswordValidatorType)) { Type c = Type.GetType(this.CustomUserNamePasswordValidatorType, true); if (!typeof(UserNamePasswordValidator).IsAssignableFrom(c)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidUserNamePasswordValidatorType", new object[] { this.CustomUserNamePasswordValidatorType, typeof(UserNamePasswordValidator).ToString() }))); } userName.CustomUserNamePasswordValidator = (UserNamePasswordValidator)Activator.CreateInstance(c); } }
public bool IsInRole(string role) { RoleProvider roleProvider = (this.roleProvider as RoleProvider) ?? SystemWebHelper.GetDefaultRoleProvider(); if (roleProvider != null) { return(roleProvider.IsUserInRole(this.securityContext.PrimaryIdentity.Name, role)); } return(false); }
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); }
private UserNamePasswordValidator GetMembershipProviderValidator() { System.Web.Security.MembershipProvider membershipProvider; if (this.membershipProvider != null) { membershipProvider = (System.Web.Security.MembershipProvider) this.membershipProvider; } else { membershipProvider = SystemWebHelper.GetMembershipProvider(); } if (membershipProvider == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MissingMembershipProvider"))); } return(UserNamePasswordValidator.CreateMembershipProviderValidator(membershipProvider)); }
UserNamePasswordValidator GetMembershipProviderValidator() { MembershipProvider provider; if (this.membershipProvider != null) { provider = (MembershipProvider)this.membershipProvider; } else { provider = SystemWebHelper.GetMembershipProvider(); } if (provider == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MissingMembershipProvider))); } return(UserNamePasswordValidator.CreateMembershipProviderValidator(provider)); }