2015-01-08 4 views
0

인증을 위해 스프링 보안을 사용하는 스프링 MVC 웹 애플리케이션이 있습니다. 등록 페이지가 있으며 사용자가 모든 세부 정보를 입력하면 방금 입력 한 정보를 사용하여 자동으로 로그인되기를 원합니다. 어떻게해야합니까?서버 측에서 스프링 보안 인증

답변

1

사용자 세부 사항을 처리하는 동안 Authentication 개체를 수동으로 설정하여 수행 할 수 있습니다. 여기에 코드입니다 : NEWUSER 및 NEWPASSWORD 등록 된 사용자의 자격 증명을 사용하여 두 개의 문자열이

List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>(); 
Authentication a = new UsernamePasswordAuthenticationToken(newUsername, newPassword, grantedAuths); 
SecurityContextHolder.getContext().setAuthentication(a);`