xml – 为什么’permitAll()’不起作用?

前端之家收集整理的这篇文章主要介绍了xml – 为什么’permitAll()’不起作用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
提到值得:我正在关注 Securing GWT apps with Spring Security的教程.

我不懂.我似乎无法获得permitAll,因为我需要它.

这是我目前的配置:

  1. <http auto-config="true">
  2. <intercept-url pattern="/**" access="permitAll" />
  3. <form-login
  4. login-page="/login"
  5. default-target-url="/welcome"
  6. authentication-failure-url="/login?error"
  7. username-parameter="username"
  8. password-parameter="password" />
  9. </http>

如果我在// localhost:8080上访问我的网站,则该网站因为请求而未完全加载

  1. //localhost:8080/app/xsrf

因某种原因被禁止403.如果我理解正确的话,我配置Spring Security的方式应该不是问题.

如果我简单地添加,我就无法工作

  1. <intercept-url pattern="/**" access="permitAll" />

到< http ..>什么工作是添加这个:

  1. <http pattern="/app/xsrf" security="none"/>

我想了解为什么,因为这不是我要配置Spring Security的方式..添加应该允许的每个URL.

我面临的另一个问题是,无论出于何种原因(可能相同),我都无法访问// localhost:8080 / login.这意味着如果我将登录信息提交到/ login,我将收到403 Forbidden.

现在,人们会认为添加< http pattern =“/ login”security =“none”/>会有所帮助,但没有.如果我将其添加到我的配置中,我将在此特定URL上找到404 Not Found.

这开始让我疯了,因为我被困在这里这么多天我不敢告诉你.您的帮助将得到赞赏和奖励.

整个applicationContext-service.xml

  1. <beans:beans xmlns="http://www.springframework.org/schema/security"
  2. xmlns:beans="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:security="http://www.springframework.org/schema/security"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
  7. http://www.springframework.org/schema/security
  8. http://www.springframework.org/schema/security/spring-security-4.0.xsd">
  9.  
  10. <!-- Imports -->
  11. <beans:import resource="applicationContext-jooq.xml"/>
  12.  
  13. <!-- /////////////////////////////////////////////////////////////// -->
  14. <!-- // BEGIN Spring Security -->
  15.  
  16. <http pattern="/app/xsrf" security="none"/>
  17. <!-- <http pattern="/login" security="none"/> -->
  18.  
  19. <http auto-config="true">
  20. <intercept-url pattern="/**" access="permitAll" />
  21.  
  22. <form-login
  23. login-page="/login"
  24. default-target-url="/welcome"
  25. authentication-failure-url="/login?error"
  26. username-parameter="username"
  27. password-parameter="password" />
  28. </http>
  29.  
  30. <beans:bean id="authenticationListener"
  31. class="com.mz.server.web.auth.CustomAuthenticationListener"/>
  32.  
  33. <beans:bean id="authenticationProvider"
  34. class="com.mz.server.web.auth.CustomAuthenticationProvider"/>
  35.  
  36. <beans:bean id="userDetailsService"
  37. class="com.mz.server.web.service.CustomUserDetailsService"/>
  38.  
  39. <authentication-manager alias="authenticationManager">
  40. <authentication-provider ref="authenticationProvider"/>
  41. </authentication-manager>
  42.  
  43. <!-- // END Spring Security -->
  44. <!-- /////////////////////////////////////////////////////////////// -->
  45. <!-- // BEGIN Services -->
  46.  
  47. <beans:bean id="loginService" class="com.mz.server.web.service.LoginService">
  48. <beans:constructor-arg ref="dslContext" />
  49. </beans:bean>
  50.  
  51. <!-- // END Services -->
  52.  
  53. </beans:beans>

编辑:

减少了applicationContext-service.xml

  1. <beans:beans xmlns="http://www.springframework.org/schema/security"
  2. xmlns:beans="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.  
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
  7. http://www.springframework.org/schema/security
  8. http://www.springframework.org/schema/security/spring-security-4.0.xsd">
  9.  
  10. <!-- Imports -->
  11. <beans:import resource="applicationContext-jooq.xml"/>
  12.  
  13. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  14. <!-- // BEGIN Spring Security -->
  15.  
  16. <global-method-security pre-post-annotations="enabled"/>
  17.  
  18. <http auto-config="true">
  19. <intercept-url pattern="/**" access="permitAll" />
  20. </http>
  21.  
  22. <!-- // END Spring Security-->
  23.  
  24. </beans:beans>

