Skip to content

Commit

Permalink
repackaging
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFlick72 committed Oct 22, 2024
1 parent 5a60e17 commit ae703fd
Show file tree
Hide file tree
Showing 41 changed files with 83 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.vauthenticator.server.extentions.oauth2ClientId
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import jakarta.servlet.http.HttpSession
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vauthenticator.server.i18n.I18nMessageInjector
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.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import jakarta.servlet.http.HttpSession
import org.springframework.http.ResponseEntity
import org.springframework.http.ResponseEntity.badRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.vauthenticator.server.account.repository.dynamodb.DynamoAccountConver
import com.vauthenticator.server.account.repository.dynamodb.DynamoAccountQueryFactory.findAccountQueryForUserName
import com.vauthenticator.server.account.repository.dynamodb.DynamoAccountQueryFactory.storeAccountQueryFor
import com.vauthenticator.server.extentions.filterEmptyMetadata
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.domain.RoleRepository
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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.role.Role
import com.vauthenticator.server.role.domain.Role
import java.time.Instant

open class SignUpUse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.vauthenticator.server.account.welcome
import com.vauthenticator.server.account.AccountNotFoundException
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import jakarta.servlet.http.HttpSession
import org.springframework.http.ResponseEntity
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.vauthenticator.server.account.repository.dynamodb.DynamoDbAccountRepo
import com.vauthenticator.server.account.repository.jdbc.JdbcAccountRepository
import com.vauthenticator.server.cache.CacheOperation
import com.vauthenticator.server.cache.RedisCacheOperation
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.domain.RoleRepository
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.vauthenticator.server.cache.CacheOperation
import com.vauthenticator.server.cache.RedisCacheOperation
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.RoleCacheContentConverter
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.role.domain.RoleCacheContentConverter
import com.vauthenticator.server.role.adapter.CachedRoleRepository
import com.vauthenticator.server.role.adapter.dynamodb.DynamoDbRoleRepository
import com.vauthenticator.server.role.adapter.jdbc.JdbcRoleRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vauthenticator.server.mfa.domain.MfaChallengeSender
import com.vauthenticator.server.mfa.domain.MfaDeviceId
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import jakarta.servlet.http.HttpSession
import org.springframework.security.core.Authentication
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vauthenticator.server.extentions.clientAppId
import com.vauthenticator.server.mfa.domain.*
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.http.ResponseEntity.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vauthenticator.server.oauth2.clientapp.api

import com.vauthenticator.server.oauth2.clientapp.domain.*
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import org.springframework.http.ResponseEntity
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
import org.springframework.web.bind.annotation.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.vauthenticator.server.i18n.I18nMessageInjector
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.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.ticket.TicketId
import jakarta.servlet.http.HttpSession
import org.springframework.http.ResponseEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.vauthenticator.server.role.adapter

import com.vauthenticator.server.cache.CacheContentConverter
import com.vauthenticator.server.cache.CacheOperation
import com.vauthenticator.server.role.Role
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository

private const val ROLES_CACHE_KEY = "roles"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package com.vauthenticator.server.role
package com.vauthenticator.server.role.adapter.dynamodb

import com.vauthenticator.server.extentions.asDynamoAttribute
import com.vauthenticator.server.extentions.valueAsStringFor
import com.vauthenticator.server.role.domain.Role
import software.amazon.awssdk.services.dynamodb.model.AttributeValue
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest
import software.amazon.awssdk.services.dynamodb.model.ScanRequest

interface RoleRepository {

fun findAll(): List<Role>
fun save(role: Role)
fun delete(role: String)

}

