前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Security 自定义登录页

Spring Security 自定义登录页

作者头像
Demo_Null
发布2020-10-26 17:09:14
6700
发布2020-10-26 17:09:14
举报
文章被收录于专栏:Java 学习Java 学习

1.1 自定义登录页面

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登陆</title>
</head>
<body>

--欢迎的登陆系统--
<!-- 提交地址必须为:/login, 用户名为:username, 密码为:password-->
<form action="/login" method="post">
	用户名:<input name="username"><br>
	密码:<input name="password"><br>
	<button>登陆</button>
</form>


</body>
</html>

1.2 修改配置文件

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/security
                http://www.springframework.org/schema/security/spring-security.xsd">

    <!-- 设置页面不登陆也可以访问 -->
    <http pattern="/login.html" security="none"></http>
    <http pattern="/login_error.html" security="none"></http>

    <!-- 页面的拦截规则    use-expressions:是否启动 SPEL 表达式 默认是 true -->
    <http use-expressions="false">
        <!-- 当前用户必须有 ROLE_USER 的角色 才可以访问根目录及所属子目录的资源 -->
        <intercept-url pattern="/**" access="ROLE_USER"/>
        
        <!-- 开启表单登陆功能 
	        login.html ☞ 登录页
	        login_error.html ☞ 错误页
	        index.html ☞ 首页 
        -->
        <form-login login-page="/login.html" 
			        default-target-url="/index.html" 
			        authentication-failure-url="/login_error.html"/>
			        
        <!-- 关闭跨站请求伪造 -->
        <csrf disabled="true"/>
    </http>

    <!-- 认证管理器 -->
    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="admin" password="123456" authorities="ROLE_USER"/>
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-10-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.1 自定义登录页面
  • 1.2 修改配置文件
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档