Java Spring-Http基本身份验证-将端点标记为公共
我使用spring提供基本的http身份验证。为此,我只需在应用程序中设置用户和密码。属性: 但是,我希望将端点/静态文件公开为公共文件(不需要身份验证)。有没有一个简单的方法可以做到这一点Java Spring-Http基本身份验证-将端点标记为公共,java,spring,spring-security,basic-authentication,spring-web,Java,Spring,Spring Security,Basic Authentication,Spring Web,我使用spring提供基本的http身份验证。为此,我只需在应用程序中设置用户和密码。属性: 但是,我希望将端点/静态文件公开为公共文件(不需要身份验证)。有没有一个简单的方法可以做到这一点 我发现spring文档很难搜索,因此任何提示都将不胜感激。您可以使用一种方法在应用程序上配置端点: protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests()
我发现spring文档很难搜索,因此任何提示都将不胜感激。您可以使用一种方法在应用程序上配置端点:
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/public/**").permitAll()
.antMatchers("/users/**").hasAuthority("ADMIN")
.anyRequest().fullyAuthenticated()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error")
.usernameParameter("email")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.deleteCookies("remember-me")
.logoutSuccessUrl("/")
.permitAll()
.and()
.rememberMe();
}
完整的示例可以在这里找到:在Spring设置中共享一些代码或配置。我正在使用Spring引导。例如,端点可能看起来像:@RequestMapping(“/greeting”)public int greeting(){return 1;}