Esempio n. 1
0
		/// <summary>
		/// 获取配置文件数据, 只有开启disconf远程才会进行切面
		/// </summary>
		/// <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(disconfFileItem)") public Object decideAccess(org.aspectj.lang.ProceedingJoinPoint pjp, com.baidu.disconf.client.common.annotations.DisconfFileItem disconfFileItem) throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
		public virtual object decideAccess(ProceedingJoinPoint pjp, DisconfFileItem disconfFileItem)
		{

			if (DisClientConfig.Instance.ENABLE_DISCONF)
			{

				MethodSignature ms = (MethodSignature) pjp.Signature;
				Method method = ms.Method;

				//
				// 文件名
				//
				Type cls = method.DeclaringClass;
				DisconfFile disconfFile = cls.getAnnotation(typeof(DisconfFile));

				//
				// Field名
				//
				Field field = MethodUtils.getFieldFromMethod(method, cls.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance), DisConfigTypeEnum.FILE);
				if (field != null)
				{

					//
					// 请求仓库配置数据
					//
					DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.DisconfStoreFileProcessor;
					object ret = disconfStoreProcessor.getConfig(disconfFile.filename(), disconfFileItem.name());
					if (ret != null)
					{
						LOGGER.debug("using disconf store value: " + disconfFile.filename() + " (" + disconfFileItem.name() + " , " + ret + ")");
						return ret;
					}
				}
			}

			object rtnOb;

			try
			{
				// 返回原值
				rtnOb = pjp.proceed();
			}
			catch (Exception t)
			{
				LOGGER.info(t.Message);
				throw t;
			}

			return rtnOb;
		}
Esempio n. 2
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;
		}
Esempio n. 3
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;
		}
Esempio n. 4
0
		/// <summary>
		/// 获取配置项数据, 只有开启disconf远程才会进行切面
		/// </summary>
		/// <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(disconfItem)") public Object decideAccess(org.aspectj.lang.ProceedingJoinPoint pjp, com.baidu.disconf.client.common.annotations.DisconfItem disconfItem) throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
		public virtual object decideAccess(ProceedingJoinPoint pjp, DisconfItem disconfItem)
		{

			if (DisClientConfig.Instance.ENABLE_DISCONF)
			{
				//
				// 请求仓库配置数据
				//
				DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.DisconfStoreItemProcessor;
				object ret = disconfStoreProcessor.getConfig(null, disconfItem.key());
				if (ret != null)
				{
					LOGGER.debug("using disconf store value: (" + disconfItem.key() + " , " + ret + ")");
					return ret;
				}
			}

			object rtnOb;

			try
			{
				// 返回原值
				rtnOb = pjp.proceed();
			}
			catch (Exception t)
			{
				LOGGER.info(t.Message);
				throw t;
			}

			return rtnOb;
		}