Compare commits
No commits in common. "a5c570ec42f4eb856899520b62605971854544fd" and "1549abfac4725420685f434f8108d1195b94e6bb" have entirely different histories.
a5c570ec42
...
1549abfac4
@ -34,7 +34,6 @@ dependencies {
|
|||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation("org.springframework.security:spring-security-test")
|
||||||
testImplementation("org.testcontainers:postgresql")
|
testImplementation("org.testcontainers:postgresql")
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
implementation("org.yaml:snakeyaml")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,10 @@
|
|||||||
package ru.vyatsu.qr_access_api.controller
|
package ru.vyatsu.qr_access_api.controller
|
||||||
|
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.web.bind.annotation.RestController
|
|
||||||
import ru.vyatsu.apis.QrApi
|
import ru.vyatsu.apis.QrApi
|
||||||
import ru.vyatsu.models.QrCodesResponse
|
import ru.vyatsu.models.QrCodesResponse
|
||||||
import ru.vyatsu.qr_access_api.service.QrSyncService
|
import ru.vyatsu.qr_access_api.service.QrSyncService
|
||||||
|
|
||||||
@RestController
|
|
||||||
class QrSyncController(val syncService: QrSyncService) : QrApi {
|
class QrSyncController(val syncService: QrSyncService) : QrApi {
|
||||||
|
|
||||||
override fun getQrCodes(): ResponseEntity<QrCodesResponse> =
|
override fun getQrCodes(): ResponseEntity<QrCodesResponse> =
|
||||||
|
@ -9,8 +9,8 @@ import java.util.*
|
|||||||
private const val GET_ACTUAL_QRS_BY_UNIT_ID = """
|
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
|
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 doors d ON (d.id = q.door_id)
|
||||||
JOIN oauth2_registered_client c ON (c.client_id = d.unit_id)
|
JOIN oauth2_registered_client c ON (c.id = d.unit_id)
|
||||||
WHERE c.client_id = ? AND q.start_date_time <= CURRENT_TIMESTAMP AND q.end_date_time >= CURRENT_TIMESTAMP
|
WHERE c.id = ? AND q.start_date_time <= CURRENT_TIMESTAMP AND q.end_date_time >= CURRENT_TIMESTAMP
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ru.vyatsu.qr_access_api.service
|
package ru.vyatsu.qr_access_api.service
|
||||||
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import ru.vyatsu.models.QrCode
|
import ru.vyatsu.models.QrCode
|
||||||
import ru.vyatsu.qr_access_api.repository.QrRepository
|
import ru.vyatsu.qr_access_api.repository.QrRepository
|
||||||
@ -8,7 +7,8 @@ import ru.vyatsu.qr_access_api.repository.QrRepository
|
|||||||
@Service
|
@Service
|
||||||
class QrSyncService(val qrRepository: QrRepository) {
|
class QrSyncService(val qrRepository: QrRepository) {
|
||||||
fun getQrCodes(): List<QrCode> {
|
fun getQrCodes(): List<QrCode> {
|
||||||
val sc = SecurityContextHolder.getContext()
|
// TODO: Тут логика с извлечением клайма из jwt в котором идентификатор клиента лежит
|
||||||
return qrRepository.getActualQrCodesByUnitId(sc.authentication.name)
|
val extractedUnitId = "945c8621-9adc-4a49-bc56-10253d27c581"
|
||||||
|
return qrRepository.getActualQrCodesByUnitId(extractedUnitId)
|
||||||
}
|
}
|
||||||
}
|
}
|
4
src/main/resources/application.properties
Normal file
4
src/main/resources/application.properties
Normal 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
|
@ -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
|
|
@ -16,7 +16,6 @@ databaseChangeLog:
|
|||||||
- column:
|
- column:
|
||||||
constraints:
|
constraints:
|
||||||
nullable: false
|
nullable: false
|
||||||
unique: true
|
|
||||||
name: client_id
|
name: client_id
|
||||||
type: VARCHAR(100)
|
type: VARCHAR(100)
|
||||||
- column:
|
- column:
|
||||||
@ -120,5 +119,5 @@ databaseChangeLog:
|
|||||||
baseColumnNames: unit_id
|
baseColumnNames: unit_id
|
||||||
baseTableName: doors
|
baseTableName: doors
|
||||||
constraintName: FK_unit_door
|
constraintName: FK_unit_door
|
||||||
referencedColumnNames: client_id
|
referencedColumnNames: id
|
||||||
referencedTableName: oauth2_registered_client
|
referencedTableName: oauth2_registered_client
|
Loading…
Reference in New Issue
Block a user