spring security xml配置詳解

security 3.x

<?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-3.0.xsd    
http://www.springframework.org/schema/security   
http://www.springframework.org/schema/security/spring-security-3.1.xsd">  <global-method-security pre-post-annotations="enabled">  </global-method-security>  <!-- 該路徑下的資源不用過濾 -->  <http pattern="/include/js/**" security="none" />  <http pattern="/include/css/**" security="none" />  <http pattern="/include/scripts/**" security="none" />  <http pattern="/include/jsp/**" security="none" />  <http pattern="/images/**" security="none" />  <http pattern="/login.jsp" security="none" />  <!--auto-config = true 則使用from-login. 如果不使用該屬性 則默認為http-basic(沒有session).-->  <!-- lowercase-comparisons:表示URL比較前先轉為小寫。-->  <!-- path-type:表示使用Apache Ant的匹配模式。-->  <!--access-denied-page:訪問拒絕時轉向的頁面。-->  <!-- access-decision-manager-ref:指定了自定義的訪問策略管理器。-->  <http use-expressions="true" auto-config="true"  access-denied-page="/include/jsp/timeout.jsp">  
<!--login-page:指定登錄頁面。  -->  
<!-- login-processing-url:指定了客戶在登錄頁面中按下 Sign In 按鈕時要訪問的 URL。-->  <!-- authentication-failure-url:指定了身份驗證失敗時跳轉到的頁面。-->  <!-- default-target-url:指定了成功進行身份驗證和授權后默認呈現給用戶的頁面。-->  
<!-- always-use-default-target:指定了是否在身份驗證通過后總是跳轉到default-target-url屬性指定的URL。 
-->  <form-login login-page="/login.jsp" default-target-url='/system/default.jsp'  always-use-default-target="true" authentication-failure-url="/login.jsp?login_error=1" />  
<!--logout-url:指定了用于響應退出系統請求的URL。其默認值為:/j_spring_security_logout。-->  <!-- logout-success-url:退出系統后轉向的URL。-->  <!-- invalidate-session:指定在退出系統時是否要銷毀Session。-->  <logout invalidate-session="true" logout-success-url="/login.jsp"  logout-url="/j_spring_security_logout" />  <!-- 實現免登陸驗證 -->  <remember-me />  <!-- max-sessions:允許用戶帳號登錄的次數。范例限制用戶只能登錄一次。-->  
<!-- 此值表示:用戶第二次登錄時,前一次的登錄信息都被清空。-->  <!--   exception-if-maximum-exceeded:默認為false,-->  
<!-- 當exception-if-maximum-exceeded="true"時系統會拒絕第二次登錄。-->  <session-management invalid-session-url="/login.jsp"  session-fixation-protection="none">  <concurrency-control max-sessions="1"  error-if-maximum-exceeded="false" />  </session-management>  <custom-filter ref="myFilter" before="FILTER_SECURITY_INTERCEPTOR" />  <session-management  session-authentication-strategy-ref="sas" />  </http>  
<beans:bean id="sas"  
class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">  <beans:constructor-arg name="sessionRegistry"  ref="sessionRegistry" />  <beans:property name="maximumSessions" value="1" />  <!-- 防止session攻擊 -->  <beans:property name="alwaysCreateSession" value="true" />  <beans:property name="migrateSessionAttributes" value="false" />  <!--  同一個帳號 同時只能一個人登錄 -->  <beans:property name="exceptionIfMaximumExceeded"  value="false" />  </beans:bean>  <beans:bean id="sessionRegistry"  class="org.springframework.security.core.session.SessionRegistryImpl" />  <!-- 
事件監聽:實現了ApplicationListener監聽接口,包括AuthenticationCredentialsNotFoundEvent 事件,-->  <!-- AuthorizationFailureEvent事件,AuthorizedEvent事件, PublicInvocationEvent事件-->  <beans:bean  class="org.springframework.security.authentication.event.LoggerListener" />  <!-- 自定義資源文件   提示信息 -->  <beans:bean id="messageSource"  
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">  <beans:property name="basenames" value="classpath:message_zh_CN">  
</beans:property>  </beans:bean>  <!-- 配置過濾器 -->  <beans:bean id="myFilter"  class="com.taskmanager.web.security.MySecurityFilter">  <!-- 用戶擁有的權限 -->  <beans:property name="authenticationManager" ref="myAuthenticationManager" />  <!-- 用戶是否擁有所請求資源的權限 -->  <beans:property name="accessDecisionManager" ref="myAccessDecisionManager" />  <!-- 資源與權限對應關系 -->  <beans:property name="securityMetadataSource" ref="mySecurityMetadataSource" />  </beans:bean>  <!-- 實現了UserDetailsService的Bean -->  <authentication-manager alias="myAuthenticationManager">  <authentication-provider user-service-ref="myUserDetailServiceImpl">  <!-- 登入 密碼  采用MD5加密 -->  <password-encoder hash="md5" ref="passwordEncoder">  </password-encoder>  </authentication-provider>  </authentication-manager>  <!-- 驗證用戶請求資源  是否擁有權限 -->  <beans:bean id="myAccessDecisionManager"  class="com.taskmanager.web.security.MyAccessDecisionManager">  </beans:bean>  <!-- 系統運行時加載 系統要攔截的資源   與用戶請求時要過濾的資源 -->  <beans:bean id="mySecurityMetadataSource"  class="com.taskmanager.web.security.MySecurityMetadataSource">  <beans:constructor-arg name="powerService" ref="powerService">  
</beans:constructor-arg>  </beans:bean>  <!-- 獲取用戶登入角色信息 -->  <beans:bean id="myUserDetailServiceImpl"  class="com.taskmanager.web.security.MyUserDetailServiceImpl">  <beans:property name="userService" ref="userService"></beans:property>  </beans:bean>  <!-- 用戶的密碼加密或解密 -->  <beans:bean id="passwordEncoder"  
class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />  
</beans:beans>    

