首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在spring webservices中使用http-basic-authentication

在spring webservices中使用http-basic-authentication
EN

Stack Overflow用户
提问于 2015-11-11 23:57:01
回答 2查看 4.4K关注 0票数 0

我跟随https://spring.io/guides/gs/producing-web-service/的脚步,用Spring实现了简单的webservice。一切都像预期的那样工作。现在,我正在尝试使用javaconfig向其添加http基本身份验证。我应该如何继续?我找到了一些使用@EnableWebSecurity的链接,但似乎什么都不起作用……服务无需身份验证即可响应...

EN

回答 2

Stack Overflow用户

发布于 2015-11-12 00:14:51

只需创建一个Spring Security配置文件,如下所示:

代码语言:javascript
复制
@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/

票数 3
EN

Stack Overflow用户

发布于 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的博客文章。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33654516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档