【问题标题】:SecurityProperties in Spring bootSpring Boot 中的安全属性
【发布时间】: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个同名的类:

1) https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/security/SecurityProperties.html

2) https://docs.spring.io/spring-boot/docs/2.0.0.M3/api/org/springframework/boot/autoconfigure/security/SecurityProperties.html

所以我需要第二类的 getIgnored() 方法。请帮我完成这个过程。我知道这可能是一个愚蠢的问题,但我感谢任何帮助。

顺便说一句,这就是我使用@Autowired 注释定义“安全性”的方式:

@Autowired
SecurityProperties security;

【问题讨论】:

  • 您的依赖项可能一团糟。您需要严格遵守 Spring Boot 2 中的内容。您需要发布您的 Pom 以便我们提供帮助。

标签: java spring spring-boot spring-security jwt


【解决方案1】:

嗯,这不是 2 个不同的类,而是不同版本的相同。

getIgnored 方法已被删除,请参阅Github commit

【讨论】:

  • 我明白了。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 2021-07-14
  • 2016-05-14
  • 2017-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多