Я не могу найти заголовок, который я установил в отправляемом запросе ajax get.ЭТО не бывает всегда.Я что-то здесь упускаю?'JWTAuthorizationFilter' вызывается, и это не так;найти заголовок.Только у Access-Control-Request-Headers
есть имя.Не уверен, почему это происходит.Кроме того, я вижу ошибку Response for preflight is invalid (redirect)
в консоли.
Запрос Ajax:
$.ajax({
url : 'http://localhost:8080/assessments/all',
dataType : 'json',
contentType : 'application/json',
headers : {
'authorization' : localStorage.getItem('authHeader')
},
success : function (response) {
var assessmentTemplate, rating, url;
var assessmentsContainer = $('.assessments-container');
//set data
}
SecurityConfig
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/assessments/**").fullyAuthenticated()
//.antMatchers("/").permitAll()
.and()
.addFilter(new JWTAuthorizationFilter(authenticationManager()))
.formLogin()
//.loginPage("http://htmlcode.s3-website.us-east-2.amazonaws.com")
.loginPage("http://localhost:8000")
.loginProcessingUrl("/login")
.usernameParameter("username")
.passwordParameter("password")
.successHandler(new CustomAuthenticationSuccessHandler())
//.successForwardUrl("/assessment/all")
//.loginPage("/login")
.failureUrl("/login?error")
.permitAll()
.and()
.logout()
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID")
.permitAll();
}
JWTAuthorizationFilter
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
String header = request.getHeader(HEADER_STRING);
if (header == null || !header.startsWith(TOKEN_PREFIX)) {
chain.doFilter(request, response);
return;
}
UsernamePasswordAuthenticationToken authentication = getAuthentication(request);
SecurityContextHolder.getContext().setAuthentication(authentication);
chain.doFilter(request, response);
}