【发布时间】:2017-11-22 06:04:02
【问题描述】:
当我注意到一些看起来很奇怪的东西时,我正在努力在我的 Angular 应用中使用 hmac 实现 spring 安全性。
谁能解释我为什么不明白 "X-HMAC-CSRF","X-Secret","WWW-Authenticate" 值 在我的 console.log 中?
console.log(JSON.stringify(response.headers()))
{"pragma":"no-cache","content-type":"application/json;charset=UTF-8","cache-
control":"no-cache, no-store, max-age=0, must-revalidate","expires":"0"}
虽然我在网络 (F12) 中正确获取了它们,但无法记录它们 一段代码:
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
public static final String X_SECRET = "X-Secret";
public static final String CSRF_CLAIM_HEADER = "X-HMAC-CSRF";
response.setHeader(X_SECRET, filteredUrl);
response.setHeader(WWW_AUTHENTICATE,HmacUtils.HMAC_SHA_256);
response.setHeader(CSRF_CLAIM_HEADER, csrfId);
response.addCookie(jwtCookie);
我还添加了一个 cors 过滤器,因为后端和前端不在同一个域中:
@Slf4j
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CorsFilter implements Filter {
@PostConstruct
public void init() {
log.info("Setup cors filter");
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
//TODO ALLOW ALL ORIGIN ???
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,OPTIONS,DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, If-Modified-Since, Accept, Authorization, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, X-Handle-Errors-Generically");
chain.doFilter(req, res);
}
【问题讨论】:
标签: java angularjs spring-boot cors