Compare commits
	
		
			No commits in common. "e5d833846e9ab2e9d4f92191d9736fdd0b8a248d" and "1a0319e0b48e386684f3636b6402e440a53d2500" have entirely different histories.
		
	
	
		
			e5d833846e
			...
			1a0319e0b4
		
	
		
@ -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_authorized_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
 | 
			
		||||
            JOIN oauth2_authorized_client c ON (c.client_registration_id = d.unit_id AND c.principal_name = d.principal_name)
 | 
			
		||||
            WHERE c.client_registration_id = ? AND q.start_date_time <= CURRENT_TIMESTAMP AND q.end_date_time >= CURRENT_TIMESTAMP
 | 
			
		||||
            """
 | 
			
		||||
 | 
			
		||||
@Repository
 | 
			
		||||
 | 
			
		||||
@ -4,75 +4,63 @@ databaseChangeLog:
 | 
			
		||||
      author: d.krupin
 | 
			
		||||
      changes:
 | 
			
		||||
        - createTable:
 | 
			
		||||
            tableName: oauth2_registered_client
 | 
			
		||||
            tableName: oauth2_authorized_client
 | 
			
		||||
            columns:
 | 
			
		||||
              - column:
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
                    primaryKey: true
 | 
			
		||||
                    primaryKeyName: PK_oauth2_client
 | 
			
		||||
                  name: id
 | 
			
		||||
                  name: client_registration_id
 | 
			
		||||
                  type: VARCHAR(100)
 | 
			
		||||
              - column:
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    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)
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: client_id_issued_at
 | 
			
		||||
                  name: access_token_value
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: access_token_issued_at
 | 
			
		||||
                  type: TIMESTAMP
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: client_secret
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: client_secret_expires_at
 | 
			
		||||
                  name: access_token_expires_at
 | 
			
		||||
                  type: TIMESTAMP
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: client_name
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: client_authentication_methods
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: authorization_grant_types
 | 
			
		||||
                  name: access_token_scopes
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: true
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: redirect_uris
 | 
			
		||||
                  name: refresh_token_value
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: true
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: post_logout_redirect_uris
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  name: refresh_token_issued_at
 | 
			
		||||
                  type: TIMESTAMP
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
                    nullable: true
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: scopes
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: client_settings
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
              - column:
 | 
			
		||||
                  name: token_settings
 | 
			
		||||
                  type: TEXT
 | 
			
		||||
                  name: created_at
 | 
			
		||||
                  type: TIMESTAMP
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
                  defaultValueComputed: CURRENT_TIMESTAMP
 | 
			
		||||
        - createTable:
 | 
			
		||||
            tableName: doors
 | 
			
		||||
            columns:
 | 
			
		||||
@ -88,6 +76,11 @@ databaseChangeLog:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
                  name: unit_id
 | 
			
		||||
                  type: VARCHAR(100)
 | 
			
		||||
              - column:
 | 
			
		||||
                  constraints:
 | 
			
		||||
                    nullable: false
 | 
			
		||||
                  name: principal_name
 | 
			
		||||
                  type: VARCHAR(200)
 | 
			
		||||
        - createTable:
 | 
			
		||||
            tableName: qrs
 | 
			
		||||
            columns:
 | 
			
		||||
@ -116,8 +109,8 @@ databaseChangeLog:
 | 
			
		||||
                  name: end_date_time
 | 
			
		||||
                  type: TIMESTAMP WITH TIME ZONE
 | 
			
		||||
        - addForeignKeyConstraint:
 | 
			
		||||
            baseColumnNames: unit_id
 | 
			
		||||
            baseColumnNames: unit_id, principal_name
 | 
			
		||||
            baseTableName: doors
 | 
			
		||||
            constraintName: FK_unit_door
 | 
			
		||||
            referencedColumnNames: id
 | 
			
		||||
            referencedTableName: oauth2_registered_client
 | 
			
		||||
            referencedColumnNames: client_registration_id, principal_name
 | 
			
		||||
            referencedTableName: oauth2_authorized_client
 | 
			
		||||
@ -5,8 +5,8 @@ import java.time.LocalDateTime
 | 
			
		||||
import java.time.OffsetDateTime
 | 
			
		||||
 | 
			
		||||
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) 
 | 
			
		||||
       VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, to_json(?::json), to_json(?::json))"""
 | 
			
		||||
    """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 (?, ?, ?, ?, ?, ?, ?)"""
 | 
			
		||||
 | 
			
		||||
class InsertDatabaseHelper(private val template: JdbcTemplate) {
 | 
			
		||||
    fun insertQr(
 | 
			
		||||
@ -23,28 +23,23 @@ class InsertDatabaseHelper(private val template: JdbcTemplate) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun insertDoor(id: String, unitId: String): Int {
 | 
			
		||||
        return template.update("INSERT INTO doors(id, unit_id) VALUES (?, ?)") { ps ->
 | 
			
		||||
    fun insertDoor(id: String, unitId: String, principalName: String = ""): Int {
 | 
			
		||||
        return template.update("INSERT INTO doors(id, unit_id, principal_name) VALUES (?, ?, ?)") { ps ->
 | 
			
		||||
            ps.setString(1, id)
 | 
			
		||||
            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 ->
 | 
			
		||||
            ps.setString(1, id)
 | 
			
		||||
            ps.setString(2, id)
 | 
			
		||||
            ps.setObject(3, LocalDateTime.now())
 | 
			
		||||
            ps.setString(4, "secret")
 | 
			
		||||
            ps.setString(2, principalName)
 | 
			
		||||
            ps.setString(3, "Bearer")
 | 
			
		||||
            ps.setString(4, "Tokenasfgerseawvg")
 | 
			
		||||
            ps.setObject(5, LocalDateTime.now())
 | 
			
		||||
            ps.setString(6, id)
 | 
			
		||||
            ps.setString(7, "client_secret_post")
 | 
			
		||||
            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, "{}")
 | 
			
		||||
            ps.setObject(6, LocalDateTime.now())
 | 
			
		||||
            ps.setObject(7, LocalDateTime.now())
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user