fix: resolve CI compile failure and complete OAuth2 review fixes

Agent-Logs-Url: https://github.com/devitq/movienight-backend/sessions/62eaa8e4-560b-4737-be4b-478f1a4c484a

Co-authored-by: devitq <118541411+devitq@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-08 17:37:35 +00:00
committed by GitHub
co-authored by devitq
parent 0aa7dcaf98
commit 0b57c31611
6 changed files with 73 additions and 74 deletions
@@ -1,7 +1,6 @@
package com.project.movienight package com.project.movienight
import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.SpringBootApplication
//import org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration
import org.springframework.boot.context.properties.ConfigurationPropertiesScan import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication import org.springframework.boot.runApplication
@@ -9,7 +9,6 @@ import com.project.movienight.domain.model.User
import org.springframework.jdbc.core.JdbcTemplate import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
import java.sql.ResultSet import java.sql.ResultSet
//import java.time.LocalDateTime
import java.util.UUID import java.util.UUID
@Repository @Repository
@@ -30,29 +29,31 @@ class UserRepository(
override fun save(user: User): User { override fun save(user: User): User {
val existingUser = findById(user.id) val existingUser = findById(user.id)
val entity = if (existingUser != null) { val entity =
val existingEntity = existingUser.toEntity() if (existingUser != null) {
user.toEntity( val existingEntity = existingUser.toEntity()
provider = existingEntity.provider?.let { AuthProvider.valueOf(it) }, user.toEntity(
providerId = existingEntity.providerId, provider = existingEntity.provider?.let { AuthProvider.valueOf(it) },
createdAt = existingEntity.createdAt providerId = existingEntity.providerId,
) createdAt = existingEntity.createdAt,
} else { )
user.toEntity() } else {
} user.toEntity()
}
val updatedRows = jdbc.update( val updatedRows =
""" jdbc.update(
UPDATE users """
SET name = ?, email = ?, provider = ?, provider_id = ? UPDATE users
WHERE id = ? SET name = ?, email = ?, provider = ?, provider_id = ?
""".trimIndent(), WHERE id = ?
entity.name, """.trimIndent(),
entity.email, entity.name,
entity.provider, entity.email,
entity.providerId, entity.provider,
entity.id, entity.providerId,
) entity.id,
)
if (updatedRows == 0) { if (updatedRows == 0) {
jdbc.update( jdbc.update(
@@ -72,28 +73,31 @@ class UserRepository(
} }
override fun findById(id: UUID): User? { override fun findById(id: UUID): User? {
val entities = jdbc.query( val entities =
"SELECT id, name, email, provider, provider_id, created_at FROM users WHERE id = ?", jdbc.query(
userEntityRowMapper, "SELECT id, name, email, provider, provider_id, created_at FROM users WHERE id = ?",
id, userEntityRowMapper,
) id,
)
return entities.firstOrNull()?.toDomain() return entities.firstOrNull()?.toDomain()
} }
override fun findByEmail(email: String): User? { override fun findByEmail(email: String): User? {
val entities = jdbc.query( val entities =
"SELECT id, name, email, provider, provider_id, created_at FROM users WHERE email = ?", jdbc.query(
userEntityRowMapper, "SELECT id, name, email, provider, provider_id, created_at FROM users WHERE email = ?",
email, userEntityRowMapper,
) email,
)
return entities.firstOrNull()?.toDomain() return entities.firstOrNull()?.toDomain()
} }
override fun findAll(): List<User> = override fun findAll(): List<User> =
jdbc.query( jdbc
"SELECT id, name, email, provider, provider_id, created_at FROM users", .query(
userEntityRowMapper, "SELECT id, name, email, provider, provider_id, created_at FROM users",
).map { it.toDomain() } userEntityRowMapper,
).map { it.toDomain() }
override fun deleteById(id: UUID) { override fun deleteById(id: UUID) {
jdbc.update("DELETE FROM users WHERE id = ?", id) jdbc.update("DELETE FROM users WHERE id = ?", id)
@@ -103,16 +107,17 @@ class UserRepository(
provider: AuthProvider, provider: AuthProvider,
providerId: String, providerId: String,
): User? { ): User? {
val entities = jdbc.query( val entities =
""" jdbc.query(
SELECT id, name, email, provider, provider_id, created_at """
FROM users SELECT id, name, email, provider, provider_id, created_at
WHERE provider = ? AND provider_id = ? FROM users
""".trimIndent(), WHERE provider = ? AND provider_id = ?
userEntityRowMapper, """.trimIndent(),
provider.name, userEntityRowMapper,
providerId, provider.name,
) providerId,
)
return entities.firstOrNull()?.toDomain() return entities.firstOrNull()?.toDomain()
} }
} }
@@ -18,22 +18,22 @@ class SecurityConfiguration(
oauth2 oauth2
.userInfoEndpoint { userInfo -> .userInfoEndpoint { userInfo ->
userInfo.userService(customOAuth2UserService) userInfo.userService(customOAuth2UserService)
} }.defaultSuccessUrl("/api/users/me", true)
.defaultSuccessUrl("/api/users/me", true) }.authorizeHttpRequests { auth ->
}
.authorizeHttpRequests { auth ->
auth auth
.requestMatchers("/", "/login/**", "/oauth2/**", "/h2-console/**", "/actuator/health").permitAll() .requestMatchers("/", "/login/**", "/oauth2/**", "/h2-console/**", "/actuator/health")
.requestMatchers("/api/users/me").authenticated() .permitAll()
.requestMatchers("/api/**").authenticated() .requestMatchers("/api/users/me")
.anyRequest().authenticated() .authenticated()
} .requestMatchers("/api/**")
.headers { headers -> .authenticated()
.anyRequest()
.authenticated()
}.headers { headers ->
headers.frameOptions { frameOptions -> headers.frameOptions { frameOptions ->
frameOptions.sameOrigin() frameOptions.sameOrigin()
} }
} }.csrf { csrf ->
.csrf { csrf ->
csrf.disable() csrf.disable()
} }
@@ -10,8 +10,8 @@ import java.util.UUID
class UserPrincipal( class UserPrincipal(
private val user: User, private val user: User,
private val attributes: Map<String, Any>? = null, private val attributes: Map<String, Any>? = null,
) : OAuth2User, UserDetails { ) : OAuth2User,
UserDetails {
fun getId(): UUID = user.id fun getId(): UUID = user.id
override fun getName(): String = user.name override fun getName(): String = user.name
@@ -19,7 +19,9 @@ class UserPrincipal(
override fun getAttributes(): Map<String, Any> = attributes ?: emptyMap() override fun getAttributes(): Map<String, Any> = attributes ?: emptyMap()
override fun getAuthorities(): Collection<GrantedAuthority> = override fun getAuthorities(): Collection<GrantedAuthority> =
listOf(SimpleGrantedAuthority("ROLE_USER")) listOf(
SimpleGrantedAuthority("ROLE_USER"),
)
override fun getPassword(): String = "" override fun getPassword(): String = ""
@@ -34,7 +36,9 @@ class UserPrincipal(
override fun isEnabled(): Boolean = true override fun isEnabled(): Boolean = true
companion object { companion object {
fun create(user: User, attributes: Map<String, Any>? = null): UserPrincipal = fun create(
UserPrincipal(user, attributes) user: User,
attributes: Map<String, Any>? = null,
): UserPrincipal = UserPrincipal(user, attributes)
} }
} }
@@ -20,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
//import com.project.movienight.adapters.security.UserPrincipal
import java.util.UUID import java.util.UUID
@RestController @RestController
@@ -74,12 +73,4 @@ class UserController(
fun delete( fun delete(
@PathVariable id: UUID, @PathVariable id: UUID,
) = deleteUserUseCase.delete(id) ) = deleteUserUseCase.delete(id)
/*
@GetMapping("/me")
fun getCurrentUser(principal: UserPrincipal): UserResponse =
UserResponse.fromDomain(
getUserByIdUseCase.getById(principal.getId())
)
*/
} }