Fixed spring configuration
This commit is contained in:
parent
140edcbb6d
commit
638c360975
5 changed files with 32 additions and 34 deletions
|
@ -21,7 +21,7 @@ repositories {
|
||||||
val exposedVersion = "0.41.1"
|
val exposedVersion = "0.41.1"
|
||||||
val postgresVersion = "42.5.4"
|
val postgresVersion = "42.5.4"
|
||||||
val telegramBotVersion = "6.5.0"
|
val telegramBotVersion = "6.5.0"
|
||||||
val springBootVersion = "3.1.0"
|
val springBootVersion = "2.7.14"
|
||||||
val serializationVersion = "1.5.0"
|
val serializationVersion = "1.5.0"
|
||||||
val loggingVersion = "3.0.5"
|
val loggingVersion = "3.0.5"
|
||||||
val securityTestVersion = "6.0.2"
|
val securityTestVersion = "6.0.2"
|
||||||
|
@ -34,16 +34,9 @@ dependencies {
|
||||||
implementation("org.telegram:telegrambotsextensions:$telegramBotVersion")
|
implementation("org.telegram:telegrambotsextensions:$telegramBotVersion")
|
||||||
implementation("org.telegram:telegrambots-spring-boot-starter:$telegramBotVersion")
|
implementation("org.telegram:telegrambots-spring-boot-starter:$telegramBotVersion")
|
||||||
|
|
||||||
implementation("org.springframework.boot:spring-boot-starter:$springBootVersion") {
|
implementation("org.springframework.boot:spring-boot-starter:$springBootVersion")
|
||||||
exclude("org.springframework.boot:spring-boot-starter-tomcat")
|
implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
|
||||||
}
|
implementation("org.springframework.boot:spring-boot-starter-security:$springBootVersion")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") {
|
|
||||||
exclude("org.springframework.boot:spring-boot-starter-tomcat")
|
|
||||||
}
|
|
||||||
implementation("org.springframework.boot:spring-boot-starter-security:$springBootVersion") {
|
|
||||||
exclude("org.springframework.boot:spring-boot-starter-tomcat")
|
|
||||||
}
|
|
||||||
implementation("org.springframework.boot:spring-boot-starter-jetty:$springBootVersion")
|
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
|
||||||
|
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||||
|
@ -58,16 +51,6 @@ dependencies {
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
|
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations.all {
|
|
||||||
resolutionStrategy {
|
|
||||||
eachDependency {
|
|
||||||
if (requested.group == "jakarta.servlet") {
|
|
||||||
useVersion("5.0.0")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
tasks.withType<KotlinCompile> {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
freeCompilerArgs = listOf("-Xjsr305=strict")
|
freeCompilerArgs = listOf("-Xjsr305=strict")
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package ru.sicamp.sicamphelper.api.controller
|
package ru.sicamp.sicamphelper.api.controller
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
|
||||||
import com.fasterxml.jackson.module.kotlin.convertValue
|
|
||||||
import mu.KLogging
|
import mu.KLogging
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import ru.sicamp.sicamphelper.model.dto.UserDto
|
import ru.sicamp.sicamphelper.model.dto.UserDto
|
||||||
|
@ -11,7 +9,6 @@ import ru.sicamp.sicamphelper.service.UserService
|
||||||
@RestController
|
@RestController
|
||||||
class UsersController(
|
class UsersController(
|
||||||
private val userService: UserService,
|
private val userService: UserService,
|
||||||
private val objectMapper: ObjectMapper,
|
|
||||||
) {
|
) {
|
||||||
@PostMapping("/user/create")
|
@PostMapping("/user/create")
|
||||||
fun create(@RequestParam dto: UserDto): UserInfo {
|
fun create(@RequestParam dto: UserDto): UserInfo {
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package ru.sicamp.sicamphelper.repository
|
package ru.sicamp.sicamphelper.repository
|
||||||
|
|
||||||
import mu.KLogging
|
import mu.KLogging
|
||||||
|
import org.jetbrains.exposed.dao.load
|
||||||
import org.jetbrains.exposed.dao.with
|
import org.jetbrains.exposed.dao.with
|
||||||
import org.jetbrains.exposed.sql.and
|
import org.jetbrains.exposed.sql.and
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder
|
import org.springframework.security.crypto.password.PasswordEncoder
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
import ru.sicamp.sicamphelper.db.entity.User
|
import ru.sicamp.sicamphelper.db.entity.User
|
||||||
import ru.sicamp.sicamphelper.db.table.Users
|
import ru.sicamp.sicamphelper.db.table.Users
|
||||||
import ru.sicamp.sicamphelper.model.dto.UserDto
|
import ru.sicamp.sicamphelper.model.dto.UserDto
|
||||||
import ru.sicamp.sicamphelper.util.badArgument
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
@ -21,7 +22,10 @@ class UserRepository(
|
||||||
User.find {
|
User.find {
|
||||||
(Users.tgId eq id) and
|
(Users.tgId eq id) and
|
||||||
(Users.tgUsername eq userName)
|
(Users.tgUsername eq userName)
|
||||||
}.firstOrNull()
|
}.with(
|
||||||
|
User::supervisor,
|
||||||
|
User::group
|
||||||
|
).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findUserByUsername(username: String) = transaction {
|
fun findUserByUsername(username: String) = transaction {
|
||||||
|
@ -30,11 +34,14 @@ class UserRepository(
|
||||||
}.with(
|
}.with(
|
||||||
User::supervisor,
|
User::supervisor,
|
||||||
User::group
|
User::group
|
||||||
).firstOrNull() ?: badArgument("Not found user with username $username")
|
).firstOrNull() ?: throw UsernameNotFoundException("Not found user with username $username")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findUserById(id: Long) = transaction {
|
fun findUserById(id: Long) = transaction {
|
||||||
User.findById(id)
|
User.findById(id)?.load(
|
||||||
|
User::supervisor,
|
||||||
|
User::group
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createUser(userDto: UserDto): User = transaction {
|
fun createUser(userDto: UserDto): User = transaction {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package ru.sicamp.sicamphelper.security
|
||||||
|
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import ru.sicamp.sicamphelper.db.entity.User
|
||||||
|
import ru.sicamp.sicamphelper.repository.UserRepository
|
||||||
|
import ru.sicamp.sicamphelper.util.badArgument
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class UserDetailsServiceImpl(
|
||||||
|
private val userRepository: UserRepository
|
||||||
|
) : UserDetailsService {
|
||||||
|
override fun loadUserByUsername(username: String?): User = userRepository.findUserByUsername(
|
||||||
|
username = username ?: badArgument("Username shouldn't be null")
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package ru.sicamp.sicamphelper.service
|
package ru.sicamp.sicamphelper.service
|
||||||
|
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import ru.sicamp.sicamphelper.db.entity.User
|
import ru.sicamp.sicamphelper.db.entity.User
|
||||||
import ru.sicamp.sicamphelper.model.dto.UserDto
|
import ru.sicamp.sicamphelper.model.dto.UserDto
|
||||||
|
@ -12,16 +11,12 @@ import ru.sicamp.sicamphelper.util.badArgument
|
||||||
@Service
|
@Service
|
||||||
class UserService(
|
class UserService(
|
||||||
private val userRepository: UserRepository
|
private val userRepository: UserRepository
|
||||||
) : UserDetailsService {
|
) {
|
||||||
fun findUserByTgUser(user: TgUser): User? = userRepository.findUserByTgUsernameAndId(
|
fun findUserByTgUser(user: TgUser): User? = userRepository.findUserByTgUsernameAndId(
|
||||||
id = user.id,
|
id = user.id,
|
||||||
userName = user.userName
|
userName = user.userName
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun loadUserByUsername(username: String?): User = userRepository.findUserByUsername(
|
|
||||||
username = username ?: badArgument("Username shouldn't be null")
|
|
||||||
)
|
|
||||||
|
|
||||||
fun findUserInfoByLogin(login: String) = UserInfo.from(
|
fun findUserInfoByLogin(login: String) = UserInfo.from(
|
||||||
userRepository.findUserByUsername(login)
|
userRepository.findUserByUsername(login)
|
||||||
) ?: badArgument("Not found user with login=$login")
|
) ?: badArgument("Not found user with login=$login")
|
||||||
|
|
Loading…
Reference in a new issue