Skip to content

Commit

Permalink
Merge pull request #1 from face-gram/temp
Browse files Browse the repository at this point in the history
fix: login authorize error
  • Loading branch information
jin-jae authored Mar 28, 2023
2 parents 0efe508 + fade334 commit 5ac047a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ out/
!**/src/main/**/out/
!**/src/test/**/out/
application-oauth.yml
key.json
src/main/resources/keys/key.json

### NetBeans ###
/nbproject/private/
Expand All @@ -37,5 +37,5 @@ key.json

### VS Code ###
.vscode/
key.json
src/main/resources/keys/key.json
application-oauth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import com.facegram.facegrambackend.dto.response.history.analysishistory.Analysi
import com.facegram.facegrambackend.dto.response.history.userhistory.UserHistoryAnalysisDto
import com.facegram.facegrambackend.security.CustomUserDetails
import com.facegram.facegrambackend.service.history.HistoryService
import lombok.extern.slf4j.Slf4j
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import kotlin.math.log


@Service
Expand All @@ -22,6 +24,7 @@ class HistoryController constructor(
request: HttpServletRequest,
response: HttpServletResponse
): MutableList<UserHistoryAnalysisDto> {
println("컨트롤러 도착")
val userId: Long = user.name.toLong()
return historyService.historySearchByUser(userId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OAuth2AuthenticationSuccessHandler(
private val tokenProvider: JwtTokenProvider,
private val cookieAuthorizationRequestRepository: CookieAuthorizationRequestRepository
): SimpleUrlAuthenticationSuccessHandler() {
val log: Logger = LoggerFactory.getLogger(JwtTokenProvider::class.java)
val log: Logger = LoggerFactory.getLogger(OAuth2AuthenticationSuccessHandler::class.java)

override fun onAuthenticationSuccess(
request: HttpServletRequest,
Expand All @@ -54,6 +54,7 @@ class OAuth2AuthenticationSuccessHandler(
response: HttpServletResponse?,
authentication: Authentication?)
:String{
println("성공 핸들러 도착")
if (request!=null){
val redirectUri: Optional<String> = CookieUtil.getCookie(request, REDIRECT_URI_PARAM_COOKIE_NAME)
.map { cookie -> cookie.value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@Component
class JwtAccessDeniedHandler():AccessDeniedHandler {
class JwtAccessDeniedHandler:AccessDeniedHandler {
override fun handle(
request: HttpServletRequest?,
response: HttpServletResponse?,
accessDeniedException: AccessDeniedException?
) {
// response.sendError(HttpServletResponse.SC_UNAUTHORIZED,authException.localizedMessage)
throw NoAuthorizationException("권한이 없는 사용자입니다.")
response!!.sendError(HttpServletResponse.SC_UNAUTHORIZED,"권한이 없는 사용자입니다.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ constructor(
val context: SecurityContext = SecurityContextHolder.getContext()
context.authentication = authentication
log.info("인증정보 저장 => ",authentication.name)
println("인증필터 도착")
}else{
log.debug("유효한 JWT 토큰이 없습니다.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class JwtTokenProvider(
val authorities: Collection<GrantedAuthority> = claims[AUTHORITIES_KEY].toString().split(",")
.map { SimpleGrantedAuthority(it) }
.toList()
val principal = CustomUserDetails(java.lang.Long.valueOf(claims.subject), "", authorities)
val principal = CustomUserDetails(java.lang.Long.valueOf(claims.subject), "test", authorities)
log.info("CustomUserDetials = {} {}",principal.name,principal.username)
log.info("principal 확인$principal")
return UsernamePasswordAuthenticationToken(principal, "", authorities)
}

Expand Down

0 comments on commit 5ac047a

Please sign in to comment.