4 changed files with 0 additions and 92 deletions
@ -1,33 +0,0 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 http://www.renren.io
|
|||
* <p> |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|||
* use this file except in compliance with the License. You may obtain a copy of |
|||
* the License at |
|||
* <p> |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* <p> |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|||
* License for the specific language governing permissions and limitations under |
|||
* the License. |
|||
*/ |
|||
|
|||
package com.epmet.commons.tools.annotation; |
|||
|
|||
import com.epmet.commons.tools.enums.RequirePermissionEnum; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 运营端-权限注解 |
|||
* @Author wxz |
|||
* @Description |
|||
* @Date 2022/09/27 16:17 |
|||
**/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface OperRequiredPermission { |
|||
} |
@ -1,56 +0,0 @@ |
|||
package com.epmet.commons.tools.aspect; |
|||
|
|||
import com.epmet.commons.tools.dto.form.HasOperPermissionFormDTO; |
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.EpmetException; |
|||
import com.epmet.commons.tools.feign.CommonOperAccessOpenFeignClient; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import org.aspectj.lang.JoinPoint; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Before; |
|||
import org.aspectj.lang.reflect.MethodSignature; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.core.annotation.Order; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.context.request.RequestContextHolder; |
|||
import org.springframework.web.context.request.ServletRequestAttributes; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
|
|||
@Aspect |
|||
@Component |
|||
@Order(30) |
|||
public class OperRequiredPermissionAspect { |
|||
|
|||
@Autowired |
|||
private CommonOperAccessOpenFeignClient operAccessOpenFeignClient; |
|||
|
|||
@Before("@annotation(com.epmet.commons.tools.annotation.OperRequiredPermission)") |
|||
public void proceed(JoinPoint pjp) throws Throwable { |
|||
// MethodSignature signature = (MethodSignature) pjp.getSignature();
|
|||
HttpServletRequest request = getRequest(); |
|||
|
|||
String url = request.getRequestURI().toString(); |
|||
String method = request.getMethod(); |
|||
|
|||
HasOperPermissionFormDTO form = new HasOperPermissionFormDTO(); |
|||
form.setUri(url); |
|||
form.setMethod(method); |
|||
Result result = operAccessOpenFeignClient.hasOperPermission(form); |
|||
if (result == null || !result.success()) { |
|||
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "资源未授权", "资源未授权"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取Request对象 |
|||
* |
|||
* @return |
|||
*/ |
|||
private HttpServletRequest getRequest() { |
|||
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); |
|||
ServletRequestAttributes sra = (ServletRequestAttributes) ra; |
|||
return sra.getRequest(); |
|||
} |
|||
} |
Loading…
Reference in new issue