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,18 +29,20 @@ 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 =
if (existingUser != null) {
val existingEntity = existingUser.toEntity() val existingEntity = existingUser.toEntity()
user.toEntity( user.toEntity(
provider = existingEntity.provider?.let { AuthProvider.valueOf(it) }, provider = existingEntity.provider?.let { AuthProvider.valueOf(it) },
providerId = existingEntity.providerId, providerId = existingEntity.providerId,
createdAt = existingEntity.createdAt createdAt = existingEntity.createdAt,
) )
} else { } else {
user.toEntity() user.toEntity()
} }
val updatedRows = jdbc.update( val updatedRows =
jdbc.update(
""" """
UPDATE users UPDATE users
SET name = ?, email = ?, provider = ?, provider_id = ? SET name = ?, email = ?, provider = ?, provider_id = ?
@@ -72,7 +73,8 @@ class UserRepository(
} }
override fun findById(id: UUID): User? { override fun findById(id: UUID): User? {
val entities = jdbc.query( val entities =
jdbc.query(
"SELECT id, name, email, provider, provider_id, created_at FROM users WHERE id = ?", "SELECT id, name, email, provider, provider_id, created_at FROM users WHERE id = ?",
userEntityRowMapper, userEntityRowMapper,
id, id,
@@ -81,7 +83,8 @@ class UserRepository(
} }
override fun findByEmail(email: String): User? { override fun findByEmail(email: String): User? {
val entities = jdbc.query( val entities =
jdbc.query(
"SELECT id, name, email, provider, provider_id, created_at FROM users WHERE email = ?", "SELECT id, name, email, provider, provider_id, created_at FROM users WHERE email = ?",
userEntityRowMapper, userEntityRowMapper,
email, email,
@@ -90,7 +93,8 @@ class UserRepository(
} }
override fun findAll(): List<User> = override fun findAll(): List<User> =
jdbc.query( jdbc
.query(
"SELECT id, name, email, provider, provider_id, created_at FROM users", "SELECT id, name, email, provider, provider_id, created_at FROM users",
userEntityRowMapper, userEntityRowMapper,
).map { it.toDomain() } ).map { it.toDomain() }
@@ -103,7 +107,8 @@ 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 SELECT id, name, email, provider, provider_id, created_at
FROM users FROM users
@@ -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())
)
*/
} }