有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpringMVC安全性甚至在第一步都不起作用

我已经创建了一个SpringMVC项目,它有两个控制器、一些DAO、DTO和jsp文件。 我删除了控制器上的@RequestMapping(value = "/login", method = RequestMethod.GET) ,以检查spring安全性是否正常工作

但是,它根本不起作用,总是显示404错误。 如果错误代码是403,那么我可以修复我的上下文安全设置。xml。 但我不知道我错过了什么

不管怎样,我只是设定了pom。xml来像这样注入依赖关系。 (我的spring框架是3.1.1,所以spring安全版本也是3.1.1)

        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
    
        <!-- Spring-Security -->
        <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
         
        <!-- Spring-Security-Taglibs -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

我创建了上下文安全性。appservlet文件夹中的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"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
                                 http://www.springframework.org/schema/beans/spring-beans.xsd
                                 http://www.springframework.org/schema/security
                                 http://www.springframework.org/schema/security/spring-security.xsd">
        
        <http auto-config="true" use-expressions="true">
            <intercept-url pattern="/**" access="ROLE_USER" />
  
        </http>
        
        <authentication-manager>
            <authentication-provider>
                <user-service>
                    <user name="user" password="1234" authorities="ROLE_USER"/>
                    <user name="guest" password="guest" authorities="ROLE_GUEST"/>
                </user-service>
            </authentication-provider>
        </authentication-manager>
    
</beans:beans>

我在网页上添加了一些代码。xml

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml
                    /WEB-INF/spring/context-security.xml
        </param-value>
    </context-param>
    <!-- Spring Security Filter -->
    <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>

我查了一些例子。他们可以看到spring安全登录页面,而不需要额外的类,该类具有configuaraion注释或EnableWebsecurity。但我的已经三个小时没工作了

另外,我生成了一个新的mvc项目并复制了三个XML代码。只有homeController和home。jsp。因此,我可以从项目中看到完全相同的错误。 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

我删除了<intercept-url pattern="/**" access="ROLE_USER" />=>;失败 ==>;失败 ==>;失败 ==>;holo是我的项目名称。安威失败了

但它根本不起作用。 这些XML有错误吗?还是根本不工作


共 (0) 个答案