Compare commits

..

No commits in common. "e5d833846e9ab2e9d4f92191d9736fdd0b8a248d" and "1a0319e0b48e386684f3636b6402e440a53d2500" have entirely different histories.

3 changed files with 46 additions and 58 deletions

View File

@ -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_authorized_client c ON (c.id = d.unit_id) JOIN oauth2_authorized_client c ON (c.client_registration_id = d.unit_id AND c.principal_name = d.principal_name)
WHERE c.id = ? AND q.start_date_time <= CURRENT_TIMESTAMP AND q.end_date_time >= CURRENT_TIMESTAMP WHERE c.client_registration_id = ? AND q.start_date_time <= CURRENT_TIMESTAMP AND q.end_date_time >= CURRENT_TIMESTAMP
""" """
@Repository @Repository

View File

@ -4,75 +4,63 @@ databaseChangeLog:
author: d.krupin author: d.krupin
changes: changes:
- createTable: - createTable:
tableName: oauth2_registered_client tableName: oauth2_authorized_client
columns: columns:
- column: - column:
constraints: constraints:
nullable: false nullable: false
primaryKey: true primaryKey: true
primaryKeyName: PK_oauth2_client primaryKeyName: PK_oauth2_client
name: id name: client_registration_id
type: VARCHAR(100) type: VARCHAR(100)
- column: - column:
constraints: constraints:
nullable: false nullable: false
name: client_id primaryKey: true
primaryKeyName: PK_oauth2_client
name: principal_name
type: VARCHAR(200)
- column:
name: access_token_type
type: VARCHAR(100) type: VARCHAR(100)
constraints:
nullable: false
- column: - column:
name: client_id_issued_at name: access_token_value
type: TEXT
constraints:
nullable: false
- column:
name: access_token_issued_at
type: TIMESTAMP type: TIMESTAMP
constraints: constraints:
nullable: false nullable: false
- column: - column:
name: client_secret name: access_token_expires_at
type: TEXT
constraints:
nullable: false
- column:
name: client_secret_expires_at
type: TIMESTAMP type: TIMESTAMP
constraints: constraints:
nullable: false nullable: false
- column: - column:
name: client_name name: access_token_scopes
type: TEXT
constraints:
nullable: false
- column:
name: client_authentication_methods
type: TEXT
constraints:
nullable: false
- column:
name: authorization_grant_types
type: TEXT type: TEXT
constraints: constraints:
nullable: true nullable: true
- column: - column:
name: redirect_uris name: refresh_token_value
type: TEXT type: TEXT
constraints: constraints:
nullable: true nullable: true
- column: - column:
name: post_logout_redirect_uris name: refresh_token_issued_at
type: TEXT type: TIMESTAMP
constraints: constraints:
nullable: false nullable: true
- column: - column:
name: scopes name: created_at
type: TEXT type: TIMESTAMP
constraints:
nullable: false
- column:
name: client_settings
type: TEXT
constraints:
nullable: false
- column:
name: token_settings
type: TEXT
constraints: constraints:
nullable: false nullable: false
defaultValueComputed: CURRENT_TIMESTAMP
- createTable: - createTable:
tableName: doors tableName: doors
columns: columns:
@ -88,6 +76,11 @@ databaseChangeLog:
nullable: false nullable: false
name: unit_id name: unit_id
type: VARCHAR(100) type: VARCHAR(100)
- column:
constraints:
nullable: false
name: principal_name
type: VARCHAR(200)
- createTable: - createTable:
tableName: qrs tableName: qrs
columns: columns:
@ -116,8 +109,8 @@ databaseChangeLog:
name: end_date_time name: end_date_time
type: TIMESTAMP WITH TIME ZONE type: TIMESTAMP WITH TIME ZONE
- addForeignKeyConstraint: - addForeignKeyConstraint:
baseColumnNames: unit_id baseColumnNames: unit_id, principal_name
baseTableName: doors baseTableName: doors
constraintName: FK_unit_door constraintName: FK_unit_door
referencedColumnNames: id referencedColumnNames: client_registration_id, principal_name
referencedTableName: oauth2_registered_client referencedTableName: oauth2_authorized_client

View File

@ -5,8 +5,8 @@ import java.time.LocalDateTime
import java.time.OffsetDateTime import java.time.OffsetDateTime
private const val INSERT_CLIENT_QUERY = private const val INSERT_CLIENT_QUERY =
"""INSERT INTO oauth2_authorized_client(id, client_id, client_id_issued_at, client_secret, client_secret_expires_at, client_name, client_authentication_methods, authorization_grant_types, redirect_uris, post_logout_redirect_uris, scopes, client_settings, token_settings) """INSERT INTO oauth2_authorized_client(client_registration_id, principal_name, access_token_type, access_token_value, access_token_issued_at, access_token_expires_at, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, to_json(?::json), to_json(?::json))""" VALUES (?, ?, ?, ?, ?, ?, ?)"""
class InsertDatabaseHelper(private val template: JdbcTemplate) { class InsertDatabaseHelper(private val template: JdbcTemplate) {
fun insertQr( fun insertQr(
@ -23,28 +23,23 @@ class InsertDatabaseHelper(private val template: JdbcTemplate) {
} }
} }
fun insertDoor(id: String, unitId: String): Int { fun insertDoor(id: String, unitId: String, principalName: String = ""): Int {
return template.update("INSERT INTO doors(id, unit_id) VALUES (?, ?)") { ps -> return template.update("INSERT INTO doors(id, unit_id, principal_name) VALUES (?, ?, ?)") { ps ->
ps.setString(1, id) ps.setString(1, id)
ps.setString(2, unitId) ps.setString(2, unitId)
ps.setString(3, principalName)
} }
} }
fun insertClient(id: String): Int { fun insertClient(id: String, principalName: String = ""): Int {
return template.update(INSERT_CLIENT_QUERY) { ps -> return template.update(INSERT_CLIENT_QUERY) { ps ->
ps.setString(1, id) ps.setString(1, id)
ps.setString(2, id) ps.setString(2, principalName)
ps.setObject(3, LocalDateTime.now()) ps.setString(3, "Bearer")
ps.setString(4, "secret") ps.setString(4, "Tokenasfgerseawvg")
ps.setObject(5, LocalDateTime.now()) ps.setObject(5, LocalDateTime.now())
ps.setString(6, id) ps.setObject(6, LocalDateTime.now())
ps.setString(7, "client_secret_post") ps.setObject(7, LocalDateTime.now())
ps.setString(8, "client_credentials")
ps.setString(9, "http://localhost:8080")
ps.setString(10, "http://localhost:8080")
ps.setString(11, "")
ps.setString(12, "{}")
ps.setString(13, "{}")
} }
} }
} }