spring - 自定义登录JSP页面 Springboot + SpringSecurity
问题描述
我是springboot的新手,我正在尝试实现自定义登录。它不起作用,它总是出现默认的 spring 安全登录。有什么帮助吗?我一直在寻找解决方案,但找不到适合我的项目的任何东西。请问,有什么想法吗?你可以在这里看到这个项目:
@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {
// add a reference to our security data source
@Autowired
@Qualifier("securityDataSource")
private DataSource securityDataSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// use jdbc authentication ... oh yeah!!!
auth.jdbcAuthentication().dataSource(securityDataSource);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/employees/showForm*").hasAnyRole("MANAGER", "ADMIN")
.antMatchers("/employees/save*").hasAnyRole("MANAGER", "ADMIN")
.antMatchers("/employees/delete").hasRole("ADMIN")
.antMatchers("/employees/**").hasRole("EMPLOYEE")
.antMatchers("/resources/**").permitAll()
.and()
.formLogin()
.loginPage("/fancy-login")
.loginProcessingUrl("/authenticateTheUser")
.permitAll()
.and()
.logout().permitAll()
.and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
}
谢谢!
解决方案
首先尝试这样:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/fancy-login.html")
.permitAll();
}
把你的fancy-login.html 放到resources/static/fancy-login.html。
推荐阅读
- c# - 使用外部模型引用访问 WCF 服务的 Swagger UI 时出错
- python - 如果在 1/100 秒内请求相同的烧瓶 api,则插入后 sqlalchemy 不会更新
- python - 尝试用一个数据帧的元素做最少 2 个数据帧
- ios - 打印 tableview 的计数时出现问题
- c# - 如何将 excel 公式转换为 List 或 somestrongtype
- swift - Swift - 在另一个标签栏项目上关闭视图控制器
- java - 获取 Int 的存储值并在不同的类中使用它
- linux - 使用 AWK 删除与 2 个模式匹配的列
- python - 如何在 Flask 服务器发送事件的生成器中配置 gunicorn 和 gevent 以实现睡眠功能?
- javascript - 似乎无法让突变工作 Prisma GraphQL