Ejemplo n.º 1
0
        /// <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;
                    }
                }
            })));
        }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
0
        public bool userAuthorized(string rule)
        {
            bool authorized = false;

            IAuthorizationProvider authorProvider = AuthorizationFactory.GetAuthorizationProvider("RuleProvider");

            authorized = authorProvider.Authorize(Thread.CurrentPrincipal, rule);

            return(authorized);
        }
Ejemplo n.º 7
0
 /// <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");
 }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
 public IAuthorizationProvider GetAuthorizationProvider()
 {
     return(AuthorizationFactory.GetAuthorizationProvider(Constants.Authorization_Provider));
 }
Ejemplo n.º 11
0
 public void TryToCreateAuthorizationProviderFromConfigurationThatDoesNotExist()
 {
     AuthorizationFactory.GetAuthorizationProvider("provider3");
 }
Ejemplo n.º 12
0
 public void TryToCreateAuthorizationProviderFromConfigurationWithNullName()
 {
     AuthorizationFactory.GetAuthorizationProvider(null);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of <see cref="EnterpriseLibraryAuthorizationService"/>.
 /// </summary>
 public EnterpriseLibraryAuthorizationService()
 {
     _authorizationProvider = AuthorizationFactory.GetAuthorizationProvider();
 }
Ejemplo n.º 14
0
 /// <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);
 }
Ejemplo n.º 15
0
 public EnterpriseLibraryAuthorizationActionCondition(string module)
 {
     _authzProvider = AuthorizationFactory.GetAuthorizationProvider(module);
 }
Ejemplo n.º 16
0
 public EnterpriseLibraryAuthorizationActionCondition()
 {
     _authzProvider = AuthorizationFactory.GetAuthorizationProvider();
 }
Ejemplo n.º 17
0
        public void CanCreateAuthorizationProviderFromConfiguration()
        {
            IAuthorizationProvider provider = AuthorizationFactory.GetAuthorizationProvider("provider2");

            Assert.AreEqual(typeof(MockAuthorizationProvider2), provider.GetType());
        }