从Spring Security XML配置转换为Java Config的问题 - 找不到j_spring_security_check

时间:2015-03-04 00:36:53

标签: java spring spring-mvc spring-security

我目前正在尝试从使用Spring Security XML配置转换为基于Java类的配置。

我正在使用Spring MVC和Spring Security版本3.2.6.RELEASE

我认为我已经完成了所有的映射,但它仍然无效。提交我的登录表单时,我得到了/ j_spring_security_check的404。

这是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.2.xsd">

    <global-method-security pre-post-annotations="enabled"/>

    <beans:bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder">
    </beans:bean>

    <beans:bean id="rememberMeServices" class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
        <beans:property name="userDetailsService" ref="myUserDetailsService"/>
        <beans:property name="key" value="MYKEY"/>
        <beans:property name="cookieName" value="REMEMBER_ME" />
    </beans:bean>

    <http auto-config="true" use-expressions="true">

        <form-login login-page="/login"
            default-target-url="/userHome"
            authentication-failure-url="/error-login" />
        <logout logout-url="/logout" logout-success-url="/" />

        <remember-me key="MYKEY" services-ref="rememberMeServices"/>
    </http>

    <authentication-manager>
        <authentication-provider user-service-ref="myUserDetailsService">
            <password-encoder ref="encoder" />
        </authentication-provider>
    </authentication-manager>

</beans:beans>

这是我尝试将其转换为Java Config

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
    @Resource(name="myUserDetailsService")
    private UserDetailsService myUserDetailsService;

    @Bean
    public StandardPasswordEncoder encoder()
    {
        return new StandardPasswordEncoder();
    }

    @Bean
    public TokenBasedRememberMeServices rememberMeServices()
    {
        TokenBasedRememberMeServices services = new TokenBasedRememberMeServices("MYKEY", myUserDetailsService);
        services.setCookieName("REMEMBER_ME");
        return services;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .formLogin()
                .loginPage("/login")
                .defaultSuccessUrl("/userHome")
                .failureUrl("/error-login")
                .loginProcessingUrl("/j_spring_security_check")
            .and()
            .logout()
                .logoutUrl("/logout")
                .logoutSuccessUrl("/")
            .and()
            .rememberMe()
                .key("MYKEY")
                .rememberMeServices(rememberMeServices());
    }

    @Autowired
    public void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(myUserDetailsService).passwordEncoder(encoder());
    }
}

我正在做的是@ImportResource(&#34; classpath:spring-security.xml&#34;)来自我的WebAppConfig文件并添加了Java配置类,但是当我这样做时,我找不到/ j_spring_security_check的页面

我错过了什么?

0 个答案:

没有答案