add claims & user in JWT
This commit is contained in:
parent
85dcbad805
commit
eaed2a1e04
|
|
@ -1,8 +0,0 @@
|
|||
package org.js.lorca_core.business.mappers
|
||||
|
||||
import org.js.lorca_core.business.models.Client
|
||||
import org.js.lorca_core.db.entities.ClientEntity
|
||||
import org.mapstruct.Mapper
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
interface ClientMapper : GenericMapper<Client, ClientEntity>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.js.lorca_core.web.dtos
|
||||
package org.js.lorca_core.common.dtos
|
||||
|
||||
import org.js.lorca_core.web.dtos.validators.NameValidator
|
||||
import org.js.lorca_core.common.dtos.validators.NameValidator
|
||||
|
||||
data class ClientDto(
|
||||
@field:NameValidator.Validate
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.js.lorca_core.common.dtos
|
||||
|
||||
import org.js.lorca_core.common.dtos.validators.B64Validator
|
||||
import org.js.lorca_core.common.dtos.validators.UsernameValidator
|
||||
|
||||
data class UserAuthDto(
|
||||
@field:UsernameValidator.Validate
|
||||
val username: String,
|
||||
@field:B64Validator.Validate
|
||||
val password: String
|
||||
)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.web.dtos.validators
|
||||
package org.js.lorca_core.common.dtos.validators
|
||||
|
||||
import jakarta.validation.Constraint
|
||||
import jakarta.validation.ConstraintValidator
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.web.dtos.validators
|
||||
package org.js.lorca_core.common.dtos.validators
|
||||
|
||||
import jakarta.validation.Constraint
|
||||
import jakarta.validation.ConstraintValidator
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.web.dtos.validators
|
||||
package org.js.lorca_core.common.dtos.validators
|
||||
|
||||
import jakarta.validation.Constraint
|
||||
import jakarta.validation.ConstraintValidator
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package org.js.lorca_core.common.enums
|
||||
|
||||
enum class EBusinessException(val msg: String) {
|
||||
USER_ALREADY_EXISTS("Username: '%s' already exists"),
|
||||
USER_NOT_FOUND("Username: '%s' not found"),
|
||||
ENTITY_WITH_ID_NOT_FOUND("%s with id %s not found"),
|
||||
INVALID_REQUEST("Invalid request for %s with reason: %s")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package org.js.lorca_core.common.mappers
|
||||
|
||||
import org.js.lorca_core.common.models.Client
|
||||
import org.js.lorca_core.db.entities.ClientEntity
|
||||
import org.mapstruct.Mapper
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
interface ClientMapper : GenericMapper<Client, ClientEntity>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.business.mappers
|
||||
package org.js.lorca_core.common.mappers
|
||||
|
||||
interface GenericMapper<M, E> {
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.js.lorca_core.business.mappers
|
||||
package org.js.lorca_core.common.mappers
|
||||
|
||||
import org.js.lorca_core.business.models.UserAuthClaim
|
||||
import org.js.lorca_core.common.models.UserAuthClaim
|
||||
import org.js.lorca_core.db.entities.UserAuthClaimEntity
|
||||
import org.mapstruct.Mapper
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.js.lorca_core.common.mappers
|
||||
|
||||
import org.js.lorca_core.common.models.WorkerCategory
|
||||
import org.js.lorca_core.db.entities.WorkerCategoryEntity
|
||||
import org.mapstruct.Mapper
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
interface WorkCategoryMapper : GenericMapper<WorkerCategory, WorkerCategoryEntity>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.js.lorca_core.common.mappers
|
||||
|
||||
import org.js.lorca_core.common.models.Worker
|
||||
import org.js.lorca_core.db.entities.WorkerEntity
|
||||
import org.mapstruct.Mapper
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
interface WorkerMapper : GenericMapper<Worker, WorkerEntity>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.business.models
|
||||
package org.js.lorca_core.common.models
|
||||
|
||||
data class Client(
|
||||
var id: Long?,
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.business.models
|
||||
package org.js.lorca_core.common.models
|
||||
|
||||
import org.js.lorca_core.common.enums.EUserRoles
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.js.lorca_core.common.models
|
||||
|
||||
data class Worker(
|
||||
var id: Long,
|
||||
var name: String,
|
||||
var surname: String,
|
||||
val category: WorkerCategory
|
||||
)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.js.lorca_core.common.models
|
||||
|
||||
import org.js.lorca_core.common.enums.EWorkerCategory
|
||||
|
||||
data class WorkerCategory(
|
||||
var id: Long,
|
||||
var name: EWorkerCategory
|
||||
)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.js.lorca_core.common.responses
|
||||
|
||||
data class LoginResponse(
|
||||
val token: String
|
||||
)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.js.lorca_core.config.auth
|
||||
|
||||
import org.js.lorca_core.business.repositories.UserAuthRepository
|
||||
import org.js.lorca_core.repositories.UserAuthRepository
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.security.authentication.AuthenticationManager
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ import java.util.*
|
|||
|
||||
interface UserAuthJpa : JpaRepository<UserAuthEntity, Long> {
|
||||
fun findByUsr(username: String): Optional<UserAuthEntity>
|
||||
fun existsByUsr(username: String): Boolean
|
||||
}
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
package org.js.lorca_core.db
|
||||
|
||||
import org.js.lorca_core.common.enums.EWorkerCategory
|
||||
import org.js.lorca_core.db.entities.WorkerEntity
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.repository.query.Param
|
||||
import java.util.*
|
||||
|
||||
interface WorkerJpa : JpaRepository<WorkerEntity, Long> {
|
||||
|
||||
fun findAllByCategoryName(@Param("category") category: EWorkerCategory): MutableList<WorkerEntity>
|
||||
fun findByAuthUserUsr(username: String): Optional<WorkerEntity>
|
||||
}
|
||||
|
|
@ -5,12 +5,12 @@ import org.springframework.security.core.GrantedAuthority
|
|||
import org.springframework.security.core.userdetails.UserDetails
|
||||
|
||||
@Entity(name = "user_auth")
|
||||
class UserAuthEntity : UserDetails {
|
||||
class UserAuthEntity(usr: String, pwd: String) : UserDetails {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
var id: Long? = null
|
||||
var usr: String? = null
|
||||
var pwd: String? = null
|
||||
var usr: String? = usr
|
||||
var pwd: String? = pwd
|
||||
|
||||
@ManyToMany(cascade = [CascadeType.DETACH])
|
||||
var claims: MutableList<UserAuthClaimEntity> = mutableListOf()
|
||||
|
|
|
|||
|
|
@ -9,5 +9,7 @@ data class WorkerEntity(
|
|||
var name: String,
|
||||
var surname: String,
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
val category: WorkerCategoryEntity
|
||||
val category: WorkerCategoryEntity,
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
val authUser: UserAuthEntity
|
||||
)
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package org.js.lorca_core.business.repositories
|
||||
package org.js.lorca_core.repositories
|
||||
|
||||
import org.js.lorca_core.business.models.Client
|
||||
import org.js.lorca_core.common.models.Client
|
||||
|
||||
interface ClientRepository {
|
||||
fun createClient(client: Client): Client
|
||||
fun getAll(): MutableList<Client>
|
||||
fun getById(id: Long): Client
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
package org.js.lorca_core.business.repositories
|
||||
package org.js.lorca_core.repositories
|
||||
|
||||
import org.js.lorca_core.common.enums.EUserRoles
|
||||
import org.js.lorca_core.db.entities.UserAuthEntity
|
||||
|
||||
interface UserAuthRepository {
|
||||
fun existsByUsername(username: String): Boolean
|
||||
fun getByUsername(username: String): UserAuthEntity
|
||||
fun save(userAuth: UserAuthEntity): UserAuthEntity
|
||||
fun getClaimsForuser(user: UserAuthEntity): List<EUserRoles>
|
||||
fun getClaimsForUser(user: UserAuthEntity): List<EUserRoles>
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.js.lorca_core.repositories
|
||||
|
||||
import org.js.lorca_core.common.models.Worker
|
||||
|
||||
interface WorkerRepository {
|
||||
fun getByUsername(username: String): Worker?
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package org.js.lorca_core.business.repositories.impl
|
||||
package org.js.lorca_core.repositories.impl
|
||||
|
||||
import org.js.lorca_core.business.mappers.ClientMapper
|
||||
import org.js.lorca_core.business.models.Client
|
||||
import org.js.lorca_core.business.repositories.ClientRepository
|
||||
import org.js.lorca_core.common.enums.EBusinessException
|
||||
import org.js.lorca_core.common.exceptions.LorcaException
|
||||
import org.js.lorca_core.common.mappers.ClientMapper
|
||||
import org.js.lorca_core.common.models.Client
|
||||
import org.js.lorca_core.db.ClientJpa
|
||||
import org.js.lorca_core.repositories.ClientRepository
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
package org.js.lorca_core.business.repositories.impl
|
||||
package org.js.lorca_core.repositories.impl
|
||||
|
||||
import org.js.lorca_core.business.mappers.UserAuthClaimMapper
|
||||
import org.js.lorca_core.business.repositories.UserAuthRepository
|
||||
import org.js.lorca_core.common.enums.EBusinessException
|
||||
import org.js.lorca_core.common.enums.EUserRoles
|
||||
import org.js.lorca_core.common.exceptions.LorcaException
|
||||
import org.js.lorca_core.common.mappers.UserAuthClaimMapper
|
||||
import org.js.lorca_core.db.UserAuthJpa
|
||||
import org.js.lorca_core.db.entities.UserAuthEntity
|
||||
import org.js.lorca_core.repositories.UserAuthRepository
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
|
|
@ -23,8 +23,12 @@ class UserAuthRepositoryImpl(
|
|||
return jpa.save(userAuth)
|
||||
}
|
||||
|
||||
override fun getClaimsForuser(user: UserAuthEntity): List<EUserRoles> {
|
||||
override fun getClaimsForUser(user: UserAuthEntity): List<EUserRoles> {
|
||||
return claimMapper.toModels(user.claims).map { it.name }.toList()
|
||||
}
|
||||
|
||||
override fun existsByUsername(username: String): Boolean {
|
||||
return jpa.existsByUsr(username)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.js.lorca_core.repositories.impl
|
||||
|
||||
import org.js.lorca_core.common.mappers.WorkerMapper
|
||||
import org.js.lorca_core.common.models.Worker
|
||||
import org.js.lorca_core.db.WorkerJpa
|
||||
import org.js.lorca_core.repositories.WorkerRepository
|
||||
import org.springframework.stereotype.Component
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
@Component
|
||||
class WorkerRepositoryImpl(
|
||||
val jpa: WorkerJpa,
|
||||
val mapper: WorkerMapper
|
||||
) : WorkerRepository {
|
||||
override fun getByUsername(username: String): Worker? {
|
||||
val user = jpa.findByAuthUserUsr(username).getOrNull()
|
||||
return if (user != null) mapper.toModel(user) else null
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,10 @@
|
|||
package org.js.lorca_core.services
|
||||
|
||||
import org.js.lorca_core.common.enums.EUserRoles
|
||||
import org.js.lorca_core.db.entities.UserAuthEntity
|
||||
import org.js.lorca_core.web.dtos.UserAuthDto
|
||||
import org.js.lorca_core.common.dtos.UserAuthDto
|
||||
import org.js.lorca_core.common.responses.LoginResponse
|
||||
|
||||
interface AuthenticationService {
|
||||
fun register(input: UserAuthDto): Boolean
|
||||
fun register(dto: UserAuthDto): Boolean
|
||||
|
||||
fun login(input: UserAuthDto): UserAuthEntity
|
||||
|
||||
fun getClaimsForUser(user: UserAuthEntity): List<EUserRoles>
|
||||
fun login(dto: UserAuthDto): LoginResponse
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.js.lorca_core.services
|
||||
|
||||
import org.js.lorca_core.business.models.Client
|
||||
import org.js.lorca_core.web.dtos.ClientDto
|
||||
import org.js.lorca_core.common.dtos.ClientDto
|
||||
import org.js.lorca_core.common.models.Client
|
||||
|
||||
interface ClientService {
|
||||
fun getAllClients(name: String?, surname: String?): MutableList<Client>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package org.js.lorca_core.services.impl
|
||||
|
||||
import org.js.lorca_core.business.repositories.UserAuthRepository
|
||||
import org.js.lorca_core.common.enums.EUserRoles
|
||||
import org.js.lorca_core.common.dtos.UserAuthDto
|
||||
import org.js.lorca_core.common.enums.EBusinessException
|
||||
import org.js.lorca_core.common.exceptions.LorcaException
|
||||
import org.js.lorca_core.common.responses.LoginResponse
|
||||
import org.js.lorca_core.db.entities.UserAuthEntity
|
||||
import org.js.lorca_core.repositories.UserAuthRepository
|
||||
import org.js.lorca_core.services.AuthenticationService
|
||||
import org.js.lorca_core.web.dtos.UserAuthDto
|
||||
import org.js.lorca_core.services.JwtService
|
||||
import org.springframework.security.authentication.AuthenticationManager
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
|
||||
import org.springframework.security.crypto.password.PasswordEncoder
|
||||
|
|
@ -15,30 +18,31 @@ import org.springframework.stereotype.Service
|
|||
class AuthenticationServiceImpl(
|
||||
private val userAuthRepository: UserAuthRepository,
|
||||
private val authenticationManager: AuthenticationManager,
|
||||
private val passwordEncoder: PasswordEncoder
|
||||
private val passwordEncoder: PasswordEncoder,
|
||||
private val jwtService: JwtService
|
||||
) : AuthenticationService {
|
||||
|
||||
override fun register(input: UserAuthDto): Boolean {
|
||||
val user = UserAuthEntity()
|
||||
user.username = input.username
|
||||
user.password = passwordEncoder.encode(input.password)
|
||||
userAuthRepository.save(user)
|
||||
override fun register(dto: UserAuthDto): Boolean {
|
||||
if (userAuthRepository.existsByUsername(dto.username)) {
|
||||
throw LorcaException(EBusinessException.USER_ALREADY_EXISTS, dto.username)
|
||||
}
|
||||
|
||||
userAuthRepository.save(UserAuthEntity(dto.username, passwordEncoder.encode(dto.password)))
|
||||
return true
|
||||
}
|
||||
|
||||
override fun login(input: UserAuthDto): UserAuthEntity {
|
||||
override fun login(dto: UserAuthDto): LoginResponse {
|
||||
authenticationManager.authenticate(
|
||||
UsernamePasswordAuthenticationToken(
|
||||
input.username,
|
||||
input.password
|
||||
dto.username,
|
||||
dto.password
|
||||
)
|
||||
)
|
||||
|
||||
return userAuthRepository.getByUsername(input.username)
|
||||
}
|
||||
|
||||
override fun getClaimsForUser(user: UserAuthEntity): List<EUserRoles> {
|
||||
return userAuthRepository.getClaimsForuser(user)
|
||||
val user = userAuthRepository.getByUsername(dto.username)
|
||||
return LoginResponse(
|
||||
jwtService.generateToken(user)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package org.js.lorca_core.services.impl
|
||||
|
||||
import org.js.lorca_core.business.models.Client
|
||||
import org.js.lorca_core.business.repositories.ClientRepository
|
||||
import org.js.lorca_core.common.dtos.ClientDto
|
||||
import org.js.lorca_core.common.models.Client
|
||||
import org.js.lorca_core.repositories.ClientRepository
|
||||
import org.js.lorca_core.services.ClientService
|
||||
import org.js.lorca_core.web.dtos.ClientDto
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ import io.jsonwebtoken.Claims
|
|||
import io.jsonwebtoken.Jwts
|
||||
import io.jsonwebtoken.io.Decoders
|
||||
import io.jsonwebtoken.security.Keys
|
||||
import org.js.lorca_core.common.enums.EUserRoles
|
||||
import org.js.lorca_core.db.entities.UserAuthEntity
|
||||
import org.js.lorca_core.repositories.UserAuthRepository
|
||||
import org.js.lorca_core.repositories.WorkerRepository
|
||||
import org.js.lorca_core.services.JwtService
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.security.core.userdetails.UserDetails
|
||||
|
|
@ -13,7 +17,10 @@ import java.util.function.Function
|
|||
import javax.crypto.SecretKey
|
||||
|
||||
@Service
|
||||
class JwtServiceImpl : JwtService {
|
||||
class JwtServiceImpl(
|
||||
private val userAuthRepository: UserAuthRepository,
|
||||
private val workerRepository: WorkerRepository
|
||||
) : JwtService {
|
||||
|
||||
@Value("\${security.jwt.secret-key}")
|
||||
private lateinit var secretKey: String
|
||||
|
|
@ -31,7 +38,29 @@ class JwtServiceImpl : JwtService {
|
|||
}
|
||||
|
||||
override fun generateToken(userDetails: UserDetails): String {
|
||||
return generateToken(emptyMap(), userDetails)
|
||||
val extraClaims: Map<String, Any> = mapOf()
|
||||
getClaimsForUser(userAuthRepository.getByUsername(userDetails.username)).let { claims ->
|
||||
if (claims.isNotEmpty()) {
|
||||
extraClaims.plus(
|
||||
Pair(
|
||||
"roles",
|
||||
claims
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
workerRepository.getByUsername(userDetails.username)?.let {
|
||||
extraClaims.plus(
|
||||
Pair(
|
||||
"user",
|
||||
it
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return generateToken(
|
||||
extraClaims, userDetails
|
||||
)
|
||||
}
|
||||
|
||||
override fun generateToken(extraClaims: Map<String, Any>, userDetails: UserDetails): String {
|
||||
|
|
@ -81,4 +110,8 @@ class JwtServiceImpl : JwtService {
|
|||
val keyBytes = Decoders.BASE64.decode(secretKey)
|
||||
return Keys.hmacShaKeyFor(keyBytes)
|
||||
}
|
||||
|
||||
private fun getClaimsForUser(user: UserAuthEntity): List<EUserRoles> {
|
||||
return userAuthRepository.getClaimsForUser(user)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class BaseAdvice {
|
|||
|
||||
private fun deductStatus(ex: EBusinessException): HttpStatus {
|
||||
return when (ex) {
|
||||
EBusinessException.USER_ALREADY_EXISTS -> HttpStatus.UNPROCESSABLE_ENTITY
|
||||
EBusinessException.USER_NOT_FOUND -> HttpStatus.NOT_FOUND
|
||||
EBusinessException.ENTITY_WITH_ID_NOT_FOUND -> HttpStatus.NOT_FOUND
|
||||
EBusinessException.INVALID_REQUEST -> HttpStatus.BAD_REQUEST
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ package org.js.lorca_core.web.controllers
|
|||
|
||||
import jakarta.validation.Valid
|
||||
import lombok.AllArgsConstructor
|
||||
import org.js.lorca_core.common.dtos.UserAuthDto
|
||||
import org.js.lorca_core.common.responses.LoginResponse
|
||||
import org.js.lorca_core.services.AuthenticationService
|
||||
import org.js.lorca_core.services.JwtService
|
||||
import org.js.lorca_core.web.advices.WebResponse
|
||||
import org.js.lorca_core.web.dtos.UserAuthDto
|
||||
import org.js.lorca_core.web.responses.LoginResponse
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
|
|
@ -17,8 +16,7 @@ import org.springframework.web.bind.annotation.RestController
|
|||
@RequestMapping("/auth")
|
||||
@AllArgsConstructor
|
||||
class AuthController(
|
||||
val authenticationService: AuthenticationService,
|
||||
val jwtService: JwtService
|
||||
val authenticationService: AuthenticationService
|
||||
) {
|
||||
|
||||
@PostMapping("/register")
|
||||
|
|
@ -29,13 +27,8 @@ class AuthController(
|
|||
|
||||
@PostMapping("/login")
|
||||
fun authenticate(@Valid @RequestBody loginUserDto: UserAuthDto): WebResponse<LoginResponse> {
|
||||
val user = authenticationService.login(loginUserDto)
|
||||
return WebResponse.ok(
|
||||
LoginResponse(
|
||||
jwtService.generateToken(user),
|
||||
jwtService.getExpirationTime(),
|
||||
authenticationService.getClaimsForUser(user)
|
||||
)
|
||||
authenticationService.login(loginUserDto)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package org.js.lorca_core.web.controllers
|
|||
|
||||
import jakarta.validation.Valid
|
||||
import lombok.AllArgsConstructor
|
||||
import org.js.lorca_core.business.models.Client
|
||||
import org.js.lorca_core.common.dtos.ClientDto
|
||||
import org.js.lorca_core.common.models.Client
|
||||
import org.js.lorca_core.services.ClientService
|
||||
import org.js.lorca_core.web.advices.WebResponse
|
||||
import org.js.lorca_core.web.dtos.ClientDto
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
|
|
@ -32,5 +32,5 @@ class ClientController(
|
|||
fun getClient(@PathVariable("id") id: String): WebResponse<Client> {
|
||||
return WebResponse.ok(clientService.getClientById(id.toLong()))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package org.js.lorca_core.web.dtos
|
||||
|
||||
import org.js.lorca_core.web.dtos.validators.B64Validator
|
||||
import org.js.lorca_core.web.dtos.validators.UsernameValidator
|
||||
|
||||
data class UserAuthDto(
|
||||
@field:UsernameValidator.Validate
|
||||
val username: String,
|
||||
@field:B64Validator.Validate
|
||||
val password: String
|
||||
)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package org.js.lorca_core.web.responses
|
||||
|
||||
import org.js.lorca_core.common.enums.EUserRoles
|
||||
|
||||
data class LoginResponse(
|
||||
val token: String,
|
||||
val expiresIn: Long,
|
||||
val claims: List<EUserRoles>
|
||||
)
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
server.servlet.context-path=/api
|
||||
spring.application.name=lorca-gestionale-be
|
||||
#
|
||||
#
|
||||
# DATABASE
|
||||
#
|
||||
spring.datasource.url=jdbc:postgresql://0.0.0.0:5432/lorca_db
|
||||
spring.datasource.username=lorca_usr
|
||||
spring.datasource.password=lorca_pwd
|
||||
|
|
@ -7,8 +11,12 @@ spring.datasource.driver-class-name=org.postgresql.Driver
|
|||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.generate-ddl=true
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
# HOW TO GENERATE THIS KEY AT :
|
||||
#
|
||||
#
|
||||
# HOW TO GENERATE THIS KEY AT : https://www.devglan.com/online-tools/hmac-sha256-online?ref=blog.tericcabrel.com
|
||||
# PLAIN TEXT: Boh che cazzo ne so bel testo peró complimenti
|
||||
# SECRET KEY: Ma che minchia ne so quale puo essere una bella chiave segreta dio negraccio
|
||||
security.jwt.secret-key=93d5326c5ae622c9332f291c6a9868d237e6b41fc47c5f2581448d4d90e90a1a
|
||||
security.jwt.expiration-time=3600000
|
||||
security.jwt.expiration-time=3600000
|
||||
#
|
||||
#
|
||||
|
|
|
|||
Loading…
Reference in New Issue