예제 #1
1
        public async Task <RequestMapping> GetMapPolicyById(int requestMapId)
        {
            RequestMapping req = null;

            using (IDbConnection dbConnection = this.GetConnection())
            {
                try
                {
                    dbConnection.Open();
                    var result = await dbConnection.QueryMultipleAsync("GetMapPolicyById", new
                    {
                        id = requestMapId
                    }, commandType : CommandType.StoredProcedure);

                    var requestEntities = await result.ReadAsync <RequestMapping>();

                    req = requestEntities.FirstOrDefault();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConnection.Close();
                }
            }

            return(req);
        }
예제 #2
0
        public async Task <RequestMapping> MapRequest(RequestMapping mapping)
        {
            RequestMapping req = null;

            using (IDbConnection dbConnection = this.GetConnection())
            {
                try
                {
                    dbConnection.Open();
                    var result = await dbConnection.QueryMultipleAsync("MapPolicy", new
                    {
                        id         = mapping.Id,
                        RequestId  = mapping.RequestId,
                        PolicyId   = mapping.PolicyId,
                        GrossValue = mapping.GrossValue,
                        NetValue   = mapping.NetValue
                    }, commandType : CommandType.StoredProcedure);

                    var requestEntities = await result.ReadAsync <RequestMapping>();

                    req = requestEntities.FirstOrDefault();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(req);
        }
예제 #3
0
        public async Task <bool> UpdateMapPolicy(RequestMapping mapping)
        {
            bool success;

            using (IDbConnection dbConnection = this.GetConnection())
            {
                try
                {
                    dbConnection.Open();
                    var result = await dbConnection.QueryMultipleAsync("UpdateMapPolicy", new
                    {
                        id         = mapping.Id,
                        RequestId  = mapping.RequestId,
                        PolicyId   = mapping.PolicyId,
                        GrossValue = mapping.GrossValue,
                        NetValue   = mapping.NetValue
                    }, commandType : CommandType.StoredProcedure);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    success = true;
                    dbConnection.Close();
                }
            }
            return(success);
        }
예제 #4
0
파일: App.cs 프로젝트: dfcook/Express.NET
        private async void HandleRequest(HttpListener listener)
        {
            try
            {
                var ctx = await listener.GetContextAsync();
                var req = new Request(ctx.Request, this);

                using (var res = new Response(ctx.Response, this))
                {
                    var key = new RequestMapping(ctx.Request.HttpMethod.ToLower(),
                        req.BaseUrl);

                    if (_responders.ContainsKey(key))
                    {
                        var responder = _responders[key];
                        responder(req, res);
                    }
                    else
                    {
                        res.StatusCode(404);
                    }
                }
            }
            catch (HttpListenerException) {  /*ignore*/ }
            catch (ObjectDisposedException) {  /*ignore*/ }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.GetType().Name);
                Console.Error.WriteLine(ex.Message);
            }
        }
예제 #5
0
        internal ArgumentBindingContext(RequestInfo request, RequestMapping requestMapping, ParameterInfo parameter, int index, IDictionary<RequestInfo, RequestInfo[]> multipartBodies)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

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

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

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

            Request = request;
            RequestMapping = requestMapping;
            Parameter = parameter;
            Index = index;
            MultipartBodies = multipartBodies;
        }
예제 #6
0
        internal ArgumentBindingContext(RequestInfo request, RequestMapping requestMapping, ParameterInfo parameter, int index, IDictionary <RequestInfo, RequestInfo[]> multipartBodies)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

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

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

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

            Request         = request;
            RequestMapping  = requestMapping;
            Parameter       = parameter;
            Index           = index;
            MultipartBodies = multipartBodies;
        }
예제 #7
0
		/// <summary>
		/// 判断当前用户对访问的方法是否有权限
		/// </summary>
		/// <param name="pjp">            方法 </param>
		/// <param name="requestMapping"> 方法上的annotation
		/// 
		/// @return
		/// </param>
		/// <exception cref="Throwable"> </exception>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Around("anyPublicMethod() && @annotation(requestMapping)") public Object decideAccess(org.aspectj.lang.ProceedingJoinPoint pjp, org.springframework.web.bind.annotation.RequestMapping requestMapping) throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
		public virtual object decideAccess(ProceedingJoinPoint pjp, RequestMapping requestMapping)
		{

			object rtnOb = null;

			try
			{
				// 执行方法
				rtnOb = pjp.proceed();
			}
			catch (Exception t)
			{
				LOG.info(t.Message);
				throw t;
			}

			return rtnOb;
		}
