权限操作-springSecurity快速入门-使用自定义页面
生活随笔
收集整理的這篇文章主要介紹了
权限操作-springSecurity快速入门-使用自定义页面
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用自定義頁面
spring-security.xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:security="http://www.springframework.org/schema/security"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security.xsd"> <!-- 配置不過濾的資源(靜態資源及登錄相關) --><security:http security="none" pattern="/login.html" /><security:http security="none" pattern="/failer.html" /><security:http auto-config="true" use-expressions="false" ><!-- 配置資料連接,表示任意路徑都需要ROLE_USER權限 --><security:intercept-url pattern="/**" access="ROLE_USER" /><!-- 自定義登陸頁面,login-page 自定義登陸頁面 authentication-failure-url 用戶權限 校驗失敗之后才會跳轉到這個頁面,如果數據庫中沒有這個用戶則不會跳轉到這個頁面。 default-target-url 登陸成功后跳轉的頁面。 注:登陸頁面用戶名固定 username,密碼 password,action:login --><security:form-login login-page="/login.html"login-processing-url="/login" username-parameter="username"password-parameter="password" authentication-failure-url="/failer.html"default-target-url="/success.html" /><!-- 登出, invalidate-session 是否刪除session logout-url:登出處理鏈接 logout- success-url:登出成功頁面 注:登出操作 只需要鏈接到 logout即可登出當前用戶 --><security:logout invalidate-session="true" logout-url="/logout"logout-success-url="/login.jsp" /><!-- 關閉CSRF,默認是開啟的 --><security:csrf disabled="true" /></security:http><security:authentication-manager><security:authentication-provider><security:user-service><security:user name="user" password="{noop}user"authorities="ROLE_USER" /><security:user name="admin" password="{noop}admin"authorities="ROLE_ADMIN" /></security:user-service></security:authentication-provider></security:authentication-manager> </beans>login.html?
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"><title>數據 - AdminLTE2定制版 | Log in</title><metacontent="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"name="viewport"><link rel="stylesheet"href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet"href="${pageContext.request.contextPath}/plugins/font-awesome/css/font- awesome.min.css"> <link rel="stylesheet"href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css"> <link rel="stylesheet"href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css"> <link rel="stylesheet"href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css"> </head><body class="hold-transition login-page"><div class="login-box"><div class="login-logo"><a href="all-admin-index.html"><b>ITCAST</b>后臺管理系統</a></div><!-- /.login-logo --><div class="login-box-body"><p class="login-box-msg">登錄系統</p><form action="${pageContext.request.contextPath}/login" method="post"><div class="form-group has-feedback"><input type="text" name="username" class="form-control"placeholder="用戶名"> <spanclass="glyphicon glyphicon-envelope form-control-feedback"></span></div><div class="form-group has-feedback"><input type="password" name="password" class="form-control"placeholder="密碼"> <spanclass="glyphicon glyphicon-lock form-control-feedback"></span></div><div class="row"><div class="col-xs-8"><div class="checkbox icheck"><label><input type="checkbox"> 記住 下次自動登錄</label></div></div><!-- /.col --><div class="col-xs-4"><button type="submit" class="btn btn-primary btn-block btn-flat"> 登錄</button></div><!-- /.col --></div></form><a href="#">忘記密碼</a><br></div><!-- /.login-box-body --></div><!-- /.login-box --><!-- jQuery 2.2.3 --><!-- Bootstrap 3.3.6 --><!-- iCheck --><scriptsrc="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script><scriptsrc="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script><scriptsrc="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script><script>$(function() {$('input').iCheck({checkboxClass : 'icheckbox_square-blue',radioClass : 'iradio_square-blue',increaseArea : '20%' // optional});});</script> </body></html>success.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body>success html<br><a href="logout">退出</a> </body> </html>failer.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body>登錄失敗 </body> </html>?
總結
以上是生活随笔為你收集整理的权限操作-springSecurity快速入门-使用自定义页面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 权限操作-springSecurity快
- 下一篇: 用户操作-登录流程分析