Пример #1
0
        public void AfterExecution(IInvocation invocation, bool topLevelIntercept, StageResult state)
        {
            if (!topLevelIntercept)
                return;

            if (AuthenticationIgnoreAttribute.MarkedAuthenticationIgnore(invocation))
                return;

            var authorizationAttribute = GetCanBeAuthorizedByAttribute(invocation);
            if (authorizationAttribute == null || (authorizationAttribute.AuthorizingClaims == null && authorizationAttribute.AuthorizingTypes == null))
                return;
           
            var isSearch = authorizationAttribute.AuthorizingTypes != null &&
                            authorizationAttribute.AuthorizingTypes.Contains(AuthorizationDelegate.Search);

            if ((authorizationAttribute.AuthorizingClaims == null ||
                 (!authorizationAttribute.AuthorizingClaims.Contains(EdFiClaimTypes.ViewAllStudents) &&
                  !authorizationAttribute.AuthorizingClaims.Contains(EdFiClaimTypes.ViewMyStudents))) && !isSearch)
                return;

            object value;
            int? educationOrganization = null;
                
            if (TryGetParameterValue(invocation, "SchoolId", out value))
            {
                if (value != null)
                {
                    educationOrganization = Convert.ToInt32(value);
                    if (educationOrganization == 0)
                    {
                        educationOrganization = null;
                        //throw new Exception("Unable to retrieve school id from parameter value.");
                    }
                }
            }

            if (!educationOrganization.HasValue && TryGetParameterValue(invocation,"LocalEducationAgencyId", out value))
            {
                if (value != null)
                {
                    educationOrganization = Convert.ToInt32(value);
                    if (educationOrganization == 0)
                    {
							throw new InvalidOperationException("Unable to retrieve school id from parameter value.");
                    }
                }
            }

            //Education organization may not be set here, this should primarily only be if it is a statewide call.
            var accessibleStudents = currentUserAccessibleStudentsProvider.GetAccessibleStudents(educationOrganization, isSearch);

            var filter = new StudentFilter(accessibleStudents);
            invocation.ReturnValue = filter.ExecuteFilter(invocation.ReturnValue);
        }
Пример #2
0
        public void Intercept(IInvocation invocation)
        {
            if (stages.Length == 0)
                throw new UserAccessDeniedException( "Stage Interceptor has not been configured with stages by the Inversion of Control configuration.");

            var stageStates = new StageResult[stages.Length];
            bool topLevelIntercept = IsOuterLayerCall(GetType().GetMethod("Intercept"));

            try
            {
                bool proceed = true;
                int i = 0;
                for (; i < stages.Length; i++)
                {
                    StageResult state = stages[i].Value.BeforeExecution(invocation, topLevelIntercept);
                    stageStates[i] = state;
                    if (!state.Proceed)
                    {
                        proceed = false;
                        break;
                    }
                }

                if (proceed)
                    invocation.Proceed();

                for (int j = i - 1; j >= 0; j--)
                {
                    if (j >= stages.Length)
                        continue;
                    stages[j].Value.AfterExecution(invocation, topLevelIntercept, stageStates[j]);
                }

            }
            finally
            {
                ClearLayer(topLevelIntercept);
            }

        }
 public void AfterExecution(IInvocation invocation, bool topLevelIntercept, StageResult state)
 {
 }