?

security 4.x

<beans:beans  xmlns="http://www.springframework.org/schema/security"  xmlns:beans="http://www.springframework.org/schema/beans"  xmlns:p="http://www.springframework.org/schema/p"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:context="http://www.springframework.org/schema/context"  xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd  http://www.springframework.org/schema/security  http://www.springframework.org/schema/security/spring-security.xsd">  <context:component-scan base-package="com.framework.security"/>  <!--<http pattern="/pm/**" security="none" />-->  <http pattern="/login.jsp" security="none" />  <http pattern="/common/**" security="none" />  <http pattern="/*.ico" security="none" />  <http  use-expressions="false" >  <!-- IS_AUTHENTICATED_ANONYMOUSLY 匿名登錄 -->  <intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" />  <intercept-url pattern="/pm/**/*.jsp" access="ROLE_STATIC" />  <form-login login-page="/login"    authentication-failure-url="/login?error=1" authentication-success-forward-url="/main.to" />  <logout invalidate-session="true" logout-url="/logout"  logout-success-url="/"  />  <http-basic/>  <headers >  <frame-options disabled="true"></frame-options>  </headers>  <csrf token-repository-ref="csrfTokenRepository" />  <session-management session-authentication-error-url="/frame.expired" >  <!-- max-sessions只容許一個賬號登錄,error-if-maximum-exceeded 后面賬號登錄后踢出前一個賬號,expired-url session過期跳轉界面 -->  <concurrency-control max-sessions="1" error-if-maximum-exceeded="false" expired-url="/frame.expired" session-registry-ref="sessionRegistry" />  </session-management>  <expression-handler ref="webexpressionHandler" ></expression-handler>  </http>  <beans:bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl" />  <beans:bean id="userDetailsService" class="com.framework.security.UserDetailsServiceImpl" />  <!--配置web端使用權限控制-->  <beans:bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" />  <authentication-manager >  <authentication-provider ref="authenticationProvider" />  </authentication-manager>  <!-- 自定義userDetailsService, 鹽值加密 -->  <beans:bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">  <beans:property name="hideUserNotFoundExceptions" value="true" />  <beans:property name="userDetailsService" ref="userDetailsService" />  <beans:property name="passwordEncoder" ref="passwordEncoder" />  <beans:property name="saltSource" ref="saltSource" />  </beans:bean>  <!-- Md5加密 -->  <beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />  <!-- 鹽值加密 salt對應數據庫字段-->  <beans:bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource">  <beans:property name="userPropertyToUse" value="salt"/>  </beans:bean>  <beans:bean id="csrfTokenRepository" class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository" />  
</beans:beans>  

?

