简体   繁体   English

Spring Security无法正常运行的登录页面URL(http:// localhost:8080 / site / j_spring_security_check)转到PAGE NOT FOUND

[英]Login page with Spring Security not working URL(http://localhost:8080/site/j_spring_security_check) goes to PAGE NOT FOUND

I am new to hippo and working on hippo cms site. 我是河马的新手,正在河马cms网站上工作。 I am working on creating a login page with spring security. 我正在使用Spring Security创建一个登录页面。 For this I created the following files and did the configuration for spring and spring security. 为此,我创建了以下文件并对弹簧和弹簧安全性进行了配置。

Here is my Login.jsp. 这是我的Login.jsp。

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Login Page</title>
<style>
.errorblock {
    color: #ff0000;
    background-color: #ffEEEE;
    border: 3px solid #ff0000;
    padding: 8px;
    margin: 16px;
}
</style>
</head>
<body onload='document.f.j_username.focus();'>
    <h3>Login with Username and Password (Custom Page)</h3>

    <c:if test="${not empty error}">
        <div class="errorblock">
            Your login attempt was not successful, try again.<br /> Caused :
            ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
        </div>
    </c:if>

    <form name='f' action="/j_spring_security_check"
        method='POST'>

        <table>
            <tr>
                <td>User:</td>
                <td><input type='text' name='j_username' value=''>
                </td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type='password' name='j_password' />
                </td>
            </tr>
            <tr>
                <td colspan='2'><input name="submit" type="submit"
                    value="submit" />
                </td>
            </tr>
            <tr>
                <td colspan='2'><input name="reset" type="reset" />
                </td>
            </tr>
        </table>

    </form>
</body>
</html>

The configuration files. 配置文件。

1) Web.xml configuration 1)Web.xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
        xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

        <display-name>Spring MVC Application</display-name>

        <!-- Spring MVC -->
        <servlet>
            <servlet-name>mvc-dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>mvc-dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>

        <listener>
            <listener class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/mvc-dispatcher-servlet.xml,
                /WEB-INF/spring-database.xml,
                /WEB-INF/spring-security.xml
            </param-value>
        </context-param>

        <!-- Spring Security -->
        <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>

    </web-app>

2) mvc-dispatcher-servlet.xml 2)mvc-dispatcher-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        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-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

        <context:component-scan base-package="com.example.common.controller" />

        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix">
                <value>/WEB-INF/pages/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>

        <bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basenames">
                <list>
                    <value>mymessages</value>
                </list>
            </property>
        </bean>

    </beans>

3) spring-database.xml 3)spring-database.xml

    <beans xmlns="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-3.0.xsd">

        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="url" value="jdbc:mysql://localhost:3306/vnp_db" />
            <property name="username" value="root" />
            <property name="password" value="admin" />
        </bean>

    </beans>

4) spring-security.xml 4)spring-security.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-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd">

        <http auto-config="true">
            <intercept-url pattern="/welcome*" access="ROLE_USER" />
            <form-login login-page="/login" default-target-url="/welcome"
                authentication-failure-url="/loginfailed"  login-processing-url="/j_spring_security_check"/>
            <logout logout-success-url="/logout" />
        </http>

        <authentication-manager>
            <authentication-provider>
              <jdbc-user-service data-source-ref="dataSource"

                    users-by-username-query="
                        select email,password, enabled
                        from users where email=?"

                    authorities-by-username-query="
                        select u.email, ur.authority from users u, authorities ur
                        where u.email = ur.email and u.email =?  "
                />
            </authentication-provider>
        </authentication-manager>

    </beans:beans>

And the controller file 和控制器文件

This module also contains registration part using spring thar part is working fine . 该模块还包含注册部分,使用弹簧部分工作正常。 On the login page I fill the correct username and password and clicks "Login" button. 在登录页面上,输入正确的用户名和密码,然后单击“登录”按钮。 The url goes to " http://testcebs.com:8080/site/j_spring_security_check " and redirects to PAGE NOT FOUND instead of success and fail.No authentication process initatied after clicking on "Login" button. 该URL转到“ http://testcebs.com:8080/site/j_spring_security_check ”,并重定向到PAGE NOT FOUND而不是成功和失败。单击“ Login”(登录)按钮后,没有启动身份验证过程。 I am not able to understand why it is not working. 我不明白为什么它不起作用。 However the same code and configuration is working fine in eclipse as a spring application. 但是,相同的代码和配置在Eclipse中作为spring应用程序也可以正常工作。

You've been answered here and here , please don't cross-post 您已经在这里这里得到答复,请不要交叉张贴

The answers: 答案:

if the j_spring_security_check URL is not part of the HST driven then make sure you add it to you hst:hosts exclusions, because otherwise the HST thinks it needs to handle the URL. 如果j_spring_security_check URL不是HST驱动的一部分,请确保将其添加到hst:hosts排除项中,否则HST认为它需要处理该URL。

and

You need to insert the​ SpringSecurityValve into your existing pipelines​ as well​. 您还需要将SpringSecurityValve插入现有管道中。 ​you can use the hippo-spring-sec​ plugin for a cleaner spring security integration; 您可以使用hippo-spring-sec插件进行更清晰的Spring安全集成; http://hst-springsec.forge.onehippo.org/ http://hst-springsec.forge.onehippo.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring安全性:找不到j_spring_security_check页面 - Spring security: j_spring_security_check page not found Spring Custom AuthenticationProvider从未被调用-http:// localhost:8080 / igloo / j_spring_security_check上的404错误 - Spring Custom AuthenticationProvider never invoked - 404 error on http://localhost:8080/igloo/j_spring_security_check j_spring_security_check HTTP状态404(自定义登录) - j_spring_security_check HTTP Status 404 (Custom Login) Spring Security /找不到j_spring_security_check 404 - Spring Security /j_spring_security_check Not Found 404 Spring Security-j_spring_security_check-HTTP状态403 - Spring Security - j_spring_security_check - HTTP status 403 店面登录页面重定向到具有空值的路径,而不是j_spring_security_check - Storefront login page redirects to path with null value instead of j_spring_security_check Spring 3 安全 j_spring_security_check - Spring 3 Security j_spring_security_check Spring security 4自定义登录j_spring_security_check返回http 302 - Spring security 4 custom login j_spring_security_check return http 302 Spring Security Login Error:HTTP Status 404 - / j_spring_security_check - Spring Security Login Error : HTTP Status 404 - /j_spring_security_check 在没有http auto config的情况下直接配置spring security后找不到“j_spring_security_check” - “j_spring_security_check” not found after configuring spring security directly without http auto config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM