【发布时间】:2018-10-25 06:33:54
【问题描述】:
尝试使用 JWT(JSON Web 令牌)创建具有用户身份验证的应用程序。但是,当我开始配置 WebSecurityConfig.java 时,我遇到了下一个问题:
@Override
protected void configure(HttpSecurity http) throws Exception {
String[] permited = new String[security.getIgnored().size()];
security.getIgnored().toArray(permited);
http
.csrf().disable()
.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.antMatchers("/api/authenticate").permitAll()
.antMatchers("/api/user").permitAll()
.antMatchers("/").permitAll()
.antMatchers("/favicon.ico").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginProcessingUrl("/api/authentication")
.successHandler(ajaxAuthenticationSuccessHandler)
.failureHandler(ajaxAuthenticationFailureHandler)
.usernameParameter("username")
.passwordParameter("password")
.and()
.logout()
.logoutUrl("/api/logout")
.logoutSuccessHandler(ajaxLogoutSuccessHandler)
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID");
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
http.headers().cacheControl();
}
它告诉我它“无法解决方法 getIgnored()”。这只是这种方法开始时的最初几个步骤。
我了解到spring有2个同名的类:
所以我需要第二类的 getIgnored() 方法。请帮我完成这个过程。我知道这可能是一个愚蠢的问题,但我感谢任何帮助。
顺便说一句,这就是我使用@Autowired 注释定义“安全性”的方式:
@Autowired
SecurityProperties security;
【问题讨论】:
-
您的依赖项可能一团糟。您需要严格遵守 Spring Boot 2 中的内容。您需要发布您的 Pom 以便我们提供帮助。
标签: java spring spring-boot spring-security jwt