-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOKY-179 Create a temporary token to download file
Add JWT-based document download token generation Implemented functionality to generate and manage JWT tokens for authorizing document downloads. Added new endpoints, service methods, database entities, and repository support for this feature. Updated migrations to include download token handling in both MySQL and SQL Server schemas.
- Loading branch information
1 parent
536852a
commit 4e31e03
Showing
14 changed files
with
235 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app-server/src/main/kotlin/org/hkurh/doky/documents/api/DownloadTokenResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.hkurh.doky.documents.api | ||
|
||
/** | ||
* Represents the response containing a token used for authorizing a file download. | ||
* | ||
* @property token The token string used to authorize the download operation. | ||
*/ | ||
class DownloadTokenResponse(val token: String = "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
persistence/src/main/kotlin/org/hkurh/doky/documents/db/DownloadDocumentTokenEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.hkurh.doky.documents.db | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Index | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.OneToOne | ||
import jakarta.persistence.Table | ||
import jakarta.persistence.UniqueConstraint | ||
import org.hkurh.doky.users.db.UserEntity | ||
|
||
@Entity | ||
@Table( | ||
name = "download_document_tokens", | ||
indexes = [Index(name = "idx_download_document_tokens_token", columnList = "token")], | ||
uniqueConstraints = [ | ||
UniqueConstraint(name = "uc_download_document_tokens_token", columnNames = ["token"]), | ||
UniqueConstraint( | ||
name = "uc_download_document_tokens_app_user_document", | ||
columnNames = ["app_user", "document"] | ||
)] | ||
) | ||
class DownloadDocumentTokenEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", nullable = false, updatable = false) | ||
var id: Long? = null | ||
|
||
@OneToOne | ||
@JoinColumn(name = "app_user", nullable = false, unique = true) | ||
lateinit var user: UserEntity | ||
|
||
@OneToOne | ||
@JoinColumn(name = "document", nullable = false, unique = true) | ||
lateinit var document: DocumentEntity | ||
|
||
@Column(name = "token", nullable = false, unique = true) | ||
lateinit var token: String | ||
} |
19 changes: 19 additions & 0 deletions
19
...ence/src/main/kotlin/org/hkurh/doky/documents/db/DownloadDocumentTokenEntityRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.hkurh.doky.documents.db | ||
|
||
import org.hkurh.doky.users.db.UserEntity | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor | ||
import org.springframework.data.repository.CrudRepository | ||
|
||
|
||
/** | ||
* Repository interface for managing [DownloadDocumentTokenEntity] objects. | ||
* Provides methods for querying and persisting [DownloadDocumentTokenEntity] instances in the database. | ||
* Inherits functionality from [CrudRepository] for common CRUD operations and [JpaSpecificationExecutor] | ||
* for specification-based queries. | ||
*/ | ||
interface DownloadDocumentTokenEntityRepository : CrudRepository<DownloadDocumentTokenEntity?, Long?>, | ||
JpaSpecificationExecutor<DownloadDocumentTokenEntity?> { | ||
|
||
fun findByUserAndDocument(user: UserEntity, document: DocumentEntity): DownloadDocumentTokenEntity? | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
persistence/src/main/resources/migration/mysql/V1_5__add_document_download_tokens.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE TABLE download_document_tokens | ||
( | ||
id BIGINT AUTO_INCREMENT NOT NULL, | ||
app_user BIGINT NOT NULL, | ||
document BIGINT NOT NULL, | ||
token VARCHAR(255) NOT NULL, | ||
CONSTRAINT pk_download_document_tokens PRIMARY KEY (id) | ||
); | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT uc_download_document_tokens_app_user_document UNIQUE (app_user, document); | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT uc_download_document_tokens_token UNIQUE (token); | ||
|
||
CREATE INDEX idx_download_document_tokens_token ON download_document_tokens (token); | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT FK_DOWNLOAD_DOCUMENT_TOKENS_ON_APP_USER FOREIGN KEY (app_user) REFERENCES users (id); | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT FK_DOWNLOAD_DOCUMENT_TOKENS_ON_DOCUMENT FOREIGN KEY (document) REFERENCES documents (id); | ||
|
28 changes: 28 additions & 0 deletions
28
persistence/src/main/resources/migration/sqlserver/V1_5__add_document_download_tokens.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
CREATE TABLE download_document_tokens | ||
( | ||
id bigint IDENTITY (1, 1) NOT NULL, | ||
app_user bigint NOT NULL, | ||
document bigint NOT NULL, | ||
token varchar(255) NOT NULL, | ||
CONSTRAINT pk_download_document_tokens PRIMARY KEY (id) | ||
) | ||
GO | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT uc_download_document_tokens_app_user_document UNIQUE (app_user, document) | ||
GO | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT uc_download_document_tokens_token UNIQUE (token) | ||
GO | ||
|
||
CREATE NONCLUSTERED INDEX idx_download_document_tokens_token ON download_document_tokens (token) | ||
GO | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT FK_DOWNLOAD_DOCUMENT_TOKENS_ON_APP_USER FOREIGN KEY (app_user) REFERENCES users (id) | ||
GO | ||
|
||
ALTER TABLE download_document_tokens | ||
ADD CONSTRAINT FK_DOWNLOAD_DOCUMENT_TOKENS_ON_DOCUMENT FOREIGN KEY (document) REFERENCES documents (id) | ||
GO |