예제 #8
0
        private object[] BindArguments(string callUri, MethodInfo method, Verb verb, bool indirectly = false)
        {
            var methodUri             = Regex.Replace(callUri, "\\?.+", String.Empty);
            var queryStringParameters = Regex.Matches(callUri, "[?&]([^=]+)=[^&]+").Cast <System.Text.RegularExpressions.Match>();
            var queryStringRegex      = (queryStringParameters.Any() ? "[?&](" + String.Join("|", queryStringParameters.Select(item => item.Groups[1].Value)) + ")=[^&]+" : String.Empty);
            var arguments             = method.GetParameters()
                                        .Select(item => new ArgumentInfo(item, FromQueryStringAttribute.For(item), "&test={?test}", "test"));
            var operation = new OperationInfo <Verb>(
                method,
                (HttpUrl)UrlParser.Parse(methodUri),
                callUri,
                new Regex("^" + methodUri + queryStringRegex + "$"),
                verb,
                arguments.ToArray());
            var request = new RequestInfo(Verb.GET, (HttpUrl)UrlParser.Parse("http://temp.uri" + callUri), new MemoryStream(), new BasicClaimBasedIdentity());
            var mapping = new RequestMapping(GetControllerInstance(), operation, (HttpUrl)UrlParser.Parse(methodUri));

            if (indirectly)
            {
                return(_binder.BindArguments((IRequestInfo)request, (IRequestMapping)mapping));
            }

            return(_binder.BindArguments(request, mapping));
        }
예제 #9
0
		/// <summary>
		/// 判断当前用户对访问的方法是否有权限
		/// </summary>
		/// <param name="pjp">            方法 </param>
		/// <param name="requestMapping"> 方法上的annotation
		/// 
		/// @return
		/// </param>
		/// <exception cref="Throwable"> </exception>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Around("anyPublicMethod() && @annotation(requestMapping) && !@annotation(com.baidu.dsp.common.annotation.NoAuth)") public Object decideAccess(org.aspectj.lang.ProceedingJoinPoint pjp, org.springframework.web.bind.annotation.RequestMapping requestMapping) throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
		public virtual object decideAccess(ProceedingJoinPoint pjp, RequestMapping requestMapping)
		{

			// 获取method上的url,若未标注value则默认为空字符串
			string[] values = requestMapping.value();
			string methodUrl = "";
			if (values.Length != 0)
			{
				methodUrl = values[0];
			}

			string clsUrl = pjp.Target.GetType().getAnnotation(typeof(RequestMapping)).value()[0];

			// 拼接method和class上标注的url
			if (!clsUrl.EndsWith(RoleResourceConstant.URL_SPLITOR, StringComparison.Ordinal) && !methodUrl.StartsWith(RoleResourceConstant.URL_SPLITOR, StringComparison.Ordinal))
			{
				clsUrl += RoleResourceConstant.URL_SPLITOR;
			}

			string urlPattarn = clsUrl + methodUrl;
			if (!urlPattarn.EndsWith(RoleResourceConstant.URL_SPLITOR, StringComparison.Ordinal))
			{
				urlPattarn += RoleResourceConstant.URL_SPLITOR;
			}

			if (noAuthCheckUrl != null && noAuthCheckUrl.Contains(urlPattarn))
			{

				LOG.info("don't need to check this url: " + urlPattarn);
			}
			else
			{

				// 获取method上标注的http method,若未标注method则默认为GET
				RequestMethod[] methods = requestMapping.method();
				RequestMethod methodType = RequestMethod.GET;
				if (methods.Length != 0)
				{
					methodType = methods[0];
				}

				string urlInfo = urlPattarn + ", method:" + methodType.ToString();

				// 获取用户角色
				Visitor visitor = ThreadContext.SessionVisitor;
				if (visitor == null)
				{
					LOG.warn("No session visitor!");
					throw new AccessDeniedException("No session visitor! " + urlInfo);
				}
				int? roleId = visitor.RoleId;
				string visitorInfo = ", UserId:" + visitor.Id + ", RoleId:" + roleId;

				bool? isPriviledged = true;
				// 判断用户是否有权限访问方法
				if (!this.isMethodAccessible(urlPattarn, methodType, roleId))
				{
					isPriviledged = false;
					throw new AccessDeniedException("Access Denied: " + urlInfo + visitorInfo);
				}
				LOG.info("Accessing URL:" + urlInfo + visitorInfo + ", Is priviledged:" + isPriviledged.ToString());
			}

			object rtnOb = null;

			try
			{
				// 执行方法
				rtnOb = pjp.proceed();
			}
			catch (Exception t)
			{
				LOG.info(t.Message);
				throw t;
			}

			return rtnOb;
		}
예제 #10
0
        public async Task <bool> UpdateMapPolicy(RequestMapping mapping)
        {
            var result = await _requestRepository.UpdateMapPolicy(mapping);

            return(result);
        }
예제 #11
0
        public async Task <RequestMapping> MapRequest(RequestMapping mapping)
        {
            var result = await _requestRepository.MapRequest(mapping);

            return(result);
        }
예제 #12
0
        public async Task <IActionResult> UpdateMapPolicy([FromBody] RequestMapping mapping)
        {
            var req = await _requestManager.UpdateMapPolicy(mapping);

            return(Ok(req));
        }