Пример #1
0
        public virtual bool Authorize(ServiceContext ctx, IAuthorizationIdentity identity)
        {
            var authorized = this.AuthorizeInternal(ctx, identity);

            if (!authorized)
            {
                ctx.ResultInitialized = true;
                ctx.ResultValue       = AOPResult.Failed("授权失败");
            }
            return(authorized);
        }
Пример #2
0
        public static bool Authorize(ServiceContext ctx, IAuthorizationIdentity identity)
        {
#if !DEBUG
            if (ctx.HttpContext.Request.Method != "POST")
            {
                ctx.ResultInitialized = true;
                ctx.ResultValue       = AOPResult.Failed(-405, "非法请求");
                return(false);
            }
#endif
            return(true);
        }
Пример #3
0
        protected override bool AuthorizeInternal(ServiceContext ctx, IAuthorizationIdentity identity)
        {
            string msg = null;
            var    oa  = (ObsoleteAttribute)identity;

            if (oa != null)
            {
                msg = oa.Message;
            }
            if (string.IsNullOrEmpty(msg))
            {
                msg = "此方法已废弃,请更新客户端";
            }
            ctx.ResultInitialized = true;
            ctx.ResultValue       = AOPResult.Failed(-304, msg);
            return(false);
        }
Пример #4
0
        public virtual bool Authorize(ServiceContext ctx, IAuthorizationIdentity identity)
        {
            var thisType  = this.GetType();
            var validated = ctx.Items[thisType] as bool?;            //避免重复验证

            if (validated != null)
            {
                return(validated.Value);
            }
            var authorized = this.AuthorizeInternal(ctx, identity);

            if (!authorized && !ctx.ResultInitialized)
            {
                ctx.ResultInitialized = true;
                ctx.ResultValue       = AOPResult.Failed(-1, "授权失败");
            }
            ctx.Items[thisType] = authorized;
            return(authorized);
        }
Пример #5
0
 protected override bool AuthorizeInternal(ServiceContext ctx, IAuthorizationIdentity identity)
 {
     return(PostAuthorizeAttribute.Authorize(ctx, identity));
 }
Пример #6
0
 bool IAuthorizationProvider.Authorize(ServiceContext ctx, IAuthorizationIdentity identity)
 {
     return(Authorize(ctx, identity));
 }
Пример #7
0
 protected abstract bool AuthorizeInternal(ServiceContext ctx, IAuthorizationIdentity identity);