chore(release): first stable release #45
@@ -1,7 +1,6 @@
|
||||
package com.project.movienight
|
||||
|
||||
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.runApplication
|
||||
|
||||
|
||||
+53
-48
@@ -9,7 +9,6 @@ import com.project.movienight.domain.model.User
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.sql.ResultSet
|
||||
//import java.time.LocalDateTime
|
||||
import java.util.UUID
|
||||
|
||||
@Repository
|
||||
@@ -31,30 +30,32 @@ class UserRepository(
|
||||
override fun save(user: User): User {
|
||||
val existingUser = findById(user.id)
|
||||
|
||||
val entity = if (existingUser != null) {
|
||||
val existingEntity = existingUser.toEntity()
|
||||
user.toEntity(
|
||||
provider = existingEntity.provider?.let { AuthProvider.valueOf(it) },
|
||||
providerId = existingEntity.providerId,
|
||||
createdAt = existingEntity.createdAt,
|
||||
)
|
||||
} else {
|
||||
user.toEntity()
|
||||
}
|
||||
val entity =
|
||||
if (existingUser != null) {
|
||||
val existingEntity = existingUser.toEntity()
|
||||
user.toEntity(
|
||||
provider = existingEntity.provider?.let { AuthProvider.valueOf(it) },
|
||||
providerId = existingEntity.providerId,
|
||||
createdAt = existingEntity.createdAt,
|
||||
)
|
||||
} else {
|
||||
user.toEntity()
|
||||
}
|
||||
|
||||
val updatedRows = jdbc.update(
|
||||
"""
|
||||
UPDATE users
|
||||
SET name = ?, email = ?, password = ?, provider = ?, provider_id = ?
|
||||
WHERE id = ?
|
||||
""".trimIndent(),
|
||||
entity.name,
|
||||
entity.email,
|
||||
user.password,
|
||||
entity.provider,
|
||||
entity.providerId,
|
||||
entity.id,
|
||||
)
|
||||
val updatedRows =
|
||||
jdbc.update(
|
||||
"""
|
||||
UPDATE users
|
||||
SET name = ?, email = ?, password = ?, provider = ?, provider_id = ?
|
||||
WHERE id = ?
|
||||
""".trimIndent(),
|
||||
entity.name,
|
||||
entity.email,
|
||||
user.password,
|
||||
entity.provider,
|
||||
entity.providerId,
|
||||
entity.id,
|
||||
)
|
||||
|
||||
if (updatedRows == 0) {
|
||||
jdbc.update(
|
||||
@@ -75,28 +76,31 @@ class UserRepository(
|
||||
}
|
||||
|
||||
override fun findById(id: UUID): User? {
|
||||
val entities = jdbc.query(
|
||||
"SELECT id, name, email, password, provider, provider_id, created_at FROM users WHERE id = ?",
|
||||
userEntityRowMapper,
|
||||
id,
|
||||
)
|
||||
val entities =
|
||||
jdbc.query(
|
||||
"SELECT id, name, email, password, provider, provider_id, created_at FROM users WHERE id = ?",
|
||||
userEntityRowMapper,
|
||||
id,
|
||||
)
|
||||
return entities.firstOrNull()?.toDomain()
|
||||
}
|
||||
|
||||
override fun findByEmail(email: String): User? {
|
||||
val entities = jdbc.query(
|
||||
"SELECT id, name, email, password, provider, provider_id, created_at FROM users WHERE email = ?",
|
||||
userEntityRowMapper,
|
||||
email,
|
||||
)
|
||||
val entities =
|
||||
jdbc.query(
|
||||
"SELECT id, name, email, password, provider, provider_id, created_at FROM users WHERE email = ?",
|
||||
userEntityRowMapper,
|
||||
email,
|
||||
)
|
||||
return entities.firstOrNull()?.toDomain()
|
||||
}
|
||||
|
||||
override fun findAll(): List<User> =
|
||||
jdbc.query(
|
||||
"SELECT id, name, email, password, provider, provider_id, created_at FROM users",
|
||||
userEntityRowMapper,
|
||||
).map { it.toDomain() }
|
||||
jdbc
|
||||
.query(
|
||||
"SELECT id, name, email, password, provider, provider_id, created_at FROM users",
|
||||
userEntityRowMapper,
|
||||
).map { it.toDomain() }
|
||||
|
||||
override fun deleteById(id: UUID) {
|
||||
jdbc.update("DELETE FROM users WHERE id = ?", id)
|
||||
@@ -147,16 +151,17 @@ class UserRepository(
|
||||
provider: AuthProvider,
|
||||
providerId: String,
|
||||
): User? {
|
||||
val entities = jdbc.query(
|
||||
"""
|
||||
SELECT id, name, email, password, provider, provider_id, created_at
|
||||
FROM users
|
||||
WHERE provider = ? AND provider_id = ?
|
||||
""".trimIndent(),
|
||||
userEntityRowMapper,
|
||||
provider.name,
|
||||
providerId,
|
||||
)
|
||||
val entities =
|
||||
jdbc.query(
|
||||
"""
|
||||
SELECT id, name, email, password, provider, provider_id, created_at
|
||||
FROM users
|
||||
WHERE provider = ? AND provider_id = ?
|
||||
""".trimIndent(),
|
||||
userEntityRowMapper,
|
||||
provider.name,
|
||||
providerId,
|
||||
)
|
||||
return entities.firstOrNull()?.toDomain()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,22 +18,22 @@ class SecurityConfiguration(
|
||||
oauth2
|
||||
.userInfoEndpoint { userInfo ->
|
||||
userInfo.userService(customOAuth2UserService)
|
||||
}
|
||||
.defaultSuccessUrl("/api/users/me", true)
|
||||
}
|
||||
.authorizeHttpRequests { auth ->
|
||||
}.defaultSuccessUrl("/api/users/me", true)
|
||||
}.authorizeHttpRequests { auth ->
|
||||
auth
|
||||
.requestMatchers("/", "/login/**", "/oauth2/**", "/h2-console/**", "/actuator/health").permitAll()
|
||||
.requestMatchers("/api/users/me").authenticated()
|
||||
.requestMatchers("/api/**").authenticated()
|
||||
.anyRequest().authenticated()
|
||||
}
|
||||
.headers { headers ->
|
||||
.requestMatchers("/", "/login/**", "/oauth2/**", "/h2-console/**", "/actuator/health")
|
||||
.permitAll()
|
||||
.requestMatchers("/api/users/me")
|
||||
.authenticated()
|
||||
.requestMatchers("/api/**")
|
||||
.authenticated()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
}.headers { headers ->
|
||||
headers.frameOptions { frameOptions ->
|
||||
frameOptions.sameOrigin()
|
||||
}
|
||||
}
|
||||
.csrf { csrf ->
|
||||
}.csrf { csrf ->
|
||||
csrf.disable()
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.UUID
|
||||
class UserPrincipal(
|
||||
private val user: User,
|
||||
private val attributes: Map<String, Any>? = null,
|
||||
) : OAuth2User, UserDetails {
|
||||
|
||||
) : OAuth2User,
|
||||
UserDetails {
|
||||
fun getId(): UUID = user.id
|
||||
|
||||
override fun getName(): String = user.name
|
||||
@@ -19,7 +19,9 @@ class UserPrincipal(
|
||||
override fun getAttributes(): Map<String, Any> = attributes ?: emptyMap()
|
||||
|
||||
override fun getAuthorities(): Collection<GrantedAuthority> =
|
||||
listOf(SimpleGrantedAuthority("ROLE_USER"))
|
||||
listOf(
|
||||
SimpleGrantedAuthority("ROLE_USER"),
|
||||
)
|
||||
|
||||
override fun getPassword(): String = ""
|
||||
|
||||
@@ -34,7 +36,9 @@ class UserPrincipal(
|
||||
override fun isEnabled(): Boolean = true
|
||||
|
||||
companion object {
|
||||
fun create(user: User, attributes: Map<String, Any>? = null): UserPrincipal =
|
||||
UserPrincipal(user, attributes)
|
||||
fun create(
|
||||
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.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
//import com.project.movienight.adapters.security.UserPrincipal
|
||||
import java.util.UUID
|
||||
|
||||
@RestController
|
||||
@@ -74,12 +73,4 @@ class UserController(
|
||||
fun delete(
|
||||
@PathVariable id: UUID,
|
||||
) = deleteUserUseCase.delete(id)
|
||||
|
||||
/*
|
||||
@GetMapping("/me")
|
||||
fun getCurrentUser(principal: UserPrincipal): UserResponse =
|
||||
UserResponse.fromDomain(
|
||||
getUserByIdUseCase.getById(principal.getId())
|
||||
)
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user