抱歉,标题太差了,我不知道怎么用语言表达。
我的问题是,我使用创建了一个项目:
当我映射一个URL并尝试访问它时,我得到了一个很好的登录表单:
但是当我用
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("admin").password("admin").roles("ADMIN");
}
}我收到了这个丑陋的登录表单
我猜是因为在重写配置时,有些东西正在更改Spring使用的登录表单,或者我使用Spring安全性错误。
有人能告诉我为什么会这样吗?谢谢!
发布于 2017-05-26 19:51:43
第一个不错的登录表单属于您的浏览器。如果您尝试使用不同的浏览器,您将看到不同的结果。所发生的情况是,当浏览器请求应用程序的URL时,应用程序将使用未经授权的代码进行响应,然后,浏览器要求您提供凭据来重试请求。
丑陋的登录表单是Spring的默认形式。你可以随心所欲地把它风格化。您可以看到这或这示例来帮助您入门。您需要添加一些CSS。
扩展类configure(HttpSecurity http)时没有覆盖的方法WebSecurityConfigurerAdapter的默认实现如下所示:
protected void configure(HttpSecurity http) throws Exception {
logger.debug("Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity).");
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin().and()
.httpBasic();
}.formLogin()是你获得丑陋的登录表单的地方。
https://stackoverflow.com/questions/44208945
复制相似问题