1:
第一種,添加排除路徑,這里可以添加多個(gè),也可以使用正則表達(dá)式
第二種,標(biāo)記路徑 所有包含.api的接口直接放行
第三種比較高級(jí),自定義注解放行攔截器
@Target(value = {ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface CrossAuth {
}
首先自定義權(quán)限注解
package com.example.pidog.interceptor;
import com.example.pidog.annotation.authority.Admin;
import com.example.pidog.annotation.authority.AuthUtil;
import com.example.pidog.annotation.authority.CrossAuth;
import com.example.pidog.exception.RoleException;
import com.example.pidog.threadLocal.UserThreadLocal;
import io.jsonwebtoken.SignatureException;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
@Component
public class TokenInterceptor implements HandlerInterceptor {
@Resource
private AuthUtil authUtil;
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws SignatureException {
if (handler instanceof HandlerMethod) {
Method method = ((HandlerMethod) handler).getMethod();
if (method.isAnnotationPresent(CrossAuth.class)) {
return true;
}
}
? ? ? ? //這里寫入token驗(yàn)證邏輯
}
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