Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaisqls committed May 16, 2023
2 parents ba72583 + 1ace8f7 commit 3b68f4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ValidateSameSchoolAspect(
returning = "ret"
)
fun validateSameSchool(joinPoint: JoinPoint, ret: SchoolIdDomain) {
if (ret.schoolId != securityPort.getCurrentUserSchoolId()) {
if (securityPort.isAuthenticated() && ret.schoolId != securityPort.getCurrentUserSchoolId()) {
throw SchoolMismatchException
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface SecurityPort {

fun isPasswordMatch(rawPassword: String, encodedPassword: String): Boolean

fun isAuthenticated(): Boolean

fun getCurrentUserId(): UUID

fun getCurrentUserSchoolId(): UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class SecurityAdapter(
private val passwordEncoder: PasswordEncoder
) : SecurityPort {

override fun isPasswordMatch(rawPassword: String, encodedPassword: String) = passwordEncoder.matches(
rawPassword, encodedPassword
)

override fun isAuthenticated() =
SecurityContextHolder.getContext().authentication.principal is CustomDetails

override fun getCurrentUserId(): UUID {
return (SecurityContextHolder.getContext().authentication.principal as CustomDetails).userId
}
Expand All @@ -20,9 +27,5 @@ class SecurityAdapter(
return (SecurityContextHolder.getContext().authentication.principal as CustomDetails).schoolId
}

override fun isPasswordMatch(rawPassword: String, encodedPassword: String) = passwordEncoder.matches(
rawPassword, encodedPassword
)

override fun encodePassword(password: String): String = passwordEncoder.encode(password)
}

0 comments on commit 3b68f4d

Please sign in to comment.