目錄
1、web.xml 檔案配置
2、spring-security 普通 為使用自己建立的認證類
1、web.xml 檔案配置
!-- 配置SpringSecurity的攔截器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-security.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2、spring-security 普通 為使用自己建立的認證類
<?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">
<!-- 配置放行的頁面
security="none" 不被攔截:放行的!
-->
<http pattern="/login.html" security="none"></http>
<http pattern="/css/**" security="none"></http>
<http pattern="/js/**" security="none"></http>
<http pattern="/img/**" security="none"></http>
<http pattern="/plugins/**" security="none"></http>
<!-- 配置攔截的URL
配置攔截的請求 http
intercept-url : 攔截的URL
pattern: 設定攔截的路徑
/* : 攔截URL的一級 /login.html 不能跨級攔截 比如:/brand/findAll.do
/** :
use-expressions 是支援Spring的Spel表達式,預設是true開啟的,關閉!
-->
<http use-expressions="false">
<!-- 設定哪個權限是來通路的 -->
<intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER" />
<!-- 開啟登入頁面
login-page : 指定自己的登入頁面
default-target-url : 登入完成後,跳轉到頁面
authentication-failure-url : 如果登入失敗跳轉的頁面
always-use-default-target : 驗證通過後都要到預設指定的頁面default-target-url上
-->
<form-login login-page="/login.html" default-target-url="/admin/index.html"
authentication-failure-url="/login.html" always-use-default-target="true"
/>
<!-- 配置CSRF的惡意通路 -->
<csrf disabled="true"/>
<!-- 配置放行前段架構的聲明 policy : 規則 ; SAMEORIGIN : 放行前段頁面架構-->
<headers>
<frame-options policy="SAMEORIGIN"/>
</headers>
</http>
<!-- 配置認證類(認證管理)
authorities="" : 設定此使用者是哪個權限的 "ROLE_"
-->
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" authorities="ROLE_ADMIN" password="123456"/>
<user name="shuai" authorities="ROLE_USER" password="123456"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>