-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from nhnacademy-be5-T3Team/fix/authProvider
Fix/ #25 auth provider
- Loading branch information
Showing
10 changed files
with
89 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/t3t/authenticationapi/account/component/CustomAuthenticationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.t3t.authenticationapi.account.component; | ||
|
||
import com.t3t.authenticationapi.account.auth.CustomUserDetails; | ||
import com.t3t.authenticationapi.account.dto.UserEntity; | ||
import com.t3t.authenticationapi.account.service.DefaultUserDetailsService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.security.authentication.AuthenticationProvider; | ||
import org.springframework.security.authentication.BadCredentialsException; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
|
||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class CustomAuthenticationProvider implements AuthenticationProvider { | ||
private final DefaultUserDetailsService userDetailsService; | ||
|
||
@Bean | ||
public BCryptPasswordEncoder bCryptPasswordEncoder(){ | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Override | ||
public Authentication authenticate(Authentication authentication) throws AuthenticationException { | ||
String username = authentication.getName(); | ||
String password = authentication.getCredentials().toString(); | ||
|
||
CustomUserDetails userDetails = (CustomUserDetails) userDetailsService.loadUserByUsername(username); | ||
|
||
String dbPassword = userDetails.getPassword(); | ||
if(!bCryptPasswordEncoder().matches(password,dbPassword)){ | ||
throw new BadCredentialsException("id, pw not match"); | ||
} | ||
|
||
return new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); | ||
} | ||
|
||
@Override | ||
public boolean supports(Class<?> authentication) { | ||
return authentication.equals(UsernamePasswordAuthenticationToken.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
eureka: | ||
eureka: | ||
client: | ||
register-with-eureka: true | ||
fetch-registry: true | ||
service-url: | ||
defaultZone: ${eurekaServiceUrlDefaultZone} |