私はSpring Boot 1.4とThymeleaf 2を試しています。アプリケーションを保護したいと思います。これは私のセキュリティの設定です:Spring Boot 1.4とThymeleaf 2のセキュリティ
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/resources/static/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
これは私のMVCコントローラである:私はlocalhost:8080
にアクセスしようとすると、
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/index").setViewName("index");
registry.addViewController("/").setViewName("index");
registry.addViewController("/login").setViewName("login");
}
}
は、しかし、それは、JS、CSSなしインデックス・ページを示しています! localhost:8080/login.html
で手動でログインするとすべて正常に動作します。私はSpringのコンベンションに従います - Thymeleafインテグレーションと静的リソースは/resources/static
、テンプレートは/resource/templates
です。
私の欠点は何ですか?
EDIT:
それはこの方法で動作します:
http
.authorizeRequests()
.antMatchers("/css/**").permitAll()
.antMatchers("/js/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
はしかし、私はこの方法で静的リソースの下にあるすべてのフォルダを追加する必要がありますか?私は何かが恋しいと思う。
それは奇妙だが、それは動作しますあなたのcssファイルとjsファイルを 'src/main/resources/static/resources'に置いたときにさらに設定する必要はありません – baao