コード例 #1
0
        public bool IsAuthorized(UserContext userContext, Uri resourceUri)
        {
            SenderInfo senderInfo = new SenderInfo(userContext.GetIdentity(), userContext.ClientCertificate, resourceUri);

            CustomAuthorizationHandler.CustomContext customContext = null;
            TraceHelper.Current.MethodCall0("CustomAuthorizationHandler", "IsAuthorized");
            try
            {
                using (OperationTracerWithTimeout operationTracerWithTimeout = new OperationTracerWithTimeout(new Action <string>(TraceHelper.Current.CustomAuthzCallStart), new Action <string>(TraceHelper.Current.CustomAuthzCallEnd), "AuthorizeUser", new Action <string>(TraceHelper.Current.CustomAuthzExceedTimeLimit), 30))
                {
                    UserQuota       userQuotum      = null;
                    WindowsIdentity windowsIdentity = this.customAuthorization.AuthorizeUser(senderInfo, out userQuotum);
                    if (windowsIdentity != null)
                    {
                        if (userQuotum != null)
                        {
                            TraceHelper.Current.UserQuotaInformation(userContext.Name, userQuotum.MaxConcurrentRequests, userQuotum.MaxRequestsPerTimeSlot, userQuotum.TimeSlotSize);
                            customContext = new CustomAuthorizationHandler.CustomContext(windowsIdentity, userQuotum);
                        }
                        else
                        {
                            object[] nullQuota = new object[2];
                            nullQuota[0] = "CustomAuthorization.AuthorizeUser";
                            nullQuota[1] = Resources.NullQuota;
                            throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, nullQuota));
                        }
                    }
                    else
                    {
                        object[] nullWindowsIdentity = new object[2];
                        nullWindowsIdentity[0] = "CustomAuthorization.AuthorizeUser";
                        nullWindowsIdentity[1] = Resources.NullWindowsIdentity;
                        throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, nullWindowsIdentity));
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (!exception.IsSevereException())
                {
                    exception.Trace(null);
                }
                else
                {
                    throw;
                }
            }
            this.customContextStore.StoreContext(customContext);
            if (customContext == null || customContext.Identity == null)
            {
                TraceHelper.Current.AuthorizeUserRequestFailed(userContext.Name, userContext.AuthenticationType);
                return(false);
            }
            else
            {
                TraceHelper.Current.AuthorizeUserRequestSucceeded(userContext.Name);
                return(true);
            }
        }
コード例 #2
0
        public string GetMembershipId(UserContext userContext, Uri resourceUri)
        {
            string membershipId;
            string str;

            TraceHelper.Current.MethodCall0("CustomAuthorizationHandler", "GetMembershipId");
            SenderInfo senderInfo = new SenderInfo(userContext.GetIdentity(), userContext.ClientCertificate, resourceUri);

            try
            {
                using (OperationTracerWithTimeout operationTracerWithTimeout = new OperationTracerWithTimeout(new Action <string>(TraceHelper.Current.CustomAuthzCallStart), new Action <string>(TraceHelper.Current.CustomAuthzCallEnd), "GetMembershipId", new Action <string>(TraceHelper.Current.CustomAuthzExceedTimeLimit), 30))
                {
                    membershipId = this.customAuthorization.GetMembershipId(senderInfo);
                    if (string.IsNullOrEmpty(membershipId))
                    {
                        object[] objArray = new object[2];
                        objArray[0] = "CustomAuthorization.AuthorizeUser";
                        objArray[1] = "<null>";
                        throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, objArray));
                    }
                }
                str = membershipId;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                TraceHelper.Current.GetMembershipId(userContext.Name, exception.Message);
                if (!exception.IsSevereException())
                {
                    throw new CustomModuleInvocationFailedException(this.customAuthorization.GetType().AssemblyQualifiedName, "GetMembershipId", exception);
                }
                else
                {
                    throw;
                }
            }
            return(str);
        }