这是web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  5. version="3.0">
  6.  
  7. <display-name>GWT Application | mz</display-name>
  8.  
  9. <welcome-file-list> <!-- Default page to serve -->
  10. <welcome-file>index.html</welcome-file>
  11. </welcome-file-list>
  12.  
  13. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  14. <!-- // BEGIN Filters -->
  15.  
  16. <!-- Spring Security -->
  17.  
  18. <filter>
  19. <filter-name>springSecurityFilterChain</filter-name>
  20. <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  21. </filter>
  22.  
  23. <filter-mapping>
  24. <filter-name>springSecurityFilterChain</filter-name>
  25. <url-pattern>/*</url-pattern>
  26. </filter-mapping>
  27.  
  28. <!-- // END FILTERS -->
  29. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  30. <!-- // BEGIN Listeners -->
  31.  
  32. <listener>
  33. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  34. </listener>
  35.  
  36. <listener>
  37. <listener-class>com.mz.server.web.ServerConfig</listener-class>
  38. </listener>
  39.  
  40. <!-- // END Listeners -->
  41. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  42. <!-- // BEGIN Servlets -->
  43.  
  44. <servlet>
  45. <servlet-name>login</servlet-name>
  46. <servlet-class>com.mz.server.web.servlet.LoginServletImpl</servlet-class>
  47. </servlet>
  48. <servlet-mapping>
  49. <servlet-name>login</servlet-name>
  50. <url-pattern>/app/login</url-pattern>
  51. </servlet-mapping>
  52.  
  53. <servlet>
  54. <servlet-name>xsrf</servlet-name>
  55. <servlet-class>com.google.gwt.user.server.rpc.XsrfTokenServiceServlet</servlet-class>
  56. </servlet>
  57. <servlet-mapping>
  58. <servlet-name>xsrf</servlet-name>
  59. <url-pattern>/app/xsrf</url-pattern>
  60. </servlet-mapping>
  61.  
  62. <servlet> <!-- Dispatcher Servlet for REST API for Mobile Devices -->
  63. <servlet-name>mobile-restapi</servlet-name>
  64. <servlet-class>
  65. org.springframework.web.servlet.DispatcherServlet
  66. </servlet-class>
  67. <load-on-startup>1</load-on-startup>
  68. </servlet>
  69. <servlet-mapping>
  70. <servlet-name>mobile-restapi</servlet-name>
  71. <url-pattern>/app/restapi/*</url-pattern>
  72. </servlet-mapping>
  73.  
  74. <!-- // END Servlets -->
  75. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  76. <!-- // BEGIN Context Parameter -->
  77.  
  78. <context-param>
  79. <param-name>
  80. gwt.xsrf.session_cookie_name
  81. </param-name>
  82. <param-value>
  83. mzsid
  84. </param-value>
  85. </context-param>
  86.  
  87. <context-param>
  88. <param-name>
  89. contextConfigLocation
  90. </param-name>
  91. <param-value>
  92. classpath:/**/spring-config.xml
  93. classpath*:applicationContext-service.xml
  94. </param-value>
  95. </context-param>
  96.  
  97. <!-- // END Context Parameter -->
  98. <!-- //////////////////////////////////////////////////////////////////////////////// -->
  99.  
  100. </web-app>
看来错误发生在web.xml中.而不是< url-pattern> / *< / url-pattern> (正如我所遵循的教程中所述)它应该是/ **:
  1. <filter-mapping>
  2. <filter-name>springSecurityFilterChain</filter-name>
  3. <!-- It appears that this should say '/**' and not '/*' as stated in many
  4. tutorials
  5. (e.g. http://websystique.com/spring-security/spring-security-4-hello-world-annotation-xml-example/). -->
  6. <url-pattern>/**</url-pattern>
  7. </filter-mapping>

有趣的是,我现在得到以下“信息”:

  1. INFO: SuspicIoUs url pattern: "/**" in context [] - see section SRV.11.2 of the Servlet specification

我只能说,这开始变得个人化了……

猜你在找的XML相关文章