色欲av一区久久精品_久久综合色综合色88_无码在线观看不卡_色黄视频网站_亚洲国产精品久久久久秋霞66

使用AOP進(jìn)行權(quán)限驗(yàn)證 ?

時(shí)間:2023-05-17

首要咱們定義一個(gè)切入點(diǎn)(匹配com.ed.controller.Seller最初的controller的所有public辦法)
@Pointcut(“execution(public*com.ed.controller.Seller*.*(..))”)publicvoidcheckToken(){}
然后在進(jìn)入這些辦法之前進(jìn)行token校驗(yàn)
@Before(“checkToken()”)publicvoidcheck(){
ServletRequestAttributesattributes=(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequestrequest=attributes.getRequest();//查詢cookieCookiecookie=CookieUtil.get(request,CookieConstant.TOKEN);if(cookie==null){
log.warn(“【token校驗(yàn)】Cookie中查不到token”);thrownewSellerAuthorizeException(ResultEnum.TOKEN_ERROR);
}//去redis里查詢StringtokenValue=redisTemplate.opsForValue().get(String.format(RedisConstant.TOKEN_PREFIX,cookie.getValue()));if(StringUtils.isEmpty(tokenValue)){
log.warn(“【token校驗(yàn)】Redis中查不到token”);thrownewSellerAuthorizeException(ResultEnum.TOKEN_ERROR);Java
}
}
拋出的異常可定義一個(gè)handler進(jìn)行攔截,并回來自定義的對(duì)象給前端
@ControllerAdvicepublicclassSellExceptionHandler{
@ExceptionHandler(value=SellerAuthorizeException.class)
@ResponseBodypublicResultVOhandlerSellerException(SellerAuthorizeExceptione){returnResultVOUtil.error(e.getCode(),e.getMessage());
}
}
CookieUtil辦法
/***獲取cookie
*@paramrequest
*@paramname
*@return*/publicstaticCookieget(HttpServletRequestrequest,
Stringname){
MapcookieMap=readCookieMap(request);if(cookieMap.containsKey(name)){returncookieMap.get(name);
}else{returnnull;
}
}/***將cookie封裝成Map
*@paramrequest
*@return*/privatestaticMapreadCookieMap(HttpServletRequestrequest){
MapcookieMap=newHashMap<>();
Cookie[]cookies=request.getCookies();if(cookies!=null){for(Cookiecookie:cookies){
cookieMap.put(cookie.getName(),cookie);
}
}returncookieMap;
}

文章標(biāo)簽:

Copyright ? 2016 廣州思洋文化傳播有限公司,保留所有權(quán)利。 粵ICP備09033321號(hào)

與項(xiàng)目經(jīng)理交流
掃描二維碼
與項(xiàng)目經(jīng)理交流
掃描二維碼
與項(xiàng)目經(jīng)理交流
ciya68