[#17] feat: provider 구현

- Custom AuthenticationProvider 구현체 적용(비밀번호 인증 과정)
- 불필요한 클래스 제거(SecurityUser)
This commit is contained in:
beaniejoy
2022-10-29 11:59:25 +09:00
parent e6aafebb53
commit ae0d89d870
2 changed files with 11 additions and 6 deletions

View File

@@ -1,5 +0,0 @@
package io.beaniejoy.dongnecafe.common.entity
class SecurityUser(
)

View File

@@ -2,12 +2,17 @@ package io.beaniejoy.dongnecafe.common.security
import mu.KLogging
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.userdetails.UserDetailsService
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Component
/**
* 실제 인증 절차 수행
* @property userDetailsService email로 계정 찾기
*/
@Component
class ApiAuthenticationProvider(
private val userDetailsService: UserDetailsService,
@@ -22,7 +27,12 @@ class ApiAuthenticationProvider(
val password = authentication.credentials as String?
val user = userDetailsService.loadUserByUsername(email)
TODO("Not yet implemented")
if (!passwordEncoder.matches(password, user.password)) {
throw BadCredentialsException("Input password does not match stored password")
}
// password null로 반환
return UsernamePasswordAuthenticationToken(email, null, user.authorities)
}
override fun supports(authentication: Class<*>): Boolean {