/// <summary> /// 判断用户是否满足一定的规则(按照.config文件里定义的规则名称) /// </summary> /// <param name="rulenName">规则名称</param> /// <returns></returns> public static bool AuthorizeByRuleName(string rulenName, System.Security.Principal.IPrincipal principal = null) { if (principal == null) { principal = System.Threading.Thread.CurrentPrincipal; } string key = "Authority.AuthorizeByRuleName:" + rulenName; return(Cache.TryGetCache <bool>(key, new Func <bool>(delegate() { try { return AuthorizationFactory.GetAuthorizationProvider().Authorize(principal, rulenName); } catch (Exception) { try { return AuthorizationFactory.GetAuthorizationProvider().Authorize(principal, "Others"); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return false; } } }))); }
public bool IsAuthorized(string securityContext) { IAuthorizationProvider ruleProvider = AuthorizationFactory.GetAuthorizationProvider("MyAuthorizationProvider"); //bool ret = ruleProvider.Authorize(LocalUserManager.GetThreadPrinciple(), securityContext); bool ret = ruleProvider.Authorize(LocalUserManager.GetCurrentPrinciple(), securityContext); return(ret); }
public void AuthorizedTaskWithoutData() { IAuthorizationProvider azManProvider = AuthorizationFactory.GetAuthorizationProvider(); bool res = azManProvider.Authorize(cryptographyProviderCollection, authorizedTask); Assert.IsTrue(res); }
public static bool IsCurrentUserAuthorized() { IAuthorizationProvider authorizeProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider"); bool authorized = authorizeProvider.Authorize(System.Threading.Thread.CurrentPrincipal, "ConfigSystem"); return(authorized); }
public void CanCreateAuthorizationRuleProviderFromConfiguration() { IAuthorizationProvider provider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider"); Assert.AreEqual(typeof(AuthorizationRuleProvider), provider.GetType()); AuthorizationRuleProvider ruleProvider = provider as AuthorizationRuleProvider; Assert.IsTrue(ruleProvider.Authorize(new GenericPrincipal(new GenericIdentity("TestUser"), new string[] { "Admin" }), "rule1")); }
public bool userAuthorized(string rule) { bool authorized = false; IAuthorizationProvider authorProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider"); authorized = authorProvider.Authorize(Thread.CurrentPrincipal, rule); return(authorized); }
/// <summary> /// Prevents a default instance of the <see cref="SecurityManager"/> class from being created. /// </summary> /// <externalUnit cref="AuthorizationFactory"/> /// <externalUnit cref="SecurityCacheFactory"/> /// <revision revisor="dev06" date="10/6/2008" version="1.0.0.0">\ /// Member created /// </revision> private SecurityManager() { // Get the default security manager. // Initializes the Enterprise Library authorization and security // caching providers. The ASP.NET Membership and Profile providers // do not need to be initialized in this way // TODO: remove strings to settings file this.ruleProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider"); this.cache = SecurityCacheFactory.GetSecurityCacheProvider( "Caching Store Provider"); }
public bool IsAuthorized(string Username, string rule) { try { string[] roles = Roles.GetRolesForUser(Username); IPrincipal principal = new GenericPrincipal(new GenericIdentity(Username), roles); IAuthorizationProvider ruleProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider"); return(ruleProvider.Authorize(principal, rule)); } catch (Exception err) { MMDBLogFile.Log(err); return(false); } }
private void QuickStartForm_Load(object sender, System.EventArgs e) { // Initialize image to embedded logo this.logoPictureBox.Image = GetEmbeddedImage("SecurityQuickStart.logo.gif"); // Initializes the Enterprise Library authorization and security caching providers // The ASP.NET Membership and Profile providers do not need to be initialized in this way this.ruleProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider"); this.cache = SecurityCacheFactory.GetSecurityCacheProvider("Caching Store Provider"); // Initialize forms displayed for user interaction this.addUserRoleForm = new AddUserRoleForm(); this.userRoleForm = new UserRoleForm(); this.usersForm = new UsersForm(); this.credentialsForm = new CredentialsForm(); this.roleAuthForm = new RoleAuthorizationForm(); this.profileForm = new ProfileForm(); }
public IAuthorizationProvider GetAuthorizationProvider() { return(AuthorizationFactory.GetAuthorizationProvider(Constants.Authorization_Provider)); }
public void TryToCreateAuthorizationProviderFromConfigurationThatDoesNotExist() { AuthorizationFactory.GetAuthorizationProvider("provider3"); }
public void TryToCreateAuthorizationProviderFromConfigurationWithNullName() { AuthorizationFactory.GetAuthorizationProvider(null); }
/// <summary> /// Initializes a new instance of <see cref="EnterpriseLibraryAuthorizationService"/>. /// </summary> public EnterpriseLibraryAuthorizationService() { _authorizationProvider = AuthorizationFactory.GetAuthorizationProvider(); }
/// <summary> /// Initializes a new instance of <see cref="EnterpriseLibraryAuthorizationService"/>. /// </summary> /// <param name="moduleName">The module name to get the authorization rules for.</param> public EnterpriseLibraryAuthorizationService(string moduleName) { _authorizationProvider = AuthorizationFactory.GetAuthorizationProvider(moduleName); }
public EnterpriseLibraryAuthorizationActionCondition(string module) { _authzProvider = AuthorizationFactory.GetAuthorizationProvider(module); }
public EnterpriseLibraryAuthorizationActionCondition() { _authzProvider = AuthorizationFactory.GetAuthorizationProvider(); }
public void CanCreateAuthorizationProviderFromConfiguration() { IAuthorizationProvider provider = AuthorizationFactory.GetAuthorizationProvider("provider2"); Assert.AreEqual(typeof(MockAuthorizationProvider2), provider.GetType()); }