3
다른 프레임 워크를 사용하여 Java EE 앱 프로토 타입을 빌드하려고합니다. 보안 레이어를 제외하고 모두 제대로 작동합니다. 스프링 구성으로 구성된 스프링 보안을 사용하기로했습니다.스프링 보안 서비스 구성
코드는 다음과 같다 :
봄 보안 구성
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
@Autowired
private MyUserDetailsService userDetailsService;
@Override
protected UserDetailsService userDetailsService() {
return this.userDetailsService;
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login/authenticate")
.failureUrl("/login?error=bad_credentials")
.and()
.logout()
.logoutUrl("/signout")
.deleteCookies("JSESSIONID")
.and()
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/**").permitAll()
.and()
.csrf();
}
}
사용자 상세 서비스
@Service("myUserDetailsService")
public class MyUserDetailsService implements UserDetailsService
{
public static final Logger log = Logger.getLogger(MyUserDetailsService.class);
public MyUserDetailsService() {
}
@Autowired
private UserDao userDao;
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
final User user = getSystemUser(userName);
final List<GrantedAuthority> authorities = getUserAuthorities(user);
return buildUserForAuthentication(user, authorities);
}
private User buildUserForAuthentication(User user, List<GrantedAuthority> authorities) {
//...
}
private User getSystemUser(String alias) {
//...
}
private List<GrantedAuthority> getUserAuthorities(User user) {
//...
return null;
}
}
내가 할 수있는이 코드를 기대하고있어 무엇을하는 때이다 패스로 /login/authenticate
에 도달했습니다. params에서 기본 스프링 코드가 내 사용자 서비스를 호출하지만 결코 발생하지 않습니다.
무엇이 누락 되었습니까?
스프링 보안 3.2.3.RELEASE를 사용하고 있습니다.
이 방법 (registerAuthentication (AuthenticationManagerBuilder의 인증이)) 일부가 아닌 타르 보인다 WebSecurityConfigurerAdapter에 대한 설명. 어떤 클래스에서 확장하고 있습니까? –
사용자가 언급 한 버전을 놓쳤습니다. 3.2.3에서는 config가 @Autowired가되어야합니다. \t public void configureGlobal (AuthenticationManagerBuilder auth) throws Exception {질문 : –
에서 편집하겠습니까? 완전히 맞다! 그 동안 나는 그걸 봤고 그 버전의 Spring changelog에서 메서드 이름이 변경되었다는 것을 알았습니다. 내 코드를 다시 작성하고 이제는 작동합니다! 도움 주셔서 대단히 감사합니다! 감사합니다. –