Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
kotlin("plugin.jpa") version "2.1.21"
}

group = "io.github.devcavin"
group = "io.github.devcavin.gatelog"
version = "0.0.1-SNAPSHOT"
description = "backend"

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.devcavin.backend
package io.github.devcavin.gatelog.backend

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication
import org.springframework.data.web.config.EnableSpringDataWebSupport

@SpringBootApplication
@ConfigurationPropertiesScan
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
class BackendApplication

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.devcavin.backend.web.controller
package io.github.devcavin.gatelog.backend.auth

import io.github.devcavin.backend.service.AuthService
import io.github.devcavin.backend.web.dto.auth.AuthResponse
import io.github.devcavin.backend.web.dto.auth.LoginRequest
import io.github.devcavin.backend.web.dto.auth.RefreshTokenRequest
import io.github.devcavin.gatelog.backend.auth.dto.AuthResponse
import io.github.devcavin.gatelog.backend.auth.dto.LoginRequest
import io.github.devcavin.gatelog.backend.auth.dto.RefreshTokenRequest
import jakarta.validation.Valid
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package io.github.devcavin.backend.service

import io.github.devcavin.backend.common.exception.AccountDisabledException
import io.github.devcavin.backend.common.exception.InvalidCredentialsException
import io.github.devcavin.backend.common.exception.InvalidRefreshTokenException
import io.github.devcavin.backend.domain.model.RefreshToken
import io.github.devcavin.backend.domain.repository.RefreshTokenRepository
import io.github.devcavin.backend.domain.repository.UserRepository
import io.github.devcavin.backend.security.JwtProperties
import io.github.devcavin.backend.security.JwtTokenProvider
import io.github.devcavin.backend.web.dto.auth.AuthResponse
import io.github.devcavin.backend.web.dto.auth.LoginRequest
package io.github.devcavin.gatelog.backend.auth

import io.github.devcavin.gatelog.backend.auth.dto.AuthResponse
import io.github.devcavin.gatelog.backend.auth.dto.LoginRequest
import io.github.devcavin.gatelog.backend.common.exception.AccountDisabledException
import io.github.devcavin.gatelog.backend.common.exception.InvalidCredentialsException
import io.github.devcavin.gatelog.backend.common.exception.InvalidRefreshTokenException
import io.github.devcavin.gatelog.backend.users.UserRepository
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.devcavin.backend.security
package io.github.devcavin.gatelog.backend.auth

import io.github.devcavin.backend.domain.repository.UserRepository
import io.github.devcavin.gatelog.backend.users.UserRepository
import jakarta.servlet.FilterChain
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.devcavin.backend.security
package io.github.devcavin.gatelog.backend.auth

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.devcavin.backend.security
package io.github.devcavin.gatelog.backend.auth

import io.jsonwebtoken.Claims
import io.jsonwebtoken.JwtException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.devcavin.backend.domain.model
package io.github.devcavin.gatelog.backend.auth

import io.github.devcavin.gatelog.backend.common.persistence.BaseEntity
import io.github.devcavin.gatelog.backend.users.User
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.devcavin.backend.domain.repository
package io.github.devcavin.gatelog.backend.auth

import io.github.devcavin.backend.domain.model.RefreshToken
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.devcavin.backend.security
package io.github.devcavin.gatelog.backend.auth

import io.github.devcavin.backend.domain.repository.UserRepository
import io.github.devcavin.gatelog.backend.users.UserRepository
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetails
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.devcavin.gatelog.backend.auth.dto

import java.util.UUID

data class AuthenticatedUser(
val id: UUID,
val name: String,
val email: String,
val role: String,
val siteId: UUID
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.devcavin.backend.web.dto.auth
package io.github.devcavin.gatelog.backend.auth.dto

import jakarta.validation.constraints.Email
import jakarta.validation.constraints.NotBlank
import java.util.UUID

data class LoginRequest(
@field:Email
Expand All @@ -16,17 +15,4 @@ data class LoginRequest(
data class RefreshTokenRequest(
@field:NotBlank
val token: String
)

data class AuthenticatedUser(
val id: UUID,
val name: String,
val email: String,
val role: String,
val siteId: UUID
)

data class AuthResponse(
val accessToken: String,
val refreshToken: String
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.devcavin.gatelog.backend.auth.dto

data class AuthResponse(
val accessToken: String,
val refreshToken: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.devcavin.gatelog.backend.common.exception

import org.springframework.security.authentication.BadCredentialsException

// base type
sealed class DomainException(message: String) : RuntimeException(message)

// 401 — bad credentials or invalid/expired tokens
sealed class UnauthorizedException(message: String): io.github.devcavin.gatelog.backend.common.exception.DomainException(message)

class InvalidCredentialsException : BadCredentialsException("Invalid username or password")

class InvalidRefreshTokenException : BadCredentialsException("Invalid or expired refresh token")

// 403 - authenticated but !permitted
class AccountDisabledException : io.github.devcavin.gatelog.backend.common.exception.DomainException("Account is disabled")

// 404 - resource !found
class ResourceNotFoundException(resource: String, id: Any) : io.github.devcavin.gatelog.backend.common.exception.DomainException("Resource $resource not found: $id")

// 409 - conflicts with existing state/resources, etc...
class ConflictException(message: String) : io.github.devcavin.gatelog.backend.common.exception.DomainException(message)

// 422 - semantically invalid request (e.g. checking out already checked out visitor)
class InvalidStateException(message: String) : io.github.devcavin.gatelog.backend.common.exception.DomainException(message)

class AccessDeniedException(message: String) : RuntimeException(message)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.devcavin.backend.web.error
package io.github.devcavin.gatelog.backend.common.exception

import java.time.OffsetDateTime

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.devcavin.backend.web.error
package io.github.devcavin.gatelog.backend.common.exception

import io.github.devcavin.backend.common.exception.*
import jakarta.servlet.http.HttpServletRequest
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
Expand Down Expand Up @@ -49,13 +48,15 @@ class GlobalExceptionHandler {

return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(ErrorResponse(
status = HttpStatus.BAD_REQUEST.value(),
error = HttpStatus.BAD_REQUEST.reasonPhrase,
message = "Validation failed",
path = request.requestURI,
fieldErrors = fieldErrors
))
.body(
ErrorResponse(
status = HttpStatus.BAD_REQUEST.value(),
error = HttpStatus.BAD_REQUEST.reasonPhrase,
message = "Validation failed",
path = request.requestURI,
fieldErrors = fieldErrors
)
)
}

@ExceptionHandler(BadCredentialsException::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.devcavin.backend.domain.model
package io.github.devcavin.gatelog.backend.common.persistence

import jakarta.persistence.MappedSuperclass
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.devcavin.backend.security
package io.github.devcavin.gatelog.backend.config

import io.github.devcavin.gatelog.backend.auth.JwtAuthenticationFilter
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down
Loading
Loading