當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringSecurity快速入门
生活随笔
收集整理的這篇文章主要介紹了
SpringSecurity快速入门
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Spring Security介紹
Spring Security 的前身是 Acegi Security ,是 Spring 項目組中用來提供安全認證服務的框架。
(https://projects.spring.io/spring-security/) Spring Security 為基于J2EE企業應用軟件提供了全面安全服務。特別是使用領先的J2EE解決方案-Spring框架開發的企業軟件項目。人們使用Spring Security有很多種原因,不過通常吸引他們的是在J2EE Servlet規范或EJB規范中找不到典型企業應用場景的解決方案。 特別要指出的是他們不能再WAR 或 EAR 級別進行移植。這樣,如果你更換服務器環境,就要,在新的目標環境進行大量的工作,對你的應用系統進行重新配 置安全。使用Spring Security 解決了這些問題,也為你提供很多有用的,完全可以指定的其他安全特性。 安全包括兩個主要操作。
“認證”,是為用戶建立一個他所聲明的主體。主題一般式指用戶,設備或可以在你系 統中執行動作的其他系統。(即用戶密碼登錄)
“授權”指的是一個用戶能否在你的應用中執行某個操作,在到達授權判斷之前,身份的主題已經由 身份驗證過程建立了。
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" authentication-success-forward-url="/success.html"/><!-- 關閉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>web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"version="2.5"><display-name>SpringSecurity314</display-name><context-param><param-name>contextConfigLocation</param-name><param-value>classpath: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><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list> </web-app>登錄,成功,失敗頁面:
跳轉到成功頁面。
總結
以上是生活随笔為你收集整理的SpringSecurity快速入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring注解@service(ser
- 下一篇: 怎么去除CSDN上的广告?