Compare commits

..

No commits in common. "a5c570ec42f4eb856899520b62605971854544fd" and "1549abfac4725420685f434f8108d1195b94e6bb" have entirely different histories.

8 changed files with 10 additions and 42 deletions

View File

@ -34,7 +34,6 @@ dependencies {
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.testcontainers:postgresql")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
implementation("org.yaml:snakeyaml")
}
kotlin {

View File

@ -1,20 +0,0 @@
package ru.vyatsu.qr_access_api.config
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.Customizer
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.web.SecurityFilterChain
@Configuration
@EnableWebSecurity
class SecurityConfig {
@Bean
fun defaultSecurityFilterChain(http: HttpSecurity): SecurityFilterChain {
return http.authorizeHttpRequests { it.anyRequest().authenticated() }
.oauth2ResourceServer { it.jwt(Customizer.withDefaults()) }
.build()
}
}

View File

@ -1,12 +1,10 @@
package ru.vyatsu.qr_access_api.controller
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
import ru.vyatsu.apis.QrApi
import ru.vyatsu.models.QrCodesResponse
import ru.vyatsu.qr_access_api.service.QrSyncService
@RestController
class QrSyncController(val syncService: QrSyncService) : QrApi {
override fun getQrCodes(): ResponseEntity<QrCodesResponse> =

View File

@ -9,8 +9,8 @@ import java.util.*
private const val GET_ACTUAL_QRS_BY_UNIT_ID = """
SELECT q.start_date_time, q.end_date_time, q.door_id, q.key_code FROM qrs q
JOIN doors d ON (d.id = q.door_id)
JOIN oauth2_registered_client c ON (c.client_id = d.unit_id)
WHERE c.client_id = ? AND q.start_date_time <= CURRENT_TIMESTAMP AND q.end_date_time >= CURRENT_TIMESTAMP
JOIN oauth2_registered_client c ON (c.id = d.unit_id)
WHERE c.id = ? AND q.start_date_time <= CURRENT_TIMESTAMP AND q.end_date_time >= CURRENT_TIMESTAMP
"""
@Repository

View File

@ -1,6 +1,5 @@
package ru.vyatsu.qr_access_api.service
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.stereotype.Service
import ru.vyatsu.models.QrCode
import ru.vyatsu.qr_access_api.repository.QrRepository
@ -8,7 +7,8 @@ import ru.vyatsu.qr_access_api.repository.QrRepository
@Service
class QrSyncService(val qrRepository: QrRepository) {
fun getQrCodes(): List<QrCode> {
val sc = SecurityContextHolder.getContext()
return qrRepository.getActualQrCodesByUnitId(sc.authentication.name)
// TODO: Тут логика с извлечением клайма из jwt в котором идентификатор клиента лежит
val extractedUnitId = "945c8621-9adc-4a49-bc56-10253d27c581"
return qrRepository.getActualQrCodesByUnitId(extractedUnitId)
}
}

View File

@ -0,0 +1,4 @@
spring.application.name=qr-access-api
spring.datasource.url=jdbc:postgresql://localhost:5432/qr_access
spring.datasource.username=qr_access_user
spring.datasource.password=123

View File

@ -1,12 +0,0 @@
spring:
application:
name: qr-access-api
datasource:
url: jdbc:postgresql://localhost:5432/qr_access
username: qr_access_user
password: 123
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: http://localhost:8081/oauth2/jwks

View File

@ -16,7 +16,6 @@ databaseChangeLog:
- column:
constraints:
nullable: false
unique: true
name: client_id
type: VARCHAR(100)
- column:
@ -120,5 +119,5 @@ databaseChangeLog:
baseColumnNames: unit_id
baseTableName: doors
constraintName: FK_unit_door
referencedColumnNames: client_id
referencedColumnNames: id
referencedTableName: oauth2_registered_client