×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: digas
Added: Sep 26, 2014 3:14 PM
Views: 47
Tags: spring
  1. <dependency>
  2.        <groupId>org.springframework.security</groupId>
  3.        <artifactId>spring-security-web</artifactId>
  4.        <version>${org.springframework.version}</version>
  5.        <type>jar</type>
  6.        <scope>compile</scope>
  7. </dependency>
  8. <dependency>
  9.         <groupId>org.springframework.security</groupId>
  10.         <artifactId>spring-security-config</artifactId>
  11.         <version>${org.springframework.version}</version>
  12.         <type>jar</type>
  13.         <scope>compile</scope>
  14. </dependency>
  15.  
  16.  
  17. web.xml :
  18.  
  19. <filter>
  20.        <filter-name>springSecurityFilterChain</filter-name>
  21.        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  22. </filter>
  23. <filter-mapping>
  24.        <filter-name>springSecurityFilterChain</filter-name>
  25.        <url-pattern>/*</url-pattern>
  26. </filter-mapping>
  27.  
  28. <listener>
  29.        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  30. </listener>
  31.  
  32. <context-param>
  33.        <param-name>contextConfigLocation</param-name>
  34.        <param-value>classpath:security-context.xml</param-value>
  35. </context-param>
  36.  
  37.  
  38. spring context :
  39.  
  40. <?xml version="1.0" encoding="UTF-8"?>
  41. <beans xmlns="http://www.springframework.org/schema/beans"
  42.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  43.        xmlns:security="http://www.springframework.org/schema/security"
  44.        xmlns:context="http://www.springframework.org/schema/context"
  45.        xsi:schemaLocation="
  46.            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  47.            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
  48.  
  49. http://www.springframework.org/schema/security
  50.  
  51.            http://www.springframework.org/schema/security/spring-security-3.0.xsd">
  52.  
  53. <security:http auto-config='true'>
  54.      <security:intercept-url pattern="/logs/**" access="ROLE_USER, ROLE_ADMIN"/>
  55.      <security:intercept-url pattern="/logviewer.html" access="ROLE_USER, ROLE_ADMIN"/>
  56.      <security:intercept-url pattern="/qr/**" access="ROLE_USER, ROLE_ADMIN"/>
  57.      <!-- security:intercept-url pattern="/sms/**" access="ROLE_USER, ROLE_ADMIN"/-->
  58.      <security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
  59.      <security:http-basic />
  60. </security:http>
  61.  
  62. <security:authentication-manager>
  63.      <security:authentication-provider>
  64.          <security:user-service>
  65.               <security:user name="username1" password="password1" authorities="ROLE_USER" />
  66.               <security:user name="username2" password="password2" authorities="ROLE_USER, ROLE_ADMIN" />
  67.               </security:user-service>
  68.      </security:authentication-provider>
  69. </security:authentication-manager>
  70. </beans>