gpt4 book ai didi

java - Spring Security URL 模式不起作用

转载 作者:行者123 更新时间:2023-12-02 02:20:49 27 4
gpt4 key购买 nike

这是我的 web.xml

<filter>
<display-name>springSecurityFilterChain</display-name>
<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>

这是我的 security-context.xml

     <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user authorities="admin" name="logan"
password="user" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<security:http use-expressions="true">
<security:intercept-url pattern="/" access="permitAll" />
<security:intercept-url pattern="/admin/*" access="denyAll" />
<security:form-login />
</security:http>
</beans>

我不知道为什么我仍然能够访问/admin 之后的所有内容,例如/admin/home 将我重定向到仪表板而不是将我重定向到登录页面,这是如何工作的?我对 Spring 还很陌生。

最佳答案

您是否将该文件包含在 web.xml 中,例如:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>

您还可以尝试在 url 模式中添加 /*:

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

关于java - Spring Security URL 模式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48529738/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com