Gb1400AuthInterceptor.java
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.viontech.interceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author vion
**/
public class Gb1400AuthInterceptor implements HandlerInterceptor {
private Logger log = LoggerFactory.getLogger(Gb1400AuthInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//拦截国标1400相关接口
String servletPath = request.getServletPath();
if(!servletPath.contains("/VIID/System/Register")){
return true;
}
String authorization = request.getHeader("Authorization");
if(StringUtils.isEmpty(authorization)){
response.addHeader("WWW-Authenticate","Digest realm=\"viid\",qop=\"auth\",nonce=\"123456\",opaque=\"654321\"");
response.setStatus(HttpStatus.UNAUTHORIZED.value());
return false;
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}