applicationContext-security.xml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. - Application context containing authentication, channel
  4. - security and web URI beans.
  5. -
  6. - Only used by "filter" artifact.
  7. -
  8. -->
  9. <b:beans xmlns="http://www.springframework.org/schema/security"
  10. xmlns:b="http://www.springframework.org/schema/beans"
  11. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  12. xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
  13. http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd">
  14. <global-method-security pre-post-annotations="enabled">
  15. <expression-handler ref="expressionHandler"/>
  16. </global-method-security>
  17. <http realm="Contacts Realm">
  18. <intercept-url pattern="/" access="permitAll"/>
  19. <intercept-url pattern="/index.jsp" access="permitAll"/>
  20. <intercept-url pattern="/hello.htm" access="permitAll"/>
  21. <intercept-url pattern="/login.jsp*" access="permitAll"/>
  22. <intercept-url pattern="/switchuser.jsp" access="hasRole('SUPERVISOR')"/>
  23. <intercept-url pattern="/login/impersonate" access="hasRole('SUPERVISOR')"/>
  24. <intercept-url pattern="/**" access="hasRole('USER')"/>
  25. <form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1"/>
  26. <http-basic/>
  27. <logout logout-success-url="/index.jsp"/>
  28. <remember-me />
  29. <headers/>
  30. <csrf/>
  31. <custom-filter ref="switchUserProcessingFilter" position="SWITCH_USER_FILTER"/>
  32. </http>
  33. <b:bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
  34. <authentication-manager>
  35. <authentication-provider>
  36. <password-encoder ref="encoder"/>
  37. <jdbc-user-service data-source-ref="dataSource"/>
  38. </authentication-provider>
  39. </authentication-manager>
  40. <!-- Automatically receives AuthenticationEvent messages -->
  41. <b:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
  42. <!-- Filter used to switch the user context. Note: the switch and exit url must be secured
  43. based on the role granted the ability to 'switch' to another user -->
  44. <!-- In this example 'rod' has ROLE_SUPERVISOR that can switch to regular ROLE_USER(s) -->
  45. <b:bean id="switchUserProcessingFilter" class="org.springframework.security.web.authentication.switchuser.SwitchUserFilter" autowire="byType">
  46. <b:property name="targetUrl" value="/secure/index.htm"/>
  47. </b:bean>
  48. <b:bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
  49. <b:property name="permissionEvaluator" ref="permissionEvaluator"/>
  50. <b:property name="permissionCacheOptimizer">
  51. <b:bean class="org.springframework.security.acls.AclPermissionCacheOptimizer">
  52. <b:constructor-arg ref="aclService"/>
  53. </b:bean>
  54. </b:property>
  55. </b:bean>
  56. <b:bean id="permissionEvaluator" class="org.springframework.security.acls.AclPermissionEvaluator">
  57. <b:constructor-arg ref="aclService"/>
  58. </b:bean>
  59. </b:beans>