forked from wine-area/DMS-Backend
-
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.
ㅍ
- Loading branch information
Showing
9 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
dms-core/src/main/kotlin/team/aliens/dms/common/model/SchoolSecret.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,9 @@ | ||
package team.aliens.dms.common.model | ||
|
||
import java.io.Serializable | ||
import java.util.UUID | ||
|
||
data class SchoolSecret( | ||
val schoolId: UUID, | ||
val secretKey: String | ||
) : Serializable |
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
11 changes: 11 additions & 0 deletions
11
dms-core/src/main/kotlin/team/aliens/dms/common/spi/SchoolSecretPort.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,11 @@ | ||
package team.aliens.dms.common.spi | ||
|
||
import java.util.UUID | ||
import team.aliens.dms.common.model.SchoolSecret | ||
|
||
interface SchoolSecretPort { | ||
|
||
fun saveSchoolSecret(schoolSecret: SchoolSecret) | ||
|
||
fun querySchoolSecretBySchoolId(schoolId: UUID): SchoolSecret? | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...ce/src/main/kotlin/team/aliens/dms/persistence/security/SchoolSecretPersistenceAdapter.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,28 @@ | ||
package team.aliens.dms.persistence.security | ||
|
||
import org.springframework.cache.annotation.Cacheable | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Component | ||
import team.aliens.dms.common.model.SchoolSecret | ||
import team.aliens.dms.common.spi.SchoolSecretPort | ||
import team.aliens.dms.persistence.security.mapper.SchoolSecretMapper | ||
import team.aliens.dms.persistence.security.repository.SchoolSecretJpaRepository | ||
import java.util.UUID | ||
|
||
@Component | ||
class SchoolSecretPersistenceAdapter( | ||
private val schoolSecretRepository: SchoolSecretJpaRepository, | ||
private val schoolSecretMapper: SchoolSecretMapper | ||
) : SchoolSecretPort { | ||
|
||
@Cacheable("schoolSecret") | ||
override fun querySchoolSecretBySchoolId(schoolId: UUID) = | ||
schoolSecretRepository.findByIdOrNull(schoolId) | ||
?.let { schoolSecretMapper.toDomain(it) } | ||
|
||
override fun saveSchoolSecret(schoolSecret: SchoolSecret) { | ||
schoolSecretRepository.save( | ||
schoolSecretMapper.toEntity(schoolSecret) | ||
) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ence/src/main/kotlin/team/aliens/dms/persistence/security/entity/SchoolSecretJpaEntity.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,32 @@ | ||
package team.aliens.dms.persistence.security.entity | ||
|
||
import team.aliens.dms.common.annotation.EncryptType | ||
import team.aliens.dms.common.annotation.EncryptedColumn | ||
import team.aliens.dms.persistence.school.entity.SchoolJpaEntity | ||
import java.util.UUID | ||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.FetchType | ||
import javax.persistence.Id | ||
import javax.persistence.JoinColumn | ||
import javax.persistence.MapsId | ||
import javax.persistence.OneToOne | ||
import javax.persistence.Table | ||
|
||
@Entity | ||
@Table(name = "tbl_school_secret") | ||
class SchoolSecretJpaEntity( | ||
|
||
@Id | ||
val schoolId: UUID, | ||
|
||
@MapsId | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "school_id", columnDefinition = "BINARY(16)", nullable = false) | ||
val school: SchoolJpaEntity?, | ||
|
||
@EncryptedColumn(type = EncryptType.ASYMMETRIC) | ||
@Column(columnDefinition = "TEXT", nullable = false) | ||
val secretKey: String | ||
|
||
) |
33 changes: 33 additions & 0 deletions
33
...istence/src/main/kotlin/team/aliens/dms/persistence/security/mapper/SchoolSecretMapper.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,33 @@ | ||
package team.aliens.dms.persistence.security.mapper | ||
|
||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Component | ||
import team.aliens.dms.common.model.SchoolSecret | ||
import team.aliens.dms.domain.school.exception.SchoolNotFoundException | ||
import team.aliens.dms.persistence.EncryptableGenericMapper | ||
import team.aliens.dms.persistence.school.repository.SchoolJpaRepository | ||
import team.aliens.dms.persistence.security.entity.SchoolSecretJpaEntity | ||
|
||
@Component | ||
class SchoolSecretMapper( | ||
private val schoolRepository: SchoolJpaRepository | ||
) : EncryptableGenericMapper<SchoolSecret, SchoolSecretJpaEntity> { | ||
|
||
override fun toDomain(entity: SchoolSecretJpaEntity?): SchoolSecret? { | ||
return entity?.let { | ||
SchoolSecret( | ||
schoolId = it.schoolId, | ||
secretKey = it.secretKey | ||
) | ||
} | ||
} | ||
|
||
override fun toEntity(domain: SchoolSecret): SchoolSecretJpaEntity { | ||
val school = schoolRepository.findByIdOrNull(domain.schoolId) ?: throw SchoolNotFoundException | ||
return SchoolSecretJpaEntity( | ||
schoolId = domain.schoolId, | ||
school = school, | ||
secretKey = domain.secretKey | ||
) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../main/kotlin/team/aliens/dms/persistence/security/repository/SchoolSecretJpaRepository.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,9 @@ | ||
package team.aliens.dms.persistence.security.repository | ||
|
||
import org.springframework.data.repository.CrudRepository | ||
import org.springframework.stereotype.Repository | ||
import team.aliens.dms.persistence.security.entity.SchoolSecretJpaEntity | ||
import java.util.UUID | ||
|
||
@Repository | ||
interface SchoolSecretJpaRepository : CrudRepository<SchoolSecretJpaEntity, UUID> |