spring security 應用

 今天領導要了我們前端組從十月到年末的開發計劃,發現年底的項目終於迴歸到了javascript做前端了,到時好好練練手。另外,發現以後可能會經常做權限管理,所以現在正好有點時間打算把SpringSecurity資料認真整理下,今天是入門級的,希望以後會越來越來越深入。

  java項目首先要提的就是jar包了,Springsecurity的jar下載地址:http://static.springsource.org/spring-security/site/downloads.html。不過我的項目裏的jar包比較舊點了,是從以前項目抽取出來的,我的工程結構圖如下:

第一個實例:

第一個例子是最基本,最簡單的,我第一次接觸springsecurity時候覺得這個技術真驚豔,不過現在感覺也就那麼回事了。

我首先編寫的是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"
xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation= "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id= "WebApp_ID"  version= "2.5" >
   <display-name>SpringSecurityPrj</display-name>
   <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>
         classpath:applicationContext*.xml
     </param-value>
   </context-param>
   <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>
   <listener>
     <listener- class >org.springframework.web.context.ContextLoaderListener</listener- class >
   </listener>
   <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
</web-app>

接下來編寫的是applicationContext-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:xsi= "http://www.w3.org/2001/XMLSchema-instance"
    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
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.w3.org/2001/XMLSchema-instance"
相關文章
相關標籤/搜索