2016-06-15 7 views
1

私は、Spring SecurityのSpring MVCプロジェクト(最近4.2.6.RELEASEに更新されました)の承認を取得しようとしています。 Spring MVC:Spring Security 4はインターセプトされません

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 
import org.springframework.security.config.annotation.web.builders.HttpSecurity; 
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.authorizeRequests().antMatchers("/", "/home").permitAll().anyRequest().authenticated().and().formLogin() 
       .loginPage("/login").permitAll().and().logout().permitAll(); 
    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth.inMemoryAuthentication().withUser("user").password("password").roles("USER"); 
    } 
} 

import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; 

public class SecurityWebInitializer extends AbstractSecurityWebApplicationInitializer { 
} 

私は、すべてのURLのは、現在ブロックされていることを期待するだろう:私はのみのクラスを作成する必要が理解するものから

<dependency org="org.springframework.security" name="spring-security-config" rev="4.1.0.RELEASE" /> 
    <dependency org="org.springframework.security" name="spring-security-core" rev="4.1.0.RELEASE" /> 
    <dependency org="org.springframework.security" name="spring-security-crypto" rev="4.1.0.RELEASE" /> 
    <dependency org="org.springframework.security" name="spring-security-taglibs" rev="4.1.0.RELEASE" /> 
    <dependency org="org.springframework.security" name="spring-security-web" rev="4.1.0.RELEASE" /> 

:だから私は、これらの依存性を追加しました「/」、「/ home」、「/ login」および「/ logout」を除いて、ログインしていないユーザーのためのものです。実際には何もブロックされず、私のwebappは完全にアクセス可能です。だから私はどこかで間違っているはずです...

本当にありがとう、私の問題が何かにヒントを与えることができます。ありがとうございました!

答えて

0

私はあなたのアリマッチャーをテストし、それがうまく働いていた(すべてがうまくようです)ので、私はあなたが春のサーブレットへのあなたの、カスタマーのセキュリティ設定(SecurityConfig)を登録していないと思う、それは@Importで行われています。

@EnableWebMvc 
@Configuration 
@ComponentScan({ "yourpackage" }) 
@Import({ SecurityConfig .class }) // See here 
public class SpringServlet { 

    @Bean 
    public InternalResourceViewResolver viewResolver() { 
     InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 
     viewResolver.setViewClass(JstlView.class); 
     viewResolver.setPrefix("/WEB-INF/.."); 
     viewResolver.setSuffix("..."); 
     return viewResolver; 
    } 

} 
関連する問題