我跟随https://spring.io/guides/gs/producing-web-service/的脚步,用Spring实现了简单的webservice。一切都像预期的那样工作。现在,我正在尝试使用javaconfig向其添加http基本身份验证。我应该如何继续?我找到了一些使用@EnableWebSecurity的链接,但似乎什么都不起作用……服务无需身份验证即可响应...
发布于 2015-11-12 00:14:51
只需创建一个Spring Security配置文件,如下所示:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user")
.password("password")
.roles("ROLE_USER");
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.and()
.authorizeRequests()
.anyRequest()
.authenticated();
}下面是一个要跟进的通知教程:http://www.mkyong.com/spring-security/spring-security-hello-world-annotation-example/
发布于 2017-04-30 04:31:06
根据您添加到问题中的标记,我看到您正在使用Spring Boot公开SOAP服务。在这种情况下,只需添加spring-boot-starter-security Spring Boot starter project作为依赖项即可。这将包括Spring Security和by default ‘basic’ authentication is added on all HTTP endpoints (包括SOAP服务)。
默认情况下,启动时会生成一个随机密码,但您可以使用Spring Boot security properties配置您自己的用户名/密码。
如果想了解更多信息,我创建了一篇说明how to setup Spring WS basic authentication using Spring Boot的博客文章。
https://stackoverflow.com/questions/33654516
复制相似问题