Skip to content

Commit

Permalink
repackaging
Browse files Browse the repository at this point in the history
ticket jdbc repo
  • Loading branch information
mrFlick72 committed Oct 25, 2024
1 parent 9dfca20 commit 5f0729c
Show file tree
Hide file tree
Showing 32 changed files with 316 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.vauthenticator.server.communication.domain.EMailSenderService
import com.vauthenticator.server.mfa.domain.MfaMethod
import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollment
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.ticket.Ticket
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_VALUE
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_VALUE
import com.vauthenticator.server.ticket.domain.TicketId
import org.slf4j.LoggerFactory

private const val LINK_KEY = "verificationEMailLink"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.vauthenticator.server.account.emailverification
import com.vauthenticator.server.account.Account
import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollmentAssociation
import com.vauthenticator.server.ticket.InvalidTicketException
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.InvalidTicketException
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository

class VerifyEMailChallenge(
private val ticketRepository: TicketRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.vauthenticator.server.communication.domain.SimpleEMailMessageFactory
import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollment
import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollmentAssociation
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.TicketRepository
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.vauthenticator.server.password.PasswordPolicy
import com.vauthenticator.server.password.VAuthenticatorPasswordEncoder
import com.vauthenticator.server.password.resetpassword.ResetAccountPassword
import com.vauthenticator.server.password.resetpassword.SendResetPasswordMailChallenge
import com.vauthenticator.server.ticket.TicketCreator
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.TicketCreator
import com.vauthenticator.server.ticket.domain.TicketRepository
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.vauthenticator.server.config

import com.vauthenticator.server.ticket.DynamoDbTicketRepository
import com.vauthenticator.server.ticket.TicketCreator
import com.vauthenticator.server.ticket.TicketFeatures
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.adapter.dynamodb.DynamoDbTicketRepository
import com.vauthenticator.server.ticket.domain.TicketCreator
import com.vauthenticator.server.ticket.domain.TicketFeatures
import com.vauthenticator.server.ticket.domain.TicketRepository
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/vauthenticator/server/mfa/MfaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import com.vauthenticator.server.mask.SensitiveEmailMasker
import com.vauthenticator.server.mask.SensitivePhoneMasker
import com.vauthenticator.server.mfa.adapter.dynamodb.DynamoMfaAccountMethodsRepository
import com.vauthenticator.server.mfa.domain.*
import com.vauthenticator.server.ticket.TicketCreator
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.TicketCreator
import com.vauthenticator.server.ticket.domain.TicketRepository
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.vauthenticator.server.account.AccountNotFoundException
import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.mask.SensitiveDataMaskerResolver
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.ticket.TicketContext
import com.vauthenticator.server.ticket.TicketCreator
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.TicketContext
import com.vauthenticator.server.ticket.domain.TicketCreator
import com.vauthenticator.server.ticket.domain.TicketId
import org.slf4j.LoggerFactory

class MfaMethodsEnrollment(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.vauthenticator.server.mfa.domain

import com.vauthenticator.server.ticket.InvalidTicketException
import com.vauthenticator.server.ticket.Ticket
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.InvalidTicketException
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository

typealias MfaAssociationVerifier = (ticket: Ticket) -> Unit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.password.Password
import com.vauthenticator.server.password.PasswordPolicy
import com.vauthenticator.server.password.VAuthenticatorPasswordEncoder
import com.vauthenticator.server.ticket.InvalidTicketException
import com.vauthenticator.server.ticket.Ticket
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.InvalidTicketException
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository
import java.time.Instant
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.vauthenticator.server.i18n.I18nScope
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.TicketId
import jakarta.servlet.http.HttpSession
import org.springframework.http.ResponseEntity
import org.springframework.http.ResponseEntity.noContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.vauthenticator.server.password.resetpassword
import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.communication.domain.EMailSenderService
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.ticket.TicketCreator
import com.vauthenticator.server.ticket.domain.TicketCreator

class SendResetPasswordMailChallenge(
private val accountRepository: AccountRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.vauthenticator.server.ticket
package com.vauthenticator.server.ticket.adapter.dynamodb

import com.vauthenticator.server.extentions.*
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.TicketContext
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.vauthenticator.server.ticket.adapter.jdbc

import com.fasterxml.jackson.databind.ObjectMapper
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.TicketContext
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository
import org.springframework.jdbc.core.JdbcTemplate
import java.util.*

class JdbcTicketRepository(
private val jdbcTemplate: JdbcTemplate,
private val objectMapper: ObjectMapper
) : TicketRepository {

override fun store(ticket: Ticket) {
jdbcTemplate.update(
"INSERT INTO TICKET (ticket, ttl, user_name, client_application_id, context) VALUES (?,?,?,?,?)",
ticket.ticketId.content,
ticket.ttl,
ticket.userName,
ticket.clientAppId,
objectMapper.writeValueAsString(ticket.context.content)
)
}


override fun loadFor(ticketId: TicketId): Optional<Ticket> {
val queryResult = jdbcTemplate.query(
"SELECT * FROM TICKET WHERE ticket = ?",
{ rs, _ ->
Ticket(
ticketId = TicketId(rs.getString("ticket")),
ttl = rs.getLong("ttl"),
userName = rs.getString("user_name"),
clientAppId = rs.getString("client_application_id"),
context = TicketContext(
objectMapper.readValue(
rs.getString("context"),
Map::class.java
) as Map<String, String>
)

)
},
ticketId.content
)

return if (queryResult.isEmpty()) {
Optional.empty()
} else {
Optional.of(queryResult.first())
}
}

override fun delete(ticketId: TicketId) {
jdbcTemplate.update("DELETE FROM TICKET WHERE ticket=?", ticketId.content)
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.vauthenticator.server.ticket
package com.vauthenticator.server.ticket.domain

import com.vauthenticator.server.mfa.domain.MfaDeviceId
import com.vauthenticator.server.mfa.domain.MfaMethod
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_CHANNEL_CONTEXT_KEY
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_DEVICE_ID_CONTEXT_KEY
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_METHOD_CONTEXT_KEY
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_NOT_SELF_ASSOCIATION_CONTEXT_VALUE
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_KEY
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_VALUE
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_CHANNEL_CONTEXT_KEY
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_DEVICE_ID_CONTEXT_KEY
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_METHOD_CONTEXT_KEY
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_NOT_SELF_ASSOCIATION_CONTEXT_VALUE
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_KEY
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_VALUE
import java.time.Duration

data class Ticket(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vauthenticator.server.ticket
package com.vauthenticator.server.ticket.domain

import com.vauthenticator.server.account.Account
import com.vauthenticator.server.extentions.expirationTimeStampInSecondFromNow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vauthenticator.server.ticket
package com.vauthenticator.server.ticket.domain

import java.util.*

Expand Down
13 changes: 11 additions & 2 deletions src/main/resources/data/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ CREATE TABLE KEYS
key_type varchar(255) not null,
encrypted_private_key text,
public_key text,
enabled boolean not null default false,
key_expiration_date_timestamp bigint not null default 0
enabled boolean not null default false,
key_expiration_date_timestamp bigint not null default 0
);

CREATE INDEX keys_key_purpose ON KEYS (key_purpose);

CREATE TABLE TICKET
(
ticket varchar(255) not null primary key,
ttl bigint not null default 0,
user_name varchar(255) not null,
client_application_id varchar(255) not null,
context text not null default '{}'
);

CREATE TABLE CLIENT_APPLICATION
(
client_app_id varchar(255) not null PRIMARY KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import com.vauthenticator.server.support.ClientAppFixture.aClientApp
import com.vauthenticator.server.ticket.Ticket
import com.vauthenticator.server.ticket.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_VALUE
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.Ticket.Companion.MFA_SELF_ASSOCIATION_CONTEXT_VALUE
import com.vauthenticator.server.ticket.domain.TicketId
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollmentAssociation
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.support.AccountTestFixture
import com.vauthenticator.server.support.TicketFixture
import com.vauthenticator.server.ticket.InvalidTicketException
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.InvalidTicketException
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.AccountTestFixture
import com.vauthenticator.server.support.MfaFixture.mfaDeviceId
import com.vauthenticator.server.support.SecurityFixture.principalFor
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.web.ExceptionAdviceController
import io.mockk.every
import io.mockk.impl.annotations.MockK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.vauthenticator.server.keys.domain.Kid
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.support.AccountTestFixture
import com.vauthenticator.server.support.TicketFixture
import com.vauthenticator.server.ticket.InvalidTicketException
import com.vauthenticator.server.ticket.Ticket
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.InvalidTicketException
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.vauthenticator.server.support.MfaFixture.email
import com.vauthenticator.server.support.MfaFixture.mfaDeviceId
import com.vauthenticator.server.support.MfaFixture.notAssociatedMfaAccountMethod
import com.vauthenticator.server.support.TicketFixture.ticketContext
import com.vauthenticator.server.ticket.TicketCreator
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.TicketCreator
import com.vauthenticator.server.ticket.domain.TicketId
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import com.vauthenticator.server.password.PasswordPolicy
import com.vauthenticator.server.password.VAuthenticatorPasswordEncoder
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import com.vauthenticator.server.support.TicketFixture
import com.vauthenticator.server.ticket.InvalidTicketException
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.TicketRepository
import com.vauthenticator.server.ticket.domain.InvalidTicketException
import com.vauthenticator.server.ticket.domain.TicketId
import com.vauthenticator.server.ticket.domain.TicketRepository
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.vauthenticator.server.support.ClientAppFixture.aClientApp
import com.vauthenticator.server.support.EMAIL
import com.vauthenticator.server.support.SecurityFixture.principalFor
import com.vauthenticator.server.support.VAUTHENTICATOR_ADMIN
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.TicketId
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.communication.domain.EMailSenderService
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import com.vauthenticator.server.ticket.TicketCreator
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.TicketCreator
import com.vauthenticator.server.ticket.domain.TicketId
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object JdbcUtils {
jdbcTemplate.execute("DROP TABLE IF EXISTS ACCOUNT CASCADE;")
jdbcTemplate.execute("DROP TABLE IF EXISTS ACCOUNT_ROLE;")
jdbcTemplate.execute("DROP TABLE IF EXISTS KEYS;")
jdbcTemplate.execute("DROP TABLE IF EXISTS TICKET;")
jdbcTemplate.execute("DROP TABLE IF EXISTS oauth2_authorization;")
jdbcTemplate.execute(Files.readString(Paths.get("src/main/resources/data/schema.sql")))
} catch (e: java.lang.Exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.vauthenticator.server.support

import com.vauthenticator.server.mfa.domain.MfaMethod
import com.vauthenticator.server.ticket.Ticket
import com.vauthenticator.server.ticket.TicketContext
import com.vauthenticator.server.ticket.TicketId
import com.vauthenticator.server.ticket.domain.Ticket
import com.vauthenticator.server.ticket.domain.TicketContext
import com.vauthenticator.server.ticket.domain.TicketId

object TicketFixture {

Expand Down
Loading

0 comments on commit 5f0729c

Please sign in to comment.