기본 콘텐츠로 건너뛰기

7월, 2015의 게시물 표시

[Spring Security] User Authentication Example - 2. Custom Authentication Provider 구현 및 Login Form 작성

1. AuthenticationProvider  인터페이스 구현 org.springframework.security.authentication.AuthenticationProvider 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 public   class  CustomAuthenticationProvider  implements  AuthenticationProvider {           private  UserService userService;      private   static   final  Logger logger  =  LoggerFactory.getLogger(CustomAuthenticationProvider. class );     @Override      public  Authentication authenticate(Authentication auth)  throws  AuthenticationException {          String  email  =  ( String ) auth.getPrincipal();          String  password  =  ( String ) auth.getCredentials();         User user  =  (User) userService.loadUserByUsername(email);                   if  (user.getPassword(). equals (password)) {             logger.info( "Authentication Success!!! {}" , em

[Spring Security] User Authentication Example - 1. configuration

Spring Security를 이용하여 사용자 인증을 하기 위해서 다음과 같은 설정이 필요하다. Maven을 기준으로 pom.xml에 Spring security 관련 dependency 추가 Spring Security를 위한 별도 빈 설정 파일 생성 (security-context.xml) web.xml에 새로 생성한 security-context.xml 등록 web.xmlSpring security Filter 등록 1. pom.xml Sprint Security Dependency 추가 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 < dependency >     < artifactId >spring-security-web</ artifactId >     < version >4.0.1.RELEASE</ version > </ dependency > < dependency >     < groupId >org.springframework.security</ groupId >     < artifactId >spring-security-config</ artifactId >     < version >4.0.1.RELEASE</ version > </ dependency > < dependency >     < groupId >org.springframework.security</ groupId >     < artifactId >spring-security-core</ artifactId >     < version >4.0.1.RE