我关注了this和 this创建具有基于 Java 后端的 Angular.JS 应用程序框架的教程。其代码可参见 here .
它具有身份验证功能 - 在启动时 Spring boot 会向控制台写入一个随 secret 码,您可以使用该密码登录已启动的应用程序。用户名是user
,密码在开始时打印在控制台中:
现在我想要几个具有固定密码的用户帐户(如果它们是硬编码的,那就没问题)。
如何在该应用程序中执行此操作而不破坏与 AngularJS 的兼容性?
我想我必须修改UiApplication中的SecurityConfiguration
并使用类似的东西
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user")
.password("password")
.roles("USER");
}
如所解释的here ,但我不确定它不会破坏 AngularJS。
最佳答案
这就是解决方案:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
class SecurityConfiguration extends
WebSecurityConfigurerAdapter {
@Autowired
public void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user1")
.password("password1")
.roles("ADMIN")
.and()
.withUser("user2")
.password("password2")
.roles("USER");
}
关于java - Spring boot中如何实现基本认证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31153357/