轉載于:https://www.cnblogs.com/yyxxn/p/8080141.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/281579.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/281579.shtml
英文地址,請注明出處:http://en.pswp.cn/news/281579.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【Redis源碼分析】Redis命令處理生命周期

運營研發團隊 李樂 前言 本文主要講解服務器處理客戶端命令請求的整個流程&#xff0c;包括服務器啟動監聽&#xff0c;接收命令請求并解析&#xff0c;執行命令請求&#xff0c;返回命令回復等&#xff0c;這也是本文的主題“命令處理的生命周期”。 Redis服務器作為典型的事件…

博鰲直擊 | 區塊鏈在互聯網金融中扮演怎樣的角色?

雷鋒網3月24日報道&#xff0c;今日&#xff08;3月24日&#xff09;&#xff0c;第16屆博鰲亞洲論壇2017年年會在海南繼續進行中。據雷鋒網了解&#xff0c;在今日下午的數字貨幣與區塊鏈分論壇上&#xff0c;中國銀行前行長、中國互聯網金融協會區塊鏈工作組組長李禮輝講述了…

GDB調試qemu-kvm

GDB調試qemu-kvm 前面幾篇博文都是記錄一些kvm相關包編譯安裝及使用&#xff0c;但都沒深入去代碼看看。看源碼在配合上相關原理才能更好的理解kvm。但qemu-kvm的代碼量很多&#xff0c;對我來講直接看源碼收獲甚少&#xff0c;所以找了個調試工具——GDB來配合閱讀代碼。接下來…

c語言編譯錯誤 原文,C語言常見錯誤與警告

C語言常見錯誤與警告C語言常見錯誤與警告C語言常見錯誤&#xff1a;1 invalid type argument of ‘->’ (have ‘struct qstr_xid_element’)這種錯誤一般是沒有理解C中“->”與“.”用法的不同&#xff0c;“->”是指向結構體指針獲取結構體的成員變量時所用&#xf…

力爭營收渠道多樣化,Line 向自拍應用 Snow 投資 4500 萬美元

今年&#xff0c;在科技公司 IPO 市場不景氣的情況下&#xff0c;日本通信應用 Line順利進行了 IPO &#xff0c;目前正在尋求多樣化發展。今天, Line 宣布向自拍應用 Snow 投資 4500 萬美元(500 億韓元)。本次交易之后&#xff0c;Line 將獲得 Snow 25% 的股權。 Snow 常被稱為…

用.NET設計一個假裝黑客的屏幕保護程序

本文主要介紹屏幕保護程序的一些相關知識&#xff0c;以及其在安全方面的用途&#xff0c;同時介紹了如何使用 .NET 開發一款屏幕保護程序&#xff0c;并對核心功能做了介紹&#xff0c;案例代碼開源&#xff1a;https://github.com/sangyuxiaowu/HackerScreenSaver背景前幾天在…

【IntelliJ】IntelliJ IDEA常用設置及快捷鍵以及自定義Live templates

IntelliJ IDEA是一款非常優秀的JAVA編輯器&#xff0c;初學都可會對其中的一些做法感到很別扭&#xff0c;剛開始用的時候我也感到很不習慣&#xff0c;在參考了網上一些文章后在這里把我的一些經驗寫出來&#xff0c;希望初學者能快速適應它&#xff0c;不久你就會感覺到編程是…

復習Javascript專題(一):基本概念部分

一、數據類型 基本類型&#xff1a;Null Boolean String Undefined Number(NB SUN)引用類型&#xff1a;Array Function Object類型判斷&#xff1a;typeof 返回結果"undefined"&#xff08;未定義&#xff09; "boolean"(布爾值) "st…

c語言時鐘報告,C語言圖形時鐘課程設計實驗報告

C語言圖形時鐘課程設計實驗報告 目錄1.系統功能要求。2. 數據結構設計及說明。3.程序結構(畫流程圖) 。4.各模塊的功能。5.試驗結果(包括輸入數據和輸出結果) 。6.體會。7.參考文獻。8.附錄&#xff1a;程序清單及源程序。? 系統功能要求&#xff1a;在屏幕上顯示一個圖形時鐘…

微軟發布 2023 財年第一季度財報:營收達 501 億美元,同比增長 11%

北京時間 2022 年 10 月 26 日——微軟發布 2023 財年第一季度財報。財報顯示&#xff0c;截止到 2022 年 9 月 30 日&#xff1a;營收達到 501 億美元&#xff0c;增長 11%&#xff08;按固定匯率計算增長 16%&#xff09;運營收入為 215 億美元&#xff0c;增長 6%&#xff0…

