欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Spring Security 簡單配置

 更新時間:2017年05月25日 15:23:32   作者:憨厚的老菜鳥  
本篇文章主要介紹了詳解Spring Security 簡單配置,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

開發(fā)環(huán)境

  1. maven
  2. idea
  3. jdk 1.8
  4. tomcat 8

配置spring mvc + spring security

pom.xml

 <properties>
  <spring.version>4.3.8.RELEASE</spring.version>
  <spring-sercurity.version>4.2.2.RELEASE</spring-sercurity.version>
 </properties>


 <dependencies>
  <!-- Spring 4 dependencies -->

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>${spring.version}</version>

  </dependency>

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>${spring.version}</version>
  </dependency>

  <!-- Spring Security -->
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-core</artifactId>
   <version>${spring-sercurity.version}</version>
  </dependency>

  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-web</artifactId>
   <version>${spring-sercurity.version}</version>
  </dependency>

  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-config</artifactId>
   <version>${spring-sercurity.version}</version>
  </dependency>
 </dependencies>

spring mvc 使用的是4.3.8版本,spring security 使用的是4.2.2版本。

spring-mvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  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-4.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-4.0.xsd">

 <context:component-scan base-package="com.controller" />

 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix">
   <value>/WEB-INF/pages/</value>
  </property>
  <property name="suffix">
   <value>.jsp</value>
  </property>
 </bean>
</beans>

spring-security.xml

<?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: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">

 <http auto-config="true" >
  <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
 </http>

 <authentication-manager>
  <authentication-provider>
   <user-service>
    <user name="admin" password="123456" authorities="ROLE_USER"/>
   </user-service>
  </authentication-provider>
 </authentication-manager>
</beans: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_3_0.xsd"
   id="WebApp_ID" version="3.0">
 <display-name>Archetype Created Web Application</display-name>

 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   classpath:spring-mvc-servlet.xml,
   classpath:spring-security.xml
  </param-value>
 </context-param>

 <!-- spring mvc -->
 <servlet>
  <servlet-name>spring-mvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath*:spring-mvc-servlet.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>spring-mvc</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>

 <!-- spring security -->
 <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.jsp</welcome-file>
 </welcome-file-list>
</web-app>

測試

spring會攔截所有請求,如果沒有登錄,則系統(tǒng)會跳轉(zhuǎn)到spring security默認的登錄頁面。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • java中實體類實現(xiàn)時間日期自動轉(zhuǎn)換方式

    java中實體類實現(xiàn)時間日期自動轉(zhuǎn)換方式

    這篇文章主要介紹了java中實體類實現(xiàn)時間日期自動轉(zhuǎn)換方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • PowerJob的ProcessorLoader工作流程源碼解讀

    PowerJob的ProcessorLoader工作流程源碼解讀

    這篇文章主要為大家介紹了PowerJob的ProcessorLoader工作流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-12-12
  • idea導(dǎo)入項目爆紅問題記錄以及解決

    idea導(dǎo)入項目爆紅問題記錄以及解決

    這篇文章主要介紹了idea導(dǎo)入項目爆紅問題記錄以及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Spring Security架構(gòu)以及源碼詳析

    Spring Security架構(gòu)以及源碼詳析

    這篇文章主要給大家介紹了關(guān)于Spring Security架構(gòu)以及源碼的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06
  • String與Blob互轉(zhuǎn)和file文件與Blob互轉(zhuǎn)方式

    String與Blob互轉(zhuǎn)和file文件與Blob互轉(zhuǎn)方式

    這篇文章主要介紹了String與Blob互轉(zhuǎn)和file文件與Blob互轉(zhuǎn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Java語言class類用法及泛化(詳解)

    Java語言class類用法及泛化(詳解)

    這篇文章主要介紹了Java語言class類用法及泛化(詳解),大家都知道Java程序在運行過程中,對所有的對象今夕類型標識,也就是RTTI。這項信息記錄了每個對象所屬的類,需要的朋友可以參考下
    2015-07-07
  • Resttemplate中設(shè)置超時時長方式

    Resttemplate中設(shè)置超時時長方式

    這篇文章主要介紹了Resttemplate中設(shè)置超時時長方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java微信公眾平臺開發(fā)(12) 微信用戶信息的獲取

    Java微信公眾平臺開發(fā)(12) 微信用戶信息的獲取

    這篇文章主要為大家詳細介紹了Java微信公眾平臺開發(fā)第十二步,微信用戶信息的獲取,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Java中Minio的基本使用詳解

    Java中Minio的基本使用詳解

    這篇文章主要介紹了Java中Minio的基本使用詳解,MinIO 是一個基于Apache License v2.0開源協(xié)議的對象存儲服務(wù),它兼容亞馬遜S3云存儲服務(wù)接口,非常適合于存儲大容量非結(jié)構(gòu)化的數(shù)據(jù),例如圖片、視頻、日志文件、備份數(shù)據(jù)和容器/虛擬機鏡像等,需要的朋友可以參考下
    2024-01-01
  • MyBatis/mybatis-plus項目打印SQL的方法實現(xiàn)

    MyBatis/mybatis-plus項目打印SQL的方法實現(xiàn)

    SpringBoot項目中,經(jīng)常需要打印SQL語句及其參數(shù),本文就來介紹一下MyBatis/mybatis-plus項目打印SQL的方法實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2024-07-07

最新評論