object DynamoDbRoleMapper {
fun findAllRequestFor(tableName: String): ScanRequest =
ScanRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.vauthenticator.server.role.adapter.dynamodb

import com.vauthenticator.server.role.DynamoDbRoleMapper
import com.vauthenticator.server.role.ProtectedRoleFromDeletionException
import com.vauthenticator.server.role.Role
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.domain.ProtectedRoleFromDeletionException
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository
import software.amazon.awssdk.services.dynamodb.DynamoDbClient

class DynamoDbRoleRepository(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.vauthenticator.server.role.adapter.jdbc

import com.vauthenticator.server.role.ProtectedRoleFromDeletionException
import com.vauthenticator.server.role.Role
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.domain.ProtectedRoleFromDeletionException
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.transaction.annotation.Transactional

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.vauthenticator.server.role
package com.vauthenticator.server.role.api

import com.vauthenticator.server.role.domain.ProtectedRoleFromDeletionException
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.http.ResponseEntity.noContent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vauthenticator.server.role
package com.vauthenticator.server.role.domain

import com.vauthenticator.server.extentions.clientAppId
import com.vauthenticator.server.extentions.hasEnoughScopes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vauthenticator.server.role
package com.vauthenticator.server.role.domain

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.vauthenticator.server.role.domain

interface RoleRepository {

fun findAll(): List<Role>
fun save(role: Role)
fun delete(role: String)

}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import com.vauthenticator.server.support.ClientAppFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.vauthenticator.server.account.api

import com.vauthenticator.server.account.api.AdminApiAccountApiConverter.fromDomainToAccountAdminApiRepresentation
import com.vauthenticator.server.config.adminRole
import com.vauthenticator.server.role.Role
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import io.mockk.mockk
import org.junit.jupiter.api.Assertions.assertEquals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.vauthenticator.server.account.emailverification
import com.fasterxml.jackson.databind.ObjectMapper
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.EMAIL
import com.vauthenticator.server.support.SecurityFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.vauthenticator.server.account.repository

import com.vauthenticator.server.account.Account
import com.vauthenticator.server.account.AccountMandatoryAction.RESET_PASSWORD
import com.vauthenticator.server.role.Role
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.defaultRole
import com.vauthenticator.server.role.protectedRoleName
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.defaultRole
import com.vauthenticator.server.support.protectedRoleName
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.vauthenticator.server.account.repository.dynamodb

import com.vauthenticator.server.account.repository.AbstractAccountRepositoryTest
import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.protectedRoleNames
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.protectedRoleNames
import com.vauthenticator.server.role.adapter.dynamodb.DynamoDbRoleRepository
import com.vauthenticator.server.support.DynamoDbUtils.dynamoAccountTableName
import com.vauthenticator.server.support.DynamoDbUtils.dynamoDbClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.vauthenticator.server.account.repository.jdbc

import com.vauthenticator.server.account.repository.AbstractAccountRepositoryTest
import com.vauthenticator.server.account.repository.AccountRepository
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.protectedRoleNames
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.protectedRoleNames
import com.vauthenticator.server.role.adapter.jdbc.JdbcRoleRepository
import com.vauthenticator.server.support.JdbcUtils.jdbcTemplate
import com.vauthenticator.server.support.JdbcUtils.resetDb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.role.Role
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.support.AccountTestFixture.anAccount
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,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.vauthenticator.server.account.AccountNotFoundException
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.EMAIL
import com.vauthenticator.server.support.SecurityFixture.principalFor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vauthenticator.server.mfa.domain.MfaChallengeSender
import com.vauthenticator.server.mfa.domain.MfaDeviceId
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.AccountTestFixture.anAccount
import com.vauthenticator.server.support.SecurityFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.vauthenticator.server.mfa.domain.MfaDeviceId
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.oauth2.clientapp.domain.Scopes
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.AccountTestFixture
import com.vauthenticator.server.support.ClientAppFixture.aClientApp
import com.vauthenticator.server.support.ClientAppFixture.aClientAppId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.vauthenticator.server.mfa.domain.MfaMethod.EMAIL_MFA_METHOD
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.AccountTestFixture
import com.vauthenticator.server.support.MfaFixture.mfaDeviceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.vauthenticator.server.oauth2.clientapp.api

import com.fasterxml.jackson.databind.ObjectMapper
import com.vauthenticator.server.oauth2.clientapp.domain.*
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.ClientAppFixture.aClientApp
import com.vauthenticator.server.support.ClientAppFixture.aClientAppId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId
import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository
import com.vauthenticator.server.oauth2.clientapp.domain.Scope
import com.vauthenticator.server.role.PermissionValidator
import com.vauthenticator.server.role.domain.PermissionValidator
import com.vauthenticator.server.support.A_CLIENT_APP_ID
import com.vauthenticator.server.support.ClientAppFixture.aClientApp
import com.vauthenticator.server.support.EMAIL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.vauthenticator.server.role.adapter

import com.vauthenticator.server.role.ProtectedRoleFromDeletionException
import com.vauthenticator.server.role.Role
import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.domain.ProtectedRoleFromDeletionException
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package com.vauthenticator.server.role.adapter

import com.vauthenticator.server.cache.CacheContentConverter
import com.vauthenticator.server.cache.CacheOperation
import com.vauthenticator.server.role.*
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.adminRole
import com.vauthenticator.server.support.defaultRole
import com.vauthenticator.server.support.roles
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
@@ -1,28 +1,31 @@
package com.vauthenticator.server.role
package com.vauthenticator.server.role.adapter

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.vauthenticator.server.role.domain.Role
import com.vauthenticator.server.role.domain.RoleCacheContentConverter
import com.vauthenticator.server.support.JsonUtils.prettifyInOneLineJsonFrom
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

private const val testableResource = "roles/rolesSample.json"

private val roleList = listOf(Role("ROLE_1", "ROLE_1"), Role("ROLE_2", "ROLE_2"))
private val rawValue = prettifyInOneLineJsonFrom(testableResource)


class RoleCacheContentConverterTest {

private val underTest = RoleCacheContentConverter(jacksonObjectMapper())

@Test
fun `when a string value from the cache is deserialized`() {
val actual = underTest.getObjectFromCacheContentFor(rawValue)
assertEquals(roleList, actual)
Assertions.assertEquals(roleList, actual)
}

@Test
fun `when a role object is serialized as cached value`() {
val actual = underTest.loadableContentIntoCacheFor(roleList)
assertEquals(rawValue, actual)
Assertions.assertEquals(rawValue, actual)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vauthenticator.server.role.adapter.dynamodb

import com.vauthenticator.server.role.RoleRepository
import com.vauthenticator.server.role.protectedRoleNames
import com.vauthenticator.server.role.domain.RoleRepository
import com.vauthenticator.server.support.protectedRoleNames
import com.vauthenticator.server.role.adapter.AbstractRoleRepositoryTest
import com.vauthenticator.server.support.DynamoDbUtils.dynamoDbClient
import com.vauthenticator.server.support.DynamoDbUtils.dynamoRoleTableName
Expand Down
Loading

0 comments on commit ae703fd

Please sign in to comment.