《圖解CSS3:核心技術與案例實戰》——1.3節漸進增強

本節書摘來自華章社區《圖解CSS3&#xff1a;核心技術與案例實戰》一書中的第1章&#xff0c;第1.3節漸進增強&#xff0c;作者 大漠&#xff0c;更多章節內容可以訪問云棲社區“華章社區”公眾號查看 1.3 漸進增強第一次聽到“漸進增強”&#xff08;Progressive Enhancement…

阿里云云主機搭建網站攻略 - 云翼計劃

阿里云服務器&#xff08;云主機&#xff09;搭建網站攻略 - 云翼計劃 提示&#xff1a;此搭建攻略為2017版本&#xff0c;阿里云未跟新前。 最新搭建攻略請前往 Amaya丶夜雨博客 / 最新個人博客 https://www.amayaliu.cn 支持一下哦&#xff0c;謝謝。&#xff08;9.5一…

用c語言遞歸函數做掃雷,【C語言基礎學習---掃雷游戲】(包含普通版+遞歸煉獄版)...

/*******************///以下是源文件game.c內容/*******************/#include"game.h"//初始化棋盤的實現void InitBoard(char board[ROWS][COLS], int rows, int cols, char set){int i 0;int j 0;for (i 0; i < rows; i){for (j 0; j < cols; j){board…

記一次 .NET 某醫療器械 程序崩潰分析

一&#xff1a;背景 1.講故事前段時間有位朋友在微信上找到我&#xff0c;說他的程序偶發性崩潰&#xff0c;讓我幫忙看下怎么回事&#xff0c;上面給的壓力比較大&#xff0c;對于這種偶發性崩潰&#xff0c;比較好的辦法就是利用 AEDebug 在程序崩潰的時候自動抽一管血出來&a…

1251: 字母圖形 [水題]

1251: 字母圖形 [水題] 時間限制: 1 Sec 內存限制: 128 MB提交: 140 解決: 61 統計題目描述 利用字母可以組成一些美麗的圖形&#xff0c;下面給出了一個例子&#xff1a; ABCDEFG BABCDEF CBABCDE DCBABCD EDCBABC 這是一個5行7列的圖形&#xff0c;請找出這個圖形的規律&…

c語言 三角形三邊abc,C語言代碼輸入abc三個數,求一這3個數為邊長的三角形面積...

2011-01-04 回答#include #include #include #include #include int main(){float a 0.0;float b 0.0;float c 0.0;float s 0.0;double area 0.0;while(true){printf("input your date(a,b,c):");scanf("%f%f%f",&a,&b,&c);if(!isdigit((…

shell腳本中向hive動態分區插入數據

在hive上建表與普通分區表創建方法一樣&#xff1b; 1 CREATE TABLE dwa_m_user_association_circle(2 device_number string, 3 oppo_number string, 4 prov_id_oppo string, 5 area_id_oppo string, 6 dealer_oppo string, 7 short_call_nums bigint, 8 long3…

WPF效果第二百零二篇之TreeView帶連接線

前面文章中分享了TreeView支持多選;然而在項目上使用時,領導覺得不滿意:體現不了真正的從屬關系;既然領導都發話了;那就開整就行了;今天就再來個帶有連接線的TreeView效果:1、來看看TreeViewItem的Template:2、展開和收縮動畫:3、參考資料https://www.codeproject.com/tips/673…

ObjectTive C語言語法,[譯]理解 Objective-C 運行時(下篇)

本文來自網易云社區作者&#xff1a;宋申易所以到底 objc_msgSend 發生了什么&#xff1f;很多事情。看一下這段代碼&#xff1a;[self printMessageWithString:"Hello World!"];這實際上被編譯器翻譯成&#xff1a;objc_msgSend(self, selector(printMessageWithStr…

菜鳥學習MVC實錄:弄清項目各類庫的作用和用法

MVC模式即&#xff1a;模型&#xff08;Model&#xff09;-視圖&#xff08;View&#xff09;-控制器&#xff08;Controller&#xff09; Model &#xff08;模型&#xff09;&#xff1a;是應用程序中用于處理應用程序數據邏輯的部分。通常模型對象負責數據庫中存取數據View…