Spring - Http Basic Auth - 将端点标记为公共

3
我正在使用Spring提供基本的http身份验证。为此,我只是在application.properies中设置用户名和密码: enter image description here 然而,我想公开一个端点/或静态文件作为公共资源(无需进行身份验证)。有简单的方法吗?
我发现Spring文档很难搜索,所以任何提示都将不胜感激。

分享一些你的Spring设置上的代码或配置。 - nobeh
我正在使用Spring Boot。例如,一个端点可能看起来像这样: @RequestMapping("/greeting") public int greeting() { return 1; } - user3452075
1个回答

3
您可以使用一种方法来配置您应用程序的端点:
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();
}

完整的示例可以在此处找到:https://github.com/bkielczewski/example-spring-boot-security

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接