Skip to content

Commit

Permalink
fix: Prevent query validation on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Sep 9, 2024
1 parent 16d764c commit dcf1dec
Show file tree
Hide file tree
Showing 61 changed files with 144 additions and 563 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.tolgee.security.authentication.JwtService
import io.tolgee.security.authentication.TolgeeAuthentication
import io.tolgee.service.security.SecurityService
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Lazy
import org.springframework.messaging.Message
import org.springframework.messaging.MessageChannel
import org.springframework.messaging.MessagingException
Expand All @@ -21,7 +22,9 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerCo
@Configuration
@EnableWebSocketMessageBroker
class WebSocketConfig(
@Lazy
private val jwtService: JwtService,
@Lazy
private val securityService: SecurityService,
) : WebSocketMessageBrokerConfigurer {
override fun configureMessageBroker(config: MessageBrokerRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Lazy
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.security.config.Customizer
Expand All @@ -46,12 +47,19 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@Configuration
@EnableWebSecurity
class WebSecurityConfig(
@Lazy
private val authenticationFilter: AuthenticationFilter,
@Lazy
private val globalIpRateLimitFilter: GlobalIpRateLimitFilter,
@Lazy
private val globalUserRateLimitFilter: GlobalUserRateLimitFilter,
@Lazy
private val rateLimitInterceptor: RateLimitInterceptor,
@Lazy
private val authenticationInterceptor: AuthenticationInterceptor,
@Lazy
private val organizationAuthorizationInterceptor: OrganizationAuthorizationInterceptor,
@Lazy
private val projectAuthorizationInterceptor: ProjectAuthorizationInterceptor,
private val exceptionHandlerFilter: ExceptionHandlerFilter,
) : WebMvcConfigurer {
Expand Down
8 changes: 8 additions & 0 deletions backend/app/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ spring:
enableLazyInitialization: true
enableDirtyTracking: true
dialect: io.tolgee.dialects.postgres.CustomPostgreSQLDialect
# javax:
# persistence:
# validation:
# mode: none
# jakarta:
# persistence:
# validation:
# mode: none
mvc:
pathmatch:
matching-strategy: ant_path_matcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ import io.tolgee.util.addSeconds
import io.tolgee.util.logger
import io.tolgee.util.runSentryCatching
import jakarta.persistence.EntityManager
import org.springframework.context.annotation.Lazy
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

@Component
class ScheduledJobCleaner(
@Lazy
private val batchJobService: BatchJobService,
@Lazy
private val lockingManager: BatchJobProjectLockingManager,
private val currentDateProvider: CurrentDateProvider,
@Lazy
private val batchJobStateProvider: BatchJobStateProvider,
private val entityManager: EntityManager,
@Lazy
private val cachingBatchJobService: CachingBatchJobService,
@Lazy
private val batchJobStatusProvider: BatchJobStatusProvider,
) : Logging {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package io.tolgee.repository
import io.tolgee.model.DismissedAnnouncement
import io.tolgee.model.DismissedAnnouncementId
import io.tolgee.model.enums.announcement.Announcement
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface AnnouncementRepository : JpaRepository<DismissedAnnouncement, DismissedAnnouncementId> {
@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.tolgee.repository

import io.tolgee.model.ApiKey
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.EntityGraph
Expand All @@ -11,6 +12,7 @@ import org.springframework.stereotype.Repository
import java.util.*

@Repository
@Lazy
interface ApiKeyRepository : JpaRepository<ApiKey, Long> {
fun findByKeyHash(hash: String): Optional<ApiKey>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package io.tolgee.repository

import io.tolgee.model.AutoTranslationConfig
import io.tolgee.model.Project
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface AutoTranslationConfigRepository : JpaRepository<AutoTranslationConfig, Long> {
fun findOneByProjectAndTargetLanguageId(
project: Project,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.tolgee.repository

import io.tolgee.model.automations.Automation
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface AutomationRepository : JpaRepository<Automation?, Long?> {
@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.tolgee.repository
import io.tolgee.model.batch.BatchJob
import io.tolgee.model.batch.BatchJobStatus
import io.tolgee.model.views.JobErrorMessagesView
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -11,6 +12,7 @@ import org.springframework.stereotype.Repository
import java.util.*

@Repository
@Lazy
interface BatchJobRepository : JpaRepository<BatchJob, Long> {
@Query(
value = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.tolgee.repository

import io.tolgee.model.EmailVerification
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface EmailVerificationRepository : JpaRepository<EmailVerification, Long>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package io.tolgee.repository
import io.tolgee.model.Invitation
import io.tolgee.model.Organization
import io.tolgee.model.Project
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import java.util.*

@Repository
@Lazy
interface InvitationRepository : JpaRepository<Invitation?, Long?> {
fun deleteAllByCreatedAtLessThan(date: Date)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.tolgee.repository

import io.tolgee.model.key.KeyCodeReference
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional

@Repository
@Lazy
interface KeyCodeReferenceRepository : JpaRepository<KeyCodeReference, Long> {
@Modifying
@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.tolgee.repository

import io.tolgee.model.key.KeyComment
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional

@Repository
@Lazy
interface KeyCommentRepository : JpaRepository<KeyComment?, Long?> {
@Modifying
@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.tolgee.repository

import io.tolgee.model.key.KeyMeta
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional

@Repository
@Lazy
interface KeyMetaRepository : JpaRepository<KeyMeta?, Long?> {
@Modifying
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.tolgee.dtos.queryResults.KeyView
import io.tolgee.model.Language
import io.tolgee.model.key.Key
import io.tolgee.service.key.KeySearchResultView
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -12,6 +13,7 @@ import org.springframework.stereotype.Repository
import java.util.*

@Repository
@Lazy
interface KeyRepository : JpaRepository<Key, Long> {
@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import io.tolgee.model.Screenshot
import io.tolgee.model.key.Key
import io.tolgee.model.key.screenshotReference.KeyScreenshotReference
import io.tolgee.model.key.screenshotReference.KeyScreenshotReferenceId
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface KeyScreenshotReferenceRepository : JpaRepository<KeyScreenshotReference, KeyScreenshotReferenceId> {
fun getAllByScreenshot(screenshot: Screenshot): List<KeyScreenshotReference>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package io.tolgee.repository

import io.tolgee.model.keyBigMeta.KeysDistance
import io.tolgee.service.key.KeyWithBaseTranslationView
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface KeysDistanceRepository : JpaRepository<KeysDistance, Long> {
@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.tolgee.repository

import io.tolgee.dtos.cacheable.LanguageDto
import io.tolgee.model.Language
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -10,6 +11,7 @@ import org.springframework.stereotype.Repository
import java.util.*

@Repository
@Lazy
interface LanguageRepository : JpaRepository<Language, Long> {
@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package io.tolgee.repository

import io.tolgee.dtos.queryResults.LanguageStatsDto
import io.tolgee.model.LanguageStats
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional

@Repository
@Lazy
interface LanguageStatsRepository : JpaRepository<LanguageStats, Long> {
@Modifying
@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.tolgee.repository

import io.tolgee.model.key.Namespace
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -9,6 +10,7 @@ import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface NamespaceRepository : JpaRepository<Namespace, Long> {
fun findByNameAndProjectId(
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import io.tolgee.dtos.queryResults.organization.OrganizationView
import io.tolgee.model.Organization
import io.tolgee.model.UserAccount
import io.tolgee.model.enums.OrganizationRoleType
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface OrganizationRepository : JpaRepository<Organization, Long> {
@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package io.tolgee.repository
import io.tolgee.model.Organization
import io.tolgee.model.OrganizationRole
import io.tolgee.model.enums.OrganizationRoleType
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface OrganizationRoleRepository : JpaRepository<OrganizationRole, Long> {
fun findOneByUserIdAndOrganizationId(
userId: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.tolgee.repository

import io.tolgee.model.Pat
import org.springframework.context.annotation.Lazy
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import java.util.*

@Repository
@Lazy
interface PatRepository : JpaRepository<Pat, Long> {
fun findByTokenHash(tokenHash: String): Pat?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package io.tolgee.repository

import io.tolgee.model.Language
import io.tolgee.model.Permission
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
@Lazy
interface PermissionRepository : JpaRepository<Permission, Long> {
@Query(
"""
Expand Down
Loading

0 comments on commit dcf1dec

Please sign in to comment.