コード例 #1
0
        public AuthGroupServiceWrapperTest()
        {
            _groupService = A.Fake<IGroupService>();
            _principal = A.Fake<ClaimsPrincipal>();
            _identity = A.Fake<IIdentity>();

            A.CallTo(() => _principal.Identity).Returns(_identity);
            A.CallTo(() => _identity.IsAuthenticated).Returns(true);

            _entityValidator = A.Fake<EntityValidator>();
            _userStore = A.Fake<IUserStore<IUserDto, int>>();
            _authorizationManager = new EasyTeach.Core.Security.ClaimsAuthorizationManager();

            _authGroupServiceWrapper = new AuthGroupServiceWrapper(
                _groupService,
                _principal,
                _entityValidator,
                _userStore,
                _authorizationManager);
        }
コード例 #2
0
        public AuthScoreServiceWrapper(
            IScoreService scoreService,
            ClaimsPrincipal principal,
            EntityValidator entityValidator,
            IUserStore<IUserDto, int> userStore,
            ClaimsAuthorizationManager authorizationManager)
        {
            if (scoreService == null)
            {
                throw new ArgumentNullException("scoreService");
            }

            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }

            if (userStore == null)
            {
                throw new ArgumentNullException("userStore");
            }

            if (authorizationManager == null)
            {
                throw new ArgumentNullException("authorizationManager");
            }

            _scoreService = scoreService;
            _principal = principal;
            _entityValidator = entityValidator;
            _userStore = userStore;
            _authorizationManager = authorizationManager;
        }
コード例 #3
0
        public AuthVisitServiceWrapper(
            IVisitService visitService, 
            ClaimsPrincipal principal,
            EntityValidator entityValidator,
            IUserStore<IUserDto, int> userStore,
            ClaimsAuthorizationManager authorizationManager)
        {
            if (visitService == null)
            {
                throw new ArgumentNullException("visitService");
            }
            _visitService = visitService;

            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }
            _principal = principal;

            if (entityValidator == null)
            {
                throw new ArgumentNullException("entityValidator");
            }
            _entityValidator = entityValidator;

            if (userStore == null)
            {
                throw new ArgumentNullException("userStore");
            }
            _userStore = userStore;

            if (authorizationManager == null)
            {
                throw new ArgumentNullException("authorizationManager");
            }
            _authorizationManager = authorizationManager;
        }
コード例 #4
0
        public string GetGrade(int value)
        {
            //
            // Method 1. Simple access check using static method.
            // Expect this to be most common method.
            //
            ClaimsPrincipalPermission.CheckAccess("Grade", "read");
            string result = new GradeAction().GetGrade(value);
            Console.WriteLine(result);

            //
            // Method 2. Programmatic check using the permission class
            // Follows model found at http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermission.aspx
            //
            var cpp = new ClaimsPrincipalPermission("Grade", "read");
            cpp.Demand();
            result = new GradeAction().GetGrade(value);
            Console.WriteLine(result);

            //
            // Method 3. Access check interacting directly with the authorization manager.
            //
            var am = new ClaimsAuthorizationManager();

            if (!am.CheckAccess(new AuthorizationContext((ClaimsPrincipal)Thread.CurrentPrincipal, "Grade", "read")))
                throw new SecurityException("Access denied");
            result = new GradeAction().GetGrade(value);
            Console.WriteLine(result);

            //
            // Method 4. Call a method that is protected using the permission attribute class
            //
            result = new GradeAction().ProtectedGetGrade(value);
            Console.WriteLine(result);

            return result;
        }
コード例 #5
0
        /// <summary>
        /// Loads the settings for the IdentityConfiguration from the application or web configuration file.
        /// </summary>
        /// <remarks>
        /// If there is no configuration file, or the named section does not exist, then no exception is thrown,
        /// instead the class is loaded with a set of default values.
        /// </remarks>
        protected void LoadConfiguration(IdentityConfigurationElement element)
        {

            if (element != null)
            {
                //
                // Load the claims authentication manager
                //
                if (element.ClaimsAuthenticationManager.IsConfigured)
                {
                    _claimsAuthenticationManager = GetClaimsAuthenticationManager(element);
                }

                //
                // Load the claims authorization manager.
                //
                if (element.ClaimsAuthorizationManager.IsConfigured)
                {
                    _claimsAuthorizationManager = CustomTypeElement.Resolve<ClaimsAuthorizationManager>(element.ClaimsAuthorizationManager);
                }

                //
                // Load the service level Security Token Handler configuration
                //
                _serviceHandlerConfiguration = LoadHandlerConfiguration(element);
            }

            //
            // Reads handler configuration via LoadConfiguredHandlers. Do this last.
            //
            _securityTokenHandlerCollectionManager = LoadHandlers(element);
        }
コード例 #6
0
 public WifAuthorizer(ClaimsAuthorizationManager manager) {
     this.manager = manager;
 }