0

所以我正在尝试使用休眠创建弹簧身份验证。我可能已经检查了互联网上所有关于这个问题的教程,但我似乎遗漏了一些东西,因为当我按下表单中的提交按钮时,没有执行身份验证并且我没有被重定向我应该被重定向到哪里......

这是我的安全配置:

<bean id='userDetailsService' class='fi.social.web.services.UserDetailsServiceImpl'></bean>

 <security:http auto-config="true">
    <security:form-login login-page="/" default-target-url="/welcome"
        authentication-failure-url="/loginfailed" />
 </security:http>

 <bean id='daoAuthenticationProvider' class='org.springframework.security.authentication.dao.DaoAuthenticationProvider'>
    <property name='userDetailsService' ref='userDetailsService' />
 </bean>

 <bean id='authenticationManager' class='org.springframework.security.authentication.ProviderManager'>
    <property name='providers'>
        <list>
            <ref local='daoAuthenticationProvider' />
        </list>
    </property>
 </bean>

<security:authentication-manager>
    <security:authentication-provider user-service-ref='userDetailsService'>
        <security:password-encoder hash='plaintext' />
    </security:authentication-provider>
</security:authentication-manager>

和我的 JSP 页面:

<form method="post" name="loginForm" action="<c:url value='j_spring_security_check' />">
    <table style="position:absolute; right:15px;">
        <tr>
            <td><input type="text" name="j_username" placeholder="<fmt:message key="user.usernameOrEmail"/>"/></td>
            <td><input type="password" name="j_password" placeholder="<fmt:message key="user.password"/>"/></td>
        </tr>
        <tr>
            <td colspan="2" style="color: white; text-align:right">
                <input type="checkbox" name="remember" /><fmt:message key="user.remember" />
                <input type="submit" name="submit" style="margin:0px 0px 0px 15px; display:inline;" value="<fmt:message key="user.logIn"/>" />
            </td>
        </tr>
    </table>
</form>

尽管如此,由于某种原因,当我提交我去的表格时

http://127.0.0.1:8080/social/j_spring_security_check;jsessionid=C00D6F0CA27E3B359A9B04B8FADDD87F

即使弹簧应该知道我的表单在那里并且它应该处理参数......那我做错了什么?

4

1 回答 1

0

您是否尝试过仅使用设置登录表单<form method="post" name="loginForm" action='#{request.contextPath}/j_spring_security_check'>

您的配置中还有一件奇怪的事情(但从您所说的现在不是问题):

那是您要声明两个authentication managers

<security:authentication-manager>,
<bean id='authenticationManager' class='org.springframework.security.authentication.ProviderManager'>

尝试删除

<security:authentication-manager>
    <security:authentication-provider user-service-ref='userDetailsService'>
        <security:password-encoder hash='plaintext' />
    </security:authentication-provider>
</security:authentication-manager>
于 2013-06-10T07:37:08.267 回答