gpt4 book ai didi

java - 如何将 Spring Security 配置与 IBM Liberty Profile basicRegistry 连接

转载 作者:行者123 更新时间:2023-12-01 21:58:07 26 4
gpt4 key购买 nike

我有一个正在运行的 springmvc,其中 Spring Security Web 应用程序在 IBM Liberty 配置文件上运行。我使用 java config 来设置所有内容(并且没有 web.xml)。

扩展 WebSecurityConfigurerAdapter 类,我设置了简单的用户列表,如下所示:

@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("bill").password("123456").roles("USER");
}

我不想在代码中包含用户信息,因此我想将用户注册表移至 IBM Liberty Profile 服务器的 server.xml。

<basicRegistry>
<user name="bill" password="123456"/>
</basicRegistry>

我该如何配置?

额外信息我使用一个多模块 Maven 项目,带有一个 Ear 和一个 war 模块。所以在 server.xml 中最后一行是

<enterpriseApplication id="hellospringEAR" location="hellospringEAR-00.00.0001-SNAPSHOT.ear" name="hellospringEAR"/>

非常感谢任何提示或建议。

最佳答案

您需要使用 Spring Security 对容器管理安全性的支持(即 jee() 方法)

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityConfig.class);

@Autowired
private ApplicationProperties appProperties;

@Override
protected void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and().httpBasic();

if (appProperties.isContainerManaged()) {
LOGGER.info("using container managed");
http.jee();
}
http.csrf().disable()
.logout()
.permitAll();
}
}

更多详细信息请参见此处: Roles / Authorities not working in Websphere Liberty

关于java - 如何将 Spring Security 配置与 IBM Liberty Profile basicRegistry 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40952225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com