2014-04-10 2 views

답변

55

configure (AuthenticationManagerBuilder)은 AuthenticationProviders를 쉽게 추가 할 수있게하여 인증 메커니즘을 설정하는 데 사용됩니다. 다음은 내장 된 'user'및 'admin'로그인을 사용하여 메모리 내 인증을 정의합니다.

public void configure(AuthenticationManagerBuilder auth) { 
    auth 
     .inMemoryAuthentication() 
     .withUser("user") 
     .password("password") 
     .roles("USER") 
    .and() 
     .withUser("admin") 
     .password("password") 
     .roles("ADMIN","USER"); 
} 

구성은 (HttpSecurity)은 선택 일치를 기반으로 자원 레벨에서 웹의 구성 기반 보안을 할 수 있습니다 - 예를 들어, 아래 예제에서는/admin /으로 시작하는 URL을 ADMIN 역할이있는 사용자로 제한하고 다른 URL을 성공적으로 인증해야한다고 선언합니다.

protected void configure(HttpSecurity http) throws Exception { 
    http 
     .authorizeUrls() 
     .antMatchers("/admin/**").hasRole("ADMIN") 
     .anyRequest().authenticated() 
} 

구성 (WebSecurity)이 글로벌 보안에 영향을 구성 설정에 사용됩니다 (리소스를 무시 설정 디버그 모드는 사용자 정의 방화벽 정의를 구현하여 요청을 거부). 예를 들어, 다음 방법을 사용하면 인증을 위해/resources /로 시작하는 모든 요청이 무시됩니다.

public void configure(WebSecurity web) throws Exception { 
    web 
     .ignoring() 
     .antMatchers("/resources/**"); 
} 
당신은 자세한 내용은 Spring Security Java Config Preview: Web Security

을 위해 다음 링크를 참조 할 수 있습니다

관련 문제