diff --git a/cosec-api/build.gradle.kts b/cosec-api/build.gradle.kts new file mode 100644 index 00000000..b5c51aef --- /dev/null +++ b/cosec-api/build.gradle.kts @@ -0,0 +1,16 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +dependencies { + api("io.projectreactor:reactor-core") +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/CoSec.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/CoSec.kt similarity index 92% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/CoSec.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/CoSec.kt index ad27623e..b0464b19 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/CoSec.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/CoSec.kt @@ -10,9 +10,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec +package me.ahoo.cosec.api -import me.ahoo.cosec.internal.InternalIds +import me.ahoo.cosec.api.internal.InternalIds /** * CoSec const. diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/Named.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/Named.kt similarity index 96% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/Named.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/Named.kt index 2a0e05f7..dc49f526 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/Named.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/Named.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec +package me.ahoo.cosec.api /** * Named . diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/Authentication.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/Authentication.kt similarity index 92% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/Authentication.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/Authentication.kt index 082b4e7e..ad561edc 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/Authentication.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/Authentication.kt @@ -10,9 +10,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.authentication +package me.ahoo.cosec.api.authentication -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.CoSecPrincipal import reactor.core.publisher.Mono /** diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/AuthenticationProvider.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/AuthenticationProvider.kt similarity index 87% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/AuthenticationProvider.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/AuthenticationProvider.kt index ffef44b1..e416cef4 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/AuthenticationProvider.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/AuthenticationProvider.kt @@ -10,9 +10,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.authentication +package me.ahoo.cosec.api.authentication -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.CoSecPrincipal /** * Authentication Provider. @@ -38,9 +38,4 @@ interface AuthenticationProvider { ): A { return requireNotNull(get(credentialsType)) { "Can not found Authentication by credentialsType:[${credentialsType.name}]" } } - - companion object { - @JvmField - val DEFAULT: AuthenticationProvider = SimpleAuthenticationProvider - } } diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/Credentials.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/Credentials.kt similarity index 94% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/Credentials.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/Credentials.kt index cf8be312..66913ed0 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/Credentials.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authentication/Credentials.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.authentication +package me.ahoo.cosec.api.authentication /** * Credentials tag. diff --git a/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authorization/Authorization.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authorization/Authorization.kt new file mode 100644 index 00000000..8128402f --- /dev/null +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authorization/Authorization.kt @@ -0,0 +1,33 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.ahoo.cosec.api.authorization + +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import reactor.core.publisher.Mono + +/** + * The authorization refers to the process that determines what a user is allowed to do. + * + * @author ahoo wang + */ +fun interface Authorization { + /** + * 判断当前安全上下文(用户)是否具有该操作的权限. + * + * @param context Security Context + * @param request Request + * @return If true, the current user has access to the action. + */ + fun authorize(request: Request, context: SecurityContext): Mono +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/Authorization.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authorization/AuthorizeResult.kt similarity index 66% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/Authorization.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/authorization/AuthorizeResult.kt index 35df63d4..7d6ff73f 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/Authorization.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/authorization/AuthorizeResult.kt @@ -10,27 +10,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.authorization -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request -import reactor.core.publisher.Mono - -/** - * The authorization refers to the process that determines what a user is allowed to do. - * - * @author ahoo wang - */ -fun interface Authorization { - /** - * 判断当前安全上下文(用户)是否具有该操作的权限. - * - * @param context Security Context - * @param request Request - * @return If true, the current user has access to the action. - */ - fun authorize(request: Request, context: SecurityContext): Mono -} +package me.ahoo.cosec.api.authorization interface AuthorizeResult { val authorized: Boolean diff --git a/cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/SecurityContext.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/SecurityContext.kt new file mode 100644 index 00000000..5398a3d0 --- /dev/null +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/SecurityContext.kt @@ -0,0 +1,30 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.cosec.api.context + +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.tenant.TenantCapable + +interface SecurityContext : TenantCapable { + companion object { + const val KEY = "COSEC_SECURITY_CONTEXT" + } + + val principal: CoSecPrincipal + fun setAttribute(key: String, value: Any): SecurityContext + fun getAttribute(key: String): T? + fun getRequiredAttribute(key: String): T { + return requireNotNull(value = getAttribute(key)) { "The required attribute:$key is not found." } + } +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/Request.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/request/Request.kt similarity index 91% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/Request.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/request/Request.kt index 584109e2..cb19b4ff 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/Request.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/request/Request.kt @@ -11,9 +11,9 @@ * limitations under the License. */ -package me.ahoo.cosec.context.request +package me.ahoo.cosec.api.context.request -import me.ahoo.cosec.tenant.Tenant +import me.ahoo.cosec.api.tenant.Tenant interface Request : Tenant { /** diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/internal/InternalIds.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/internal/InternalIds.kt similarity index 97% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/internal/InternalIds.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/internal/InternalIds.kt index 5d05d213..724bf154 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/internal/InternalIds.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/internal/InternalIds.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.internal +package me.ahoo.cosec.api.internal /** * Internal Id Tool . diff --git a/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/ActionMatcher.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/ActionMatcher.kt new file mode 100644 index 00000000..ebfb012b --- /dev/null +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/ActionMatcher.kt @@ -0,0 +1,18 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.cosec.api.policy + +import me.ahoo.cosec.api.principal.RequestMatcher + +interface ActionMatcher : RequestMatcher diff --git a/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/ConditionMatcher.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/ConditionMatcher.kt new file mode 100644 index 00000000..9c3f37d1 --- /dev/null +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/ConditionMatcher.kt @@ -0,0 +1,18 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.cosec.api.policy + +import me.ahoo.cosec.api.principal.RequestMatcher + +interface ConditionMatcher : RequestMatcher diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Effect.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Effect.kt similarity index 95% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Effect.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Effect.kt index 759b5b95..97530d1e 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Effect.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Effect.kt @@ -11,7 +11,7 @@ * limitations under the License. */ -package me.ahoo.cosec.policy +package me.ahoo.cosec.api.policy enum class Effect { ALLOW, DENY diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PermissionVerifier.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PermissionVerifier.kt similarity index 86% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PermissionVerifier.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PermissionVerifier.kt index a4292707..d3dbd169 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PermissionVerifier.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PermissionVerifier.kt @@ -11,10 +11,10 @@ * limitations under the License. */ -package me.ahoo.cosec.policy +package me.ahoo.cosec.api.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request interface PermissionVerifier { fun verify(request: Request, securityContext: SecurityContext): VerifyResult diff --git a/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Policy.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Policy.kt new file mode 100644 index 00000000..5354b3f1 --- /dev/null +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Policy.kt @@ -0,0 +1,28 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.cosec.api.policy + +import me.ahoo.cosec.api.Named +import me.ahoo.cosec.api.tenant.Tenant + +/** + * Permission Policy + */ +interface Policy : Named, Tenant { + val id: String + val category: String + val description: String + val type: PolicyType + val statements: Set +} diff --git a/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PolicyEvaluator.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PolicyEvaluator.kt new file mode 100644 index 00000000..8597e4a0 --- /dev/null +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PolicyEvaluator.kt @@ -0,0 +1,18 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.cosec.api.policy + +interface PolicyEvaluator { + fun evaluate(policy: Policy) +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyType.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PolicyType.kt similarity index 96% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyType.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PolicyType.kt index feae6dd6..3bb64ef6 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyType.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/PolicyType.kt @@ -11,7 +11,7 @@ * limitations under the License. */ -package me.ahoo.cosec.policy +package me.ahoo.cosec.api.policy enum class PolicyType { /** diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Statement.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Statement.kt similarity index 81% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Statement.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Statement.kt index cd5b4a9e..2e2ef777 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Statement.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/policy/Statement.kt @@ -11,10 +11,10 @@ * limitations under the License. */ -package me.ahoo.cosec.policy +package me.ahoo.cosec.api.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request interface Statement : PermissionVerifier { val effect: Effect @@ -43,9 +43,3 @@ interface Statement : PermissionVerifier { } } } - -data class StatementData( - override val effect: Effect = Effect.ALLOW, - override val actions: Set = emptySet(), - override val conditions: Set = emptySet() -) : Statement diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/CoSecPrincipal.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/CoSecPrincipal.kt similarity index 87% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/principal/CoSecPrincipal.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/CoSecPrincipal.kt index b7c941d3..bb4aa7dc 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/CoSecPrincipal.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/CoSecPrincipal.kt @@ -10,11 +10,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.principal +package me.ahoo.cosec.api.principal -import me.ahoo.cosec.CoSec -import me.ahoo.cosec.internal.InternalIds.wrap -import me.ahoo.cosec.policy.PolicyCapable +import me.ahoo.cosec.api.CoSec +import me.ahoo.cosec.api.internal.InternalIds.wrap import java.security.Principal /** @@ -53,8 +52,6 @@ interface CoSecPrincipal : Principal, PolicyCapable, RoleCapable { val ANONYMOUS_NAME = wrap("anonymous") - val ANONYMOUS: CoSecPrincipal = SimplePrincipal(ANONYMOUS_ID, ANONYMOUS_NAME) - fun CoSecPrincipal.isRoot(): Boolean { return ROOT_NAME == name } diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyCapable.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/PolicyCapable.kt similarity index 88% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyCapable.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/PolicyCapable.kt index 15b544c9..c580e854 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyCapable.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/PolicyCapable.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.policy +package me.ahoo.cosec.api.principal /** * PolicyCapable . @@ -22,7 +22,7 @@ interface PolicyCapable { * get policy ids. * relation: * - * [me.ahoo.cosec.principal.CoSecPrincipal] 1:N [me.ahoo.cosec.policy.Policy] + * [me.ahoo.cosec.api.principal.CoSecPrincipal] 1:N [me.ahoo.cosec.policy.Policy] * * @return policy ids.. */ diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/RequestMatcher.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/RequestMatcher.kt similarity index 85% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/RequestMatcher.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/RequestMatcher.kt index 88825982..c4040d17 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/RequestMatcher.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/RequestMatcher.kt @@ -11,10 +11,10 @@ * limitations under the License. */ -package me.ahoo.cosec.policy +package me.ahoo.cosec.api.principal -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request interface RequestMatcher { val type: String diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/RoleCapable.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/RoleCapable.kt similarity index 86% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/principal/RoleCapable.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/RoleCapable.kt index fa230374..1da88138 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/RoleCapable.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/RoleCapable.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.principal +package me.ahoo.cosec.api.principal /** * RoleCapable . @@ -22,8 +22,8 @@ interface RoleCapable { * get role ids. * relation: *
-     * [CoSecPrincipal] 1:N [me.ahoo.cosec.tenant.Tenant]
-     * [me.ahoo.cosec.tenant.Tenant] 1:N Role
+     * [CoSecPrincipal] 1:N [me.ahoo.cosec.api.tenant.Tenant]
+     * [me.ahoo.cosec.api.tenant.Tenant] 1:N Role
      * [CoSecPrincipal] 1:N Role
      
* * diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/TenantPrincipal.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/TenantPrincipal.kt similarity index 68% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/principal/TenantPrincipal.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/TenantPrincipal.kt index fe06fd04..da534081 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/TenantPrincipal.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/principal/TenantPrincipal.kt @@ -10,19 +10,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.principal +package me.ahoo.cosec.api.principal -import me.ahoo.cosec.tenant.Tenant -import me.ahoo.cosec.tenant.TenantCapable +import me.ahoo.cosec.api.tenant.TenantCapable /** * Tenant Principal . * * @author ahoo wang */ -interface TenantPrincipal : CoSecPrincipal, TenantCapable { - companion object { - @JvmField - val ANONYMOUS: TenantPrincipal = SimpleTenantPrincipal(CoSecPrincipal.ANONYMOUS, Tenant.DEFAULT) - } -} +interface TenantPrincipal : CoSecPrincipal, TenantCapable diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/Tenant.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/tenant/Tenant.kt similarity index 79% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/Tenant.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/tenant/Tenant.kt index 47b15cea..93770af4 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/Tenant.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/tenant/Tenant.kt @@ -10,10 +10,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.tenant +package me.ahoo.cosec.api.tenant -import me.ahoo.cosec.CoSec -import me.ahoo.cosec.internal.InternalIds.wrap +import me.ahoo.cosec.api.CoSec +import me.ahoo.cosec.api.internal.InternalIds.wrap /** * Tenant for splitting customer boundaries horizontally. @@ -43,15 +43,7 @@ interface Tenant { @JvmField val PLATFORM_TENANT_ID = wrap("platform") - @JvmField - val PLATFORM: Tenant = SimpleTenant(PLATFORM_TENANT_ID) - @JvmField val DEFAULT_TENANT_ID = CoSec.DEFAULT - - @JvmField - val DEFAULT: Tenant = SimpleTenant(DEFAULT_TENANT_ID) } } - -data class SimpleTenant(override val tenantId: String) : Tenant diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/TenantCapable.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/tenant/TenantCapable.kt similarity index 95% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/TenantCapable.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/tenant/TenantCapable.kt index d379d09e..84c3323d 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/TenantCapable.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/tenant/TenantCapable.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.tenant +package me.ahoo.cosec.api.tenant /** * Tenant Capable. diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/AccessToken.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/AccessToken.kt similarity index 95% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/token/AccessToken.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/AccessToken.kt index c88be31b..2769ce41 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/AccessToken.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/AccessToken.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.token +package me.ahoo.cosec.api.token /** * Access Token. diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/CompositeToken.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/CompositeToken.kt similarity index 95% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/token/CompositeToken.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/CompositeToken.kt index 19c9bafd..f31f766b 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/CompositeToken.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/CompositeToken.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.token +package me.ahoo.cosec.api.token /** * Composite Token . diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/RefreshToken.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/RefreshToken.kt similarity index 95% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/token/RefreshToken.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/RefreshToken.kt index cfd3c0fa..018c4e1d 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/RefreshToken.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/RefreshToken.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.token +package me.ahoo.cosec.api.token /** * Refresh Token . diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/Token.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/Token.kt similarity index 95% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/token/Token.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/Token.kt index 9c97f64b..8695be31 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/Token.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/Token.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.token +package me.ahoo.cosec.api.token /** * Token . diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenIdCapable.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenIdCapable.kt similarity index 95% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenIdCapable.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenIdCapable.kt index 817fe76c..c9817160 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenIdCapable.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenIdCapable.kt @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.token +package me.ahoo.cosec.api.token /** * Token Id Capable . diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenPrincipal.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenPrincipal.kt similarity index 69% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenPrincipal.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenPrincipal.kt index 431b5890..a9e67c90 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenPrincipal.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenPrincipal.kt @@ -10,19 +10,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.token +package me.ahoo.cosec.api.token -import me.ahoo.cosec.CoSec -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.CoSecPrincipal /** * Token Principal . * * @author ahoo wang */ -interface TokenPrincipal : TokenIdCapable, CoSecPrincipal { - companion object { - @JvmField - val ANONYMOUS: TokenPrincipal = SimpleTokenPrincipal(CoSec.DEFAULT, CoSecPrincipal.ANONYMOUS) - } -} +interface TokenPrincipal : TokenIdCapable, CoSecPrincipal diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenTenantPrincipal.kt b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenTenantPrincipal.kt similarity index 73% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenTenantPrincipal.kt rename to cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenTenantPrincipal.kt index cfc99e4d..9757da08 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenTenantPrincipal.kt +++ b/cosec-api/src/main/kotlin/me/ahoo/cosec/api/token/TokenTenantPrincipal.kt @@ -10,19 +10,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec.token +package me.ahoo.cosec.api.token -import me.ahoo.cosec.principal.TenantPrincipal -import me.ahoo.cosec.tenant.Tenant +import me.ahoo.cosec.api.principal.TenantPrincipal /** * Token Tenant Principal . * * @author ahoo wang */ -interface TokenTenantPrincipal : TenantPrincipal, TokenPrincipal { - companion object { - @JvmField - val ANONYMOUS: TokenTenantPrincipal = SimpleTokenTenantPrincipal(TokenPrincipal.ANONYMOUS, Tenant.DEFAULT) - } -} +interface TokenTenantPrincipal : TenantPrincipal, TokenPrincipal diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/CoSecTest.kt b/cosec-api/src/test/kotlin/me/ahoo/cosec/api/CoSecTest.kt similarity index 94% rename from cosec-core/src/test/kotlin/me/ahoo/cosec/CoSecTest.kt rename to cosec-api/src/test/kotlin/me/ahoo/cosec/api/CoSecTest.kt index 9e430a7e..1698d68e 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/CoSecTest.kt +++ b/cosec-api/src/test/kotlin/me/ahoo/cosec/api/CoSecTest.kt @@ -10,8 +10,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.ahoo.cosec +package me.ahoo.cosec.api +import me.ahoo.cosec.api.CoSec import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test diff --git a/cosec-core/build.gradle.kts b/cosec-core/build.gradle.kts index 0d603a25..b391d41e 100644 --- a/cosec-core/build.gradle.kts +++ b/cosec-core/build.gradle.kts @@ -12,6 +12,7 @@ */ dependencies { + api(project(":cosec-api")) compileOnly("ognl:ognl") compileOnly("org.springframework:spring-web") compileOnly("org.springframework:spring-expression") diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/SimpleAuthenticationProvider.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/DefaultAuthenticationProvider.kt similarity index 83% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/SimpleAuthenticationProvider.kt rename to cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/DefaultAuthenticationProvider.kt index be567e0e..14409f8e 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/SimpleAuthenticationProvider.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/DefaultAuthenticationProvider.kt @@ -12,7 +12,10 @@ */ package me.ahoo.cosec.authentication -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.authentication.Authentication +import me.ahoo.cosec.api.authentication.AuthenticationProvider +import me.ahoo.cosec.api.authentication.Credentials +import me.ahoo.cosec.api.principal.CoSecPrincipal import java.util.concurrent.ConcurrentHashMap /** @@ -20,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap * * @author ahoo wang */ -object SimpleAuthenticationProvider : AuthenticationProvider { +object DefaultAuthenticationProvider : AuthenticationProvider { private val authenticationMaps: MutableMap, Authentication> init { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractRefreshTokenAuthentication.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractRefreshTokenAuthentication.kt index 147c8e50..d8d22dbf 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractRefreshTokenAuthentication.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractRefreshTokenAuthentication.kt @@ -13,9 +13,9 @@ package me.ahoo.cosec.authentication.token -import me.ahoo.cosec.authentication.Authentication +import me.ahoo.cosec.api.authentication.Authentication +import me.ahoo.cosec.api.token.TokenPrincipal import me.ahoo.cosec.token.TokenConverter -import me.ahoo.cosec.token.TokenPrincipal import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.toMono diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractSwitchTenantAuthentication.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractSwitchTenantAuthentication.kt index 99ee57a5..c651a9d8 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractSwitchTenantAuthentication.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/AbstractSwitchTenantAuthentication.kt @@ -12,9 +12,9 @@ */ package me.ahoo.cosec.authentication.token -import me.ahoo.cosec.authentication.Authentication -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.principal.TenantPrincipal +import me.ahoo.cosec.api.authentication.Authentication +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.TenantPrincipal import reactor.core.publisher.Mono /** diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/RefreshTokenCredentials.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/RefreshTokenCredentials.kt index 4ecae35a..c5d87e31 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/RefreshTokenCredentials.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/RefreshTokenCredentials.kt @@ -13,7 +13,7 @@ package me.ahoo.cosec.authentication.token -import me.ahoo.cosec.authentication.Credentials -import me.ahoo.cosec.token.CompositeToken +import me.ahoo.cosec.api.authentication.Credentials +import me.ahoo.cosec.api.token.CompositeToken interface RefreshTokenCredentials : Credentials, CompositeToken diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/SwitchTenantCredentials.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/SwitchTenantCredentials.kt index 640a7072..262a2c2b 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/SwitchTenantCredentials.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authentication/token/SwitchTenantCredentials.kt @@ -12,8 +12,8 @@ */ package me.ahoo.cosec.authentication.token -import me.ahoo.cosec.authentication.Credentials -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.authentication.Credentials +import me.ahoo.cosec.api.principal.CoSecPrincipal /** * Switch Tenant Credentials . diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/IllegalTenantContextException.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/IllegalTenantContextException.kt index 99ac5ea3..1d353293 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/IllegalTenantContextException.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/IllegalTenantContextException.kt @@ -12,8 +12,8 @@ */ package me.ahoo.cosec.authorization -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.tenant.Tenant +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.tenant.Tenant /** * Illegal Tenant Context Exception . diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/PermissionRepository.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/PermissionRepository.kt index ad6cbe51..4b26b26e 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/PermissionRepository.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/PermissionRepository.kt @@ -13,7 +13,7 @@ package me.ahoo.cosec.authorization -import me.ahoo.cosec.policy.Policy +import me.ahoo.cosec.api.policy.Policy import reactor.core.publisher.Mono /** diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/SimpleAuthorization.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/SimpleAuthorization.kt index 00af8e7c..f322ad75 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/SimpleAuthorization.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/authorization/SimpleAuthorization.kt @@ -12,13 +12,15 @@ */ package me.ahoo.cosec.authorization -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request -import me.ahoo.cosec.policy.Effect -import me.ahoo.cosec.policy.Policy -import me.ahoo.cosec.policy.Statement -import me.ahoo.cosec.policy.VerifyResult -import me.ahoo.cosec.principal.CoSecPrincipal.Companion.isRoot +import me.ahoo.cosec.api.authorization.Authorization +import me.ahoo.cosec.api.authorization.AuthorizeResult +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.Effect +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.policy.Statement +import me.ahoo.cosec.api.policy.VerifyResult +import me.ahoo.cosec.api.principal.CoSecPrincipal.Companion.isRoot import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.toMono diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/AbstractSecurityContextParser.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/AbstractSecurityContextParser.kt index 82ba543e..d57fbcd2 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/AbstractSecurityContextParser.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/AbstractSecurityContextParser.kt @@ -12,8 +12,9 @@ */ package me.ahoo.cosec.context -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.token.AccessToken +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.AccessToken /** * Abstract Security Context Parser . @@ -23,9 +24,9 @@ import me.ahoo.cosec.token.AccessToken abstract class AbstractSecurityContextParser : SecurityContextParser { override fun parse(request: R): SecurityContext { - val accessToken = getAccessToken(request) ?: return SecurityContext.ANONYMOUS + val accessToken = getAccessToken(request) ?: return SimpleSecurityContext.ANONYMOUS val principal = asPrincipal(accessToken) - return SecurityContext(principal) + return SimpleSecurityContext(principal) } protected abstract fun getAccessToken(request: R): AccessToken? diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextHolder.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextHolder.kt index 68fd9ca4..18bfa62d 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextHolder.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextHolder.kt @@ -12,6 +12,8 @@ */ package me.ahoo.cosec.context +import me.ahoo.cosec.api.context.SecurityContext + /** * Security Context Holder. * diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextParser.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextParser.kt index a18f0693..4d5d085b 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextParser.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContextParser.kt @@ -12,6 +12,7 @@ */ package me.ahoo.cosec.context +import me.ahoo.cosec.api.context.SecurityContext import me.ahoo.cosec.authorization.IllegalTenantContextException /** diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContext.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SimpleSecurityContext.kt similarity index 67% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContext.kt rename to cosec-core/src/main/kotlin/me/ahoo/cosec/context/SimpleSecurityContext.kt index 8dd0a877..aa237bdb 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SecurityContext.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/SimpleSecurityContext.kt @@ -12,10 +12,12 @@ */ package me.ahoo.cosec.context -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.principal.TenantPrincipal -import me.ahoo.cosec.tenant.Tenant -import me.ahoo.cosec.tenant.TenantCapable +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.tenant.Tenant +import me.ahoo.cosec.api.tenant.TenantCapable +import me.ahoo.cosec.principal.SimpleTenantPrincipal +import me.ahoo.cosec.tenant.SimpleTenant import java.util.* import java.util.concurrent.ConcurrentHashMap import javax.annotation.concurrent.ThreadSafe @@ -26,31 +28,26 @@ import javax.annotation.concurrent.ThreadSafe * @author ahoo wang */ @ThreadSafe -class SecurityContext( - val principal: CoSecPrincipal, +class SimpleSecurityContext( + override val principal: CoSecPrincipal, override val tenant: Tenant = principal.tenant -) : TenantCapable { +) : SecurityContext { companion object { const val KEY = "COSEC_SECURITY_CONTEXT" - val ANONYMOUS: SecurityContext = SecurityContext(TenantPrincipal.ANONYMOUS) + val ANONYMOUS: SecurityContext = SimpleSecurityContext(SimpleTenantPrincipal.ANONYMOUS) } private val attributes: MutableMap = ConcurrentHashMap() - fun setAttribute(key: String, value: Any): SecurityContext { + override fun setAttribute(key: String, value: Any): SecurityContext { attributes[key] = value return this } - fun getAttribute(key: String): T? { + override fun getAttribute(key: String): T? { @Suppress("UNCHECKED_CAST") return attributes[key] as T? } - - fun getRequiredAttribute(key: String): T { - val value: T? = getAttribute(key) - return requireNotNull(value = value) { "The required attribute:$key is not found." } - } } val CoSecPrincipal.tenant: Tenant @@ -58,6 +55,6 @@ val CoSecPrincipal.tenant: Tenant return if (this is TenantCapable) { this.tenant } else { - Tenant.DEFAULT + SimpleTenant.DEFAULT } } diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestParser.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestParser.kt index af35b838..9ca57ed5 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestParser.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestParser.kt @@ -13,6 +13,8 @@ package me.ahoo.cosec.context.request +import me.ahoo.cosec.api.context.request.Request + interface RequestParser { fun parse(request: R): Request } diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestTenantIdParser.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestTenantIdParser.kt index ad10a7be..284bc66f 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestTenantIdParser.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/context/request/RequestTenantIdParser.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.context.request -import me.ahoo.cosec.tenant.Tenant +import me.ahoo.cosec.api.tenant.Tenant /** * Request Tenant Id Parser. diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatcherFactory.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatcherFactory.kt index defde126..5fc1a60f 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatcherFactory.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatcherFactory.kt @@ -13,6 +13,8 @@ package me.ahoo.cosec.policy +import me.ahoo.cosec.api.policy.ActionMatcher + object ActionMatcherFactory { fun create(type: String, pattern: String): ActionMatcher { return when (type.lowercase()) { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatcher.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatchers.kt similarity index 93% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatcher.kt rename to cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatchers.kt index 46a05b5c..0f7c0609 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatcher.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ActionMatchers.kt @@ -13,14 +13,13 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.ActionMatcher import org.springframework.expression.Expression import org.springframework.expression.ParserContext import org.springframework.expression.spel.standard.SpelExpressionParser -interface ActionMatcher : RequestMatcher - object AllActionMatcher : ActionMatcher { const val TYPE = "all" override val type: String diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcher.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcher.kt index 04e0e579..1d622d2b 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcher.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcher.kt @@ -13,10 +13,9 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request - -interface ConditionMatcher : RequestMatcher +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.ConditionMatcher object AllConditionMatcher : ConditionMatcher { const val TYPE = "all" @@ -36,6 +35,7 @@ object NoneConditionMatcher : ConditionMatcher { get() = TYPE override val pattern: String get() = "!" + override fun match(request: Request, securityContext: SecurityContext): Boolean { return false } diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcherFactory.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcherFactory.kt index 5f7eae2f..981a5ff9 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcherFactory.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/ConditionMatcherFactory.kt @@ -13,6 +13,8 @@ package me.ahoo.cosec.policy +import me.ahoo.cosec.api.policy.ConditionMatcher + object ConditionMatcherFactory { fun create(type: String, pattern: String): ConditionMatcher { return when (type.lowercase()) { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyEvaluator.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/DefaultPolicyEvaluator.kt similarity index 78% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyEvaluator.kt rename to cosec-core/src/main/kotlin/me/ahoo/cosec/policy/DefaultPolicyEvaluator.kt index e36a5fa6..a2c68538 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyEvaluator.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/DefaultPolicyEvaluator.kt @@ -13,14 +13,12 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request -import me.ahoo.cosec.principal.TenantPrincipal -import me.ahoo.cosec.tenant.Tenant - -interface PolicyEvaluator { - fun evaluate(policy: Policy) -} +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.policy.PolicyEvaluator +import me.ahoo.cosec.api.tenant.Tenant +import me.ahoo.cosec.context.SimpleSecurityContext +import me.ahoo.cosec.principal.SimpleTenantPrincipal object DefaultPolicyEvaluator : PolicyEvaluator { private val mockRequest = object : Request { @@ -29,7 +27,7 @@ object DefaultPolicyEvaluator : PolicyEvaluator { override val tenantId: String get() = Tenant.DEFAULT_TENANT_ID } - private val mockContext = SecurityContext(TenantPrincipal.ANONYMOUS) + private val mockContext = SimpleSecurityContext(SimpleTenantPrincipal.ANONYMOUS) override fun evaluate(policy: Policy) { policy.statements.forEach { statement -> diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcher.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcher.kt index fcdc5c94..46460f50 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcher.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcher.kt @@ -13,8 +13,9 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.ConditionMatcher import ognl.Ognl data class OgnlConditionMatcher(override val pattern: String) : ConditionMatcher { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PathActionMatcher.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PathActionMatcher.kt index c2b36e60..8ef9c3e5 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PathActionMatcher.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PathActionMatcher.kt @@ -13,8 +13,9 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.ActionMatcher import org.springframework.http.server.PathContainer import org.springframework.web.util.pattern.PathPatternParser diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Policy.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyData.kt similarity index 78% rename from cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Policy.kt rename to cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyData.kt index e177135f..fbcd6ff8 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/Policy.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/PolicyData.kt @@ -13,19 +13,9 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.Named -import me.ahoo.cosec.tenant.Tenant - -/** - * Permission Policy - */ -interface Policy : Named, Tenant { - val id: String - val category: String - val description: String - val type: PolicyType - val statements: Set -} +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.policy.PolicyType +import me.ahoo.cosec.api.policy.Statement data class PolicyData( override val id: String, diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/RegularActionMatcher.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/RegularActionMatcher.kt index 01f631f3..511f6ff9 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/RegularActionMatcher.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/RegularActionMatcher.kt @@ -13,8 +13,9 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.ActionMatcher data class RegularActionMatcher(override val pattern: String) : ActionMatcher { companion object { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/SpelConditionMatcher.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/SpelConditionMatcher.kt index 307c8a66..00ddfd23 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/SpelConditionMatcher.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/SpelConditionMatcher.kt @@ -13,8 +13,9 @@ package me.ahoo.cosec.policy -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.ConditionMatcher import org.springframework.expression.Expression data class SpelConditionMatcher(override val pattern: String) : ConditionMatcher { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/StatementData.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/StatementData.kt new file mode 100644 index 00000000..ddaf682f --- /dev/null +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/StatementData.kt @@ -0,0 +1,25 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.cosec.policy + +import me.ahoo.cosec.api.policy.ActionMatcher +import me.ahoo.cosec.api.policy.ConditionMatcher +import me.ahoo.cosec.api.policy.Effect +import me.ahoo.cosec.api.policy.Statement + +data class StatementData( + override val effect: Effect = Effect.ALLOW, + override val actions: Set = emptySet(), + override val conditions: Set = emptySet() +) : Statement diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/CoSecModule.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/CoSecModule.kt index 98671fca..cd05648b 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/CoSecModule.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/CoSecModule.kt @@ -14,10 +14,10 @@ package me.ahoo.cosec.policy.serialization import com.fasterxml.jackson.databind.module.SimpleModule -import me.ahoo.cosec.policy.ActionMatcher -import me.ahoo.cosec.policy.ConditionMatcher -import me.ahoo.cosec.policy.Policy -import me.ahoo.cosec.policy.Statement +import me.ahoo.cosec.api.policy.ActionMatcher +import me.ahoo.cosec.api.policy.ConditionMatcher +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.policy.Statement class CoSecModule : SimpleModule() { init { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonActionMatcherSerializer.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonActionMatcherSerializer.kt index aa2eb20a..246f7d12 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonActionMatcherSerializer.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonActionMatcherSerializer.kt @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer -import me.ahoo.cosec.policy.ActionMatcher +import me.ahoo.cosec.api.policy.ActionMatcher import me.ahoo.cosec.policy.ActionMatcherFactory object JsonActionMatcherSerializer : StdSerializer(ActionMatcher::class.java) { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonConditionMatcherSerializer.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonConditionMatcherSerializer.kt index 96b6e69c..2cf90c60 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonConditionMatcherSerializer.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonConditionMatcherSerializer.kt @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer -import me.ahoo.cosec.policy.ConditionMatcher +import me.ahoo.cosec.api.policy.ConditionMatcher import me.ahoo.cosec.policy.ConditionMatcherFactory object JsonConditionMatcherSerializer : StdSerializer(ConditionMatcher::class.java) { diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonPolicySerializer.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonPolicySerializer.kt index 4ef1712c..8ccf04a1 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonPolicySerializer.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonPolicySerializer.kt @@ -20,10 +20,10 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer -import me.ahoo.cosec.policy.Policy +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.policy.PolicyType +import me.ahoo.cosec.api.policy.Statement import me.ahoo.cosec.policy.PolicyData -import me.ahoo.cosec.policy.PolicyType -import me.ahoo.cosec.policy.Statement const val POLICY_ID_KEY = "id" const val POLICY_NAME_KEY = "name" diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonStatementSerializer.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonStatementSerializer.kt index fd15d547..20e141dc 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonStatementSerializer.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/policy/serialization/JsonStatementSerializer.kt @@ -20,10 +20,10 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer -import me.ahoo.cosec.policy.ActionMatcher -import me.ahoo.cosec.policy.ConditionMatcher -import me.ahoo.cosec.policy.Effect -import me.ahoo.cosec.policy.Statement +import me.ahoo.cosec.api.policy.ActionMatcher +import me.ahoo.cosec.api.policy.ConditionMatcher +import me.ahoo.cosec.api.policy.Effect +import me.ahoo.cosec.api.policy.Statement import me.ahoo.cosec.policy.StatementData const val STATEMENT_EFFECT_KEY = "effect" diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimplePrincipal.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimplePrincipal.kt index 20ddc97c..470f702c 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimplePrincipal.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimplePrincipal.kt @@ -12,6 +12,8 @@ */ package me.ahoo.cosec.principal +import me.ahoo.cosec.api.principal.CoSecPrincipal + /** * Simple Principal. * @@ -24,6 +26,12 @@ data class SimplePrincipal( override val roles: Set = emptySet(), override val attrs: Map = emptyMap() ) : CoSecPrincipal { + + companion object { + @JvmField + val ANONYMOUS: CoSecPrincipal = SimplePrincipal(CoSecPrincipal.ANONYMOUS_ID, CoSecPrincipal.ANONYMOUS_NAME) + } + override fun getName(): String { return name } diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimpleTenantPrincipal.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimpleTenantPrincipal.kt index 22b61738..00ec60c1 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimpleTenantPrincipal.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/principal/SimpleTenantPrincipal.kt @@ -13,7 +13,10 @@ package me.ahoo.cosec.principal import me.ahoo.cosec.Delegated -import me.ahoo.cosec.tenant.Tenant +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.TenantPrincipal +import me.ahoo.cosec.api.tenant.Tenant +import me.ahoo.cosec.tenant.SimpleTenant /** * Simple Tenant Principal . @@ -25,4 +28,9 @@ data class SimpleTenantPrincipal( override val tenant: Tenant ) : TenantPrincipal, CoSecPrincipal by delegate, - Delegated + Delegated { + companion object { + @JvmField + val ANONYMOUS: TenantPrincipal = SimpleTenantPrincipal(SimplePrincipal.ANONYMOUS, SimpleTenant.DEFAULT) + } +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/SimpleTenant.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/SimpleTenant.kt new file mode 100644 index 00000000..c4ccf43e --- /dev/null +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/tenant/SimpleTenant.kt @@ -0,0 +1,26 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.cosec.tenant + +import me.ahoo.cosec.api.tenant.Tenant + +data class SimpleTenant(override val tenantId: String) : Tenant { + companion object { + @JvmField + val PLATFORM: Tenant = SimpleTenant(Tenant.PLATFORM_TENANT_ID) + + @JvmField + val DEFAULT: Tenant = SimpleTenant(Tenant.DEFAULT_TENANT_ID) + } +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleAccessToken.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleAccessToken.kt index eddd7d29..2d60edc8 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleAccessToken.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleAccessToken.kt @@ -12,6 +12,8 @@ */ package me.ahoo.cosec.token +import me.ahoo.cosec.api.token.AccessToken + /** * Simple Access Token . * diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleCompositeToken.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleCompositeToken.kt index 92b05406..7b4ea94f 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleCompositeToken.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleCompositeToken.kt @@ -12,6 +12,8 @@ */ package me.ahoo.cosec.token +import me.ahoo.cosec.api.token.CompositeToken + /** * Simple Composite Token . * diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenPrincipal.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenPrincipal.kt index 1de4a716..be7ed916 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenPrincipal.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenPrincipal.kt @@ -13,7 +13,10 @@ package me.ahoo.cosec.token import me.ahoo.cosec.Delegated -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.CoSec +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.TokenPrincipal +import me.ahoo.cosec.principal.SimplePrincipal /** * SimpleTokenPrincipal . @@ -23,4 +26,9 @@ import me.ahoo.cosec.principal.CoSecPrincipal data class SimpleTokenPrincipal(override val tokenId: String, override val delegate: CoSecPrincipal) : TokenPrincipal, CoSecPrincipal by delegate, - Delegated + Delegated { + companion object { + @JvmField + val ANONYMOUS: TokenPrincipal = SimpleTokenPrincipal(CoSec.DEFAULT, SimplePrincipal.ANONYMOUS) + } +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenTenantPrincipal.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenTenantPrincipal.kt index 7bdae262..2b42c3e4 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenTenantPrincipal.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/SimpleTokenTenantPrincipal.kt @@ -13,7 +13,10 @@ package me.ahoo.cosec.token import me.ahoo.cosec.Delegated -import me.ahoo.cosec.tenant.Tenant +import me.ahoo.cosec.api.tenant.Tenant +import me.ahoo.cosec.api.token.TokenPrincipal +import me.ahoo.cosec.api.token.TokenTenantPrincipal +import me.ahoo.cosec.tenant.SimpleTenant /** * Simple Token Tenant Principal . @@ -23,4 +26,10 @@ import me.ahoo.cosec.tenant.Tenant data class SimpleTokenTenantPrincipal(override val delegate: TokenPrincipal, override val tenant: Tenant) : TokenTenantPrincipal, TokenPrincipal by delegate, - Delegated + Delegated { + companion object { + @JvmField + val ANONYMOUS: TokenTenantPrincipal = + SimpleTokenTenantPrincipal(SimpleTokenPrincipal.ANONYMOUS, SimpleTenant.DEFAULT) + } +} diff --git a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenConverter.kt b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenConverter.kt index 74386342..2e981e7e 100644 --- a/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenConverter.kt +++ b/cosec-core/src/main/kotlin/me/ahoo/cosec/token/TokenConverter.kt @@ -12,7 +12,10 @@ */ package me.ahoo.cosec.token -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.AccessToken +import me.ahoo.cosec.api.token.CompositeToken +import me.ahoo.cosec.api.token.TokenPrincipal /** * Token Converter. diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/authentication/SimpleAuthenticationProviderTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/authentication/DefaultAuthenticationProviderTest.kt similarity index 76% rename from cosec-core/src/test/kotlin/me/ahoo/cosec/authentication/SimpleAuthenticationProviderTest.kt rename to cosec-core/src/test/kotlin/me/ahoo/cosec/authentication/DefaultAuthenticationProviderTest.kt index b609ac89..e873f525 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/authentication/SimpleAuthenticationProviderTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/authentication/DefaultAuthenticationProviderTest.kt @@ -14,27 +14,27 @@ package me.ahoo.cosec.authentication import io.mockk.mockk +import me.ahoo.cosec.api.token.TokenPrincipal import me.ahoo.cosec.authentication.token.RefreshTokenCredentials import me.ahoo.cosec.authentication.token.SimpleRefreshTokenAuthentication -import me.ahoo.cosec.token.TokenPrincipal import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.`is` import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test -internal class SimpleAuthenticationProviderTest { +internal class DefaultAuthenticationProviderTest { @Test fun register() { Assertions.assertThrows(IllegalArgumentException::class.java) { - SimpleAuthenticationProvider.getRequired( + DefaultAuthenticationProvider.getRequired( RefreshTokenCredentials::class.java ) } val refreshTokenAuthentication = SimpleRefreshTokenAuthentication(mockk()) - SimpleAuthenticationProvider.register(refreshTokenAuthentication) + DefaultAuthenticationProvider.register(refreshTokenAuthentication) assertThat( - SimpleAuthenticationProvider.getRequired( + DefaultAuthenticationProvider.getRequired( RefreshTokenCredentials::class.java ), `is`(refreshTokenAuthentication) diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/authorization/SimpleAuthorizationTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/authorization/SimpleAuthorizationTest.kt index 4e85e3aa..c43b62d4 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/authorization/SimpleAuthorizationTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/authorization/SimpleAuthorizationTest.kt @@ -15,13 +15,15 @@ package me.ahoo.cosec.authorization import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.authorization.AuthorizeResult +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.Effect +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.context.SimpleSecurityContext import me.ahoo.cosec.policy.AllActionMatcher -import me.ahoo.cosec.policy.Effect -import me.ahoo.cosec.policy.Policy import me.ahoo.cosec.policy.StatementData -import me.ahoo.cosec.principal.CoSecPrincipal import org.junit.jupiter.api.Test import reactor.core.publisher.Mono import reactor.kotlin.test.test @@ -69,7 +71,7 @@ internal class SimpleAuthorizationTest { val authorization = SimpleAuthorization(permissionRepository) val request = mockk() - authorization.authorize(request, SecurityContext.ANONYMOUS) + authorization.authorize(request, SimpleSecurityContext.ANONYMOUS) .test() .expectNext(AuthorizeResult.IMPLICIT_DENY) .verifyComplete() @@ -93,7 +95,7 @@ internal class SimpleAuthorizationTest { val authorization = SimpleAuthorization(permissionRepository) val request = mockk() - authorization.authorize(request, SecurityContext.ANONYMOUS) + authorization.authorize(request, SimpleSecurityContext.ANONYMOUS) .test() .expectNext(AuthorizeResult.ALLOW) .verifyComplete() @@ -117,7 +119,7 @@ internal class SimpleAuthorizationTest { val authorization = SimpleAuthorization(permissionRepository) val request = mockk() - authorization.authorize(request, SecurityContext.ANONYMOUS) + authorization.authorize(request, SimpleSecurityContext.ANONYMOUS) .test() .expectNext(AuthorizeResult.EXPLICIT_DENY) .verifyComplete() diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextHolderTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextHolderTest.kt index 96ccfa9b..b3fc319d 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextHolderTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextHolderTest.kt @@ -24,8 +24,8 @@ internal class SecurityContextHolderTest { @Test fun test() { assertThat(SecurityContextHolder.context, nullValue()) - SecurityContextHolder.setContext(SecurityContext.ANONYMOUS) - assertThat(SecurityContextHolder.context, equalTo(SecurityContext.ANONYMOUS)) + SecurityContextHolder.setContext(SimpleSecurityContext.ANONYMOUS) + assertThat(SecurityContextHolder.context, equalTo(SimpleSecurityContext.ANONYMOUS)) SecurityContextHolder.remove() Assertions.assertThrows(IllegalArgumentException::class.java) { SecurityContextHolder.requiredContext diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextTest.kt index d97fceff..28e982a8 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/context/SecurityContextTest.kt @@ -13,7 +13,7 @@ package me.ahoo.cosec.context -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.principal.SimplePrincipal import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.`is` @@ -24,14 +24,14 @@ internal class SecurityContextTest { @Test fun test() { - val context = SecurityContext(CoSecPrincipal.ANONYMOUS) + val context = SimpleSecurityContext(SimplePrincipal.ANONYMOUS) context.setAttribute("key", "value") assertThat(context.getAttribute("key"), `is`("value")) assertThat(context.getRequiredAttribute("key"), `is`("value")) Assertions.assertThrows(IllegalArgumentException::class.java) { context.getRequiredAttribute("key1") } - assertThat(context.principal, equalTo(CoSecPrincipal.ANONYMOUS)) - assertThat(context.tenant, equalTo(CoSecPrincipal.ANONYMOUS.tenant)) + assertThat(context.principal, equalTo(SimplePrincipal.ANONYMOUS)) + assertThat(context.tenant, equalTo(SimplePrincipal.ANONYMOUS.tenant)) } } diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/internal/InternalIdsTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/internal/InternalIdsTest.kt index 2d5a48b5..270702ab 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/internal/InternalIdsTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/internal/InternalIdsTest.kt @@ -12,9 +12,9 @@ */ package me.ahoo.cosec.internal -import me.ahoo.cosec.internal.InternalIds.isWrapped -import me.ahoo.cosec.internal.InternalIds.unwrap -import me.ahoo.cosec.internal.InternalIds.wrap +import me.ahoo.cosec.api.internal.InternalIds.isWrapped +import me.ahoo.cosec.api.internal.InternalIds.unwrap +import me.ahoo.cosec.api.internal.InternalIds.wrap import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Assertions diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ActionPatternReplacerTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ActionPatternReplacerTest.kt index f6f2347b..d3fb86f6 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ActionPatternReplacerTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ActionPatternReplacerTest.kt @@ -15,7 +15,7 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.context.SecurityContext import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* import org.junit.jupiter.api.Test diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/DefaultPolicyEvaluatorTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/DefaultPolicyEvaluatorTest.kt index f9a41dd4..ab089d1c 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/DefaultPolicyEvaluatorTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/DefaultPolicyEvaluatorTest.kt @@ -13,6 +13,7 @@ package me.ahoo.cosec.policy +import me.ahoo.cosec.api.policy.Policy import org.hamcrest.Matchers.* import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcherTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcherTest.kt index e39d8f36..d35d1f56 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcherTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/OgnlConditionMatcherTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* import org.junit.jupiter.params.ParameterizedTest diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/PathActionMatcherTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/PathActionMatcherTest.kt index 7a47aa76..e194a48a 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/PathActionMatcherTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/PathActionMatcherTest.kt @@ -15,7 +15,7 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.request.Request import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.`is` import org.junit.jupiter.api.Test diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/RegularActionMatcherTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/RegularActionMatcherTest.kt index cd31fb77..898fd651 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/RegularActionMatcherTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/RegularActionMatcherTest.kt @@ -15,7 +15,7 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.request.Request import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* import org.junit.jupiter.params.ParameterizedTest diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceablePathActionMatcherTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceablePathActionMatcherTest.kt index 5ac2de0b..3649cdc6 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceablePathActionMatcherTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceablePathActionMatcherTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* import org.junit.jupiter.api.Test diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceableRegularActionMatcherTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceableRegularActionMatcherTest.kt index a367810a..e144d328 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceableRegularActionMatcherTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/ReplaceableRegularActionMatcherTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* import org.junit.jupiter.api.Test diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/SpelConditionMatcherTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/SpelConditionMatcherTest.kt index a006e850..9ddabec8 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/SpelConditionMatcherTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/SpelConditionMatcherTest.kt @@ -15,7 +15,7 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.context.SecurityContext import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.`is` import org.junit.jupiter.api.Test diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/StatementDataTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/StatementDataTest.kt index 58642533..eb4f5a07 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/StatementDataTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/StatementDataTest.kt @@ -15,8 +15,10 @@ package me.ahoo.cosec.policy import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.SecurityContext +import me.ahoo.cosec.api.context.request.Request +import me.ahoo.cosec.api.policy.Effect +import me.ahoo.cosec.api.policy.VerifyResult import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* import org.junit.jupiter.api.Test diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/serialization/CoSecJsonSerializerTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/serialization/CoSecJsonSerializerTest.kt index 8cd5782a..e57f3b9f 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/serialization/CoSecJsonSerializerTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/policy/serialization/CoSecJsonSerializerTest.kt @@ -14,23 +14,23 @@ package me.ahoo.cosec.policy.serialization import com.fasterxml.jackson.core.type.TypeReference -import me.ahoo.cosec.policy.ActionMatcher +import me.ahoo.cosec.api.policy.ActionMatcher +import me.ahoo.cosec.api.policy.ConditionMatcher +import me.ahoo.cosec.api.policy.Effect +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.policy.PolicyType +import me.ahoo.cosec.api.policy.Statement import me.ahoo.cosec.policy.AllActionMatcher import me.ahoo.cosec.policy.AllConditionMatcher -import me.ahoo.cosec.policy.ConditionMatcher -import me.ahoo.cosec.policy.Effect import me.ahoo.cosec.policy.NoneActionMatcher import me.ahoo.cosec.policy.NoneConditionMatcher import me.ahoo.cosec.policy.OgnlConditionMatcher import me.ahoo.cosec.policy.PathActionMatcher -import me.ahoo.cosec.policy.Policy import me.ahoo.cosec.policy.PolicyData -import me.ahoo.cosec.policy.PolicyType import me.ahoo.cosec.policy.RegularActionMatcher import me.ahoo.cosec.policy.ReplaceablePathActionMatcher import me.ahoo.cosec.policy.ReplaceableRegularActionMatcher import me.ahoo.cosec.policy.SpelConditionMatcher -import me.ahoo.cosec.policy.Statement import me.ahoo.cosec.policy.StatementData import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* diff --git a/cosec-core/src/test/kotlin/me/ahoo/cosec/principal/CoSecPrincipalTest.kt b/cosec-core/src/test/kotlin/me/ahoo/cosec/principal/CoSecPrincipalTest.kt index 2867483e..48476a70 100644 --- a/cosec-core/src/test/kotlin/me/ahoo/cosec/principal/CoSecPrincipalTest.kt +++ b/cosec-core/src/test/kotlin/me/ahoo/cosec/principal/CoSecPrincipalTest.kt @@ -12,6 +12,7 @@ */ package me.ahoo.cosec.principal +import me.ahoo.cosec.api.principal.CoSecPrincipal import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test diff --git a/cosec-gateway/src/main/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilter.kt b/cosec-gateway/src/main/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilter.kt index 13ce081c..8e9b7561 100644 --- a/cosec-gateway/src/main/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilter.kt +++ b/cosec-gateway/src/main/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilter.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.gateway -import me.ahoo.cosec.authorization.Authorization +import me.ahoo.cosec.api.authorization.Authorization import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.context.request.RequestParser import me.ahoo.cosec.webflux.ReactiveSecurityFilter diff --git a/cosec-gateway/src/test/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilterTest.kt b/cosec-gateway/src/test/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilterTest.kt index 841caebd..a3f004d6 100644 --- a/cosec-gateway/src/test/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilterTest.kt +++ b/cosec-gateway/src/test/kotlin/me/ahoo/cosec/gateway/AuthorizationGatewayFilterTest.kt @@ -18,8 +18,8 @@ import io.mockk.just import io.mockk.mockk import io.mockk.runs import io.mockk.verify -import me.ahoo.cosec.authorization.Authorization -import me.ahoo.cosec.authorization.AuthorizeResult +import me.ahoo.cosec.api.authorization.Authorization +import me.ahoo.cosec.api.authorization.AuthorizeResult import me.ahoo.cosec.context.request.RequestTenantIdParser import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.webflux.ReactiveInjectSecurityContextParser diff --git a/cosec-jwt/src/jmh/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterBenchmark.kt b/cosec-jwt/src/jmh/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterBenchmark.kt index 16b4dbd5..22e5c5d5 100644 --- a/cosec-jwt/src/jmh/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterBenchmark.kt +++ b/cosec-jwt/src/jmh/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterBenchmark.kt @@ -13,10 +13,10 @@ package me.ahoo.cosec.jwt import com.auth0.jwt.algorithms.Algorithm +import me.ahoo.cosec.api.principal.TenantPrincipal +import me.ahoo.cosec.api.token.CompositeToken +import me.ahoo.cosec.api.token.TokenTenantPrincipal import me.ahoo.cosec.jwt.Jwts.asPrincipal -import me.ahoo.cosec.principal.TenantPrincipal -import me.ahoo.cosec.token.CompositeToken -import me.ahoo.cosec.token.TokenTenantPrincipal import me.ahoo.cosid.test.MockIdGenerator import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Scope diff --git a/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/JwtTokenConverter.kt b/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/JwtTokenConverter.kt index c2b3741e..30523351 100644 --- a/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/JwtTokenConverter.kt +++ b/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/JwtTokenConverter.kt @@ -17,15 +17,15 @@ import com.auth0.jwt.algorithms.Algorithm import com.auth0.jwt.exceptions.TokenExpiredException import com.auth0.jwt.interfaces.DecodedJWT import com.auth0.jwt.interfaces.JWTVerifier +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.RoleCapable +import me.ahoo.cosec.api.tenant.TenantCapable +import me.ahoo.cosec.api.token.AccessToken +import me.ahoo.cosec.api.token.CompositeToken +import me.ahoo.cosec.api.token.TokenPrincipal import me.ahoo.cosec.context.request.RequestTenantIdParser -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.principal.RoleCapable -import me.ahoo.cosec.tenant.TenantCapable -import me.ahoo.cosec.token.AccessToken -import me.ahoo.cosec.token.CompositeToken import me.ahoo.cosec.token.SimpleCompositeToken import me.ahoo.cosec.token.TokenConverter -import me.ahoo.cosec.token.TokenPrincipal import me.ahoo.cosid.IdGenerator import java.time.Duration import java.util.* diff --git a/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/Jwts.kt b/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/Jwts.kt index 67e314aa..c6c9c92d 100644 --- a/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/Jwts.kt +++ b/cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/Jwts.kt @@ -15,17 +15,17 @@ package me.ahoo.cosec.jwt import com.auth0.jwt.JWT import com.auth0.jwt.RegisteredClaims import com.auth0.jwt.interfaces.DecodedJWT +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.principal.PolicyCapable +import me.ahoo.cosec.api.principal.RoleCapable +import me.ahoo.cosec.api.token.TokenPrincipal +import me.ahoo.cosec.api.token.TokenTenantPrincipal import me.ahoo.cosec.context.request.RequestTenantIdParser -import me.ahoo.cosec.policy.PolicyCapable -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.principal.RoleCapable import me.ahoo.cosec.principal.SimplePrincipal import me.ahoo.cosec.tenant.SimpleTenant import me.ahoo.cosec.token.SimpleAccessToken import me.ahoo.cosec.token.SimpleTokenPrincipal import me.ahoo.cosec.token.SimpleTokenTenantPrincipal -import me.ahoo.cosec.token.TokenPrincipal -import me.ahoo.cosec.token.TokenTenantPrincipal /** * Jwts . diff --git a/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterTest.kt b/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterTest.kt index d22b0703..708334cf 100644 --- a/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterTest.kt +++ b/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/JwtTokenConverterTest.kt @@ -13,12 +13,12 @@ package me.ahoo.cosec.jwt import com.auth0.jwt.algorithms.Algorithm -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.principal.TenantPrincipal -import me.ahoo.cosec.token.CompositeToken +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.CompositeToken +import me.ahoo.cosec.api.token.TokenPrincipal +import me.ahoo.cosec.api.token.TokenTenantPrincipal +import me.ahoo.cosec.principal.SimpleTenantPrincipal import me.ahoo.cosec.token.TokenExpiredException -import me.ahoo.cosec.token.TokenPrincipal -import me.ahoo.cosec.token.TokenTenantPrincipal import me.ahoo.cosid.test.MockIdGenerator import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -37,30 +37,30 @@ internal class JwtTokenConverterTest { @Test fun asToken() { - val token: CompositeToken = jwtTokenConverter.asToken(TenantPrincipal.ANONYMOUS) + val token: CompositeToken = jwtTokenConverter.asToken(SimpleTenantPrincipal.ANONYMOUS) assertThat(token, notNullValue()) } @Test fun asPrincipal() { - val token: CompositeToken = jwtTokenConverter.asToken(TenantPrincipal.ANONYMOUS) + val token: CompositeToken = jwtTokenConverter.asToken(SimpleTenantPrincipal.ANONYMOUS) val principal: TokenTenantPrincipal = jwtTokenConverter.asPrincipal(token) assertThat(principal.name, equalTo(CoSecPrincipal.ANONYMOUS_NAME)) } @Test fun refresh() { - val oldToken: CompositeToken = jwtTokenConverter.asToken(TenantPrincipal.ANONYMOUS) + val oldToken: CompositeToken = jwtTokenConverter.asToken(SimpleTenantPrincipal.ANONYMOUS) val newTokenPrincipal = jwtTokenConverter.refresh(oldToken) - assertThat(newTokenPrincipal.id, equalTo(TenantPrincipal.ANONYMOUS.id)) - assertThat(newTokenPrincipal.tenant.tenantId, equalTo(TenantPrincipal.ANONYMOUS.tenant.tenantId)) + assertThat(newTokenPrincipal.id, equalTo(SimpleTenantPrincipal.ANONYMOUS.id)) + assertThat(newTokenPrincipal.tenant.tenantId, equalTo(SimpleTenantPrincipal.ANONYMOUS.tenant.tenantId)) } @Test fun refreshWhenExpired() { val converter = JwtTokenConverter(MockIdGenerator.INSTANCE, algorithm, Duration.ofMillis(1), Duration.ofMillis(1)) - val oldToken: CompositeToken = converter.asToken(TenantPrincipal.ANONYMOUS) + val oldToken: CompositeToken = converter.asToken(SimpleTenantPrincipal.ANONYMOUS) TimeUnit.SECONDS.sleep(1) Assertions.assertThrows(TokenExpiredException::class.java) { converter.refresh(oldToken) } } diff --git a/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/SimpleRefreshTokenAuthenticationTest.kt b/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/SimpleRefreshTokenAuthenticationTest.kt index c51b405a..17688612 100644 --- a/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/SimpleRefreshTokenAuthenticationTest.kt +++ b/cosec-jwt/src/test/kotlin/me/ahoo/cosec/jwt/SimpleRefreshTokenAuthenticationTest.kt @@ -14,11 +14,11 @@ package me.ahoo.cosec.jwt import com.auth0.jwt.algorithms.Algorithm +import me.ahoo.cosec.api.token.CompositeToken import me.ahoo.cosec.authentication.token.RefreshTokenCredentials import me.ahoo.cosec.authentication.token.SimpleRefreshTokenAuthentication import me.ahoo.cosec.context.tenant -import me.ahoo.cosec.principal.TenantPrincipal -import me.ahoo.cosec.token.CompositeToken +import me.ahoo.cosec.principal.SimpleTenantPrincipal import me.ahoo.cosid.test.MockIdGenerator import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -34,7 +34,7 @@ class SimpleRefreshTokenAuthenticationTest { fun authenticate() { val refreshTokenAuthentication = SimpleRefreshTokenAuthentication(jwtTokenConverter) assertThat(refreshTokenAuthentication.supportCredentials, `is`(RefreshTokenCredentials::class.java)) - val oldToken: CompositeToken = jwtTokenConverter.asToken(TenantPrincipal.ANONYMOUS) + val oldToken: CompositeToken = jwtTokenConverter.asToken(SimpleTenantPrincipal.ANONYMOUS) refreshTokenAuthentication.authenticate(object : RefreshTokenCredentials { override val accessToken: String @@ -43,10 +43,10 @@ class SimpleRefreshTokenAuthenticationTest { get() = oldToken.refreshToken }).test() .consumeNextWith { - assertThat(it.id, equalTo(TenantPrincipal.ANONYMOUS.id)) + assertThat(it.id, equalTo(SimpleTenantPrincipal.ANONYMOUS.id)) assertThat( it.tenant.tenantId, - equalTo(TenantPrincipal.ANONYMOUS.tenant.tenantId) + equalTo(SimpleTenantPrincipal.ANONYMOUS.tenant.tenantId) ) }.verifyComplete() } diff --git a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/DirectOAuthClientPrincipalConverter.kt b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/DirectOAuthClientPrincipalConverter.kt index 7bcecd0c..00611aa7 100644 --- a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/DirectOAuthClientPrincipalConverter.kt +++ b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/DirectOAuthClientPrincipalConverter.kt @@ -12,8 +12,8 @@ */ package me.ahoo.cosec.oauth.client +import me.ahoo.cosec.api.principal.CoSecPrincipal import me.ahoo.cosec.oauth.OAuthUser -import me.ahoo.cosec.principal.CoSecPrincipal import me.ahoo.cosec.principal.SimplePrincipal import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.toMono diff --git a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClient.kt b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClient.kt index ef135c8f..ce897450 100644 --- a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClient.kt +++ b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClient.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.oauth.client -import me.ahoo.cosec.Named +import me.ahoo.cosec.api.Named import me.ahoo.cosec.oauth.OAuthException import me.ahoo.cosec.oauth.OAuthUser import reactor.core.publisher.Mono diff --git a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthentication.kt b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthentication.kt index 6521b2fa..6d331adf 100644 --- a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthentication.kt +++ b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthentication.kt @@ -12,8 +12,8 @@ */ package me.ahoo.cosec.oauth.client -import me.ahoo.cosec.authentication.Authentication -import me.ahoo.cosec.principal.CoSecPrincipal +import me.ahoo.cosec.api.authentication.Authentication +import me.ahoo.cosec.api.principal.CoSecPrincipal import reactor.core.publisher.Mono /** diff --git a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientCredentials.kt b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientCredentials.kt index 0618ab93..621ed28f 100644 --- a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientCredentials.kt +++ b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientCredentials.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.oauth.client -import me.ahoo.cosec.authentication.Credentials +import me.ahoo.cosec.api.authentication.Credentials import me.zhyd.oauth.model.AuthCallback /** diff --git a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientPrincipalConverter.kt b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientPrincipalConverter.kt index 2ac25a52..8238363f 100644 --- a/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientPrincipalConverter.kt +++ b/cosec-oauth/src/main/kotlin/me/ahoo/cosec/oauth/client/OAuthClientPrincipalConverter.kt @@ -12,8 +12,8 @@ */ package me.ahoo.cosec.oauth.client +import me.ahoo.cosec.api.principal.CoSecPrincipal import me.ahoo.cosec.oauth.OAuthUser -import me.ahoo.cosec.principal.CoSecPrincipal import reactor.core.publisher.Mono /** diff --git a/cosec-oauth/src/test/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthenticationTest.kt b/cosec-oauth/src/test/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthenticationTest.kt index baf45ffe..68001c31 100644 --- a/cosec-oauth/src/test/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthenticationTest.kt +++ b/cosec-oauth/src/test/kotlin/me/ahoo/cosec/oauth/client/OAuthClientAuthenticationTest.kt @@ -48,10 +48,12 @@ internal class OAuthClientAuthenticationTest { .test() .consumeNextWith { assertThat( - it.id, `is`("id@clientId") + it.id, + `is`("id@clientId") ) assertThat( - it.name, `is`("username") + it.name, + `is`("username") ) } .verifyComplete() diff --git a/cosec-opentelemetry/src/main/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilter.kt b/cosec-opentelemetry/src/main/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilter.kt index b74763d3..86f8dff4 100644 --- a/cosec-opentelemetry/src/main/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilter.kt +++ b/cosec-opentelemetry/src/main/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilter.kt @@ -16,9 +16,9 @@ package me.ahoo.cosec.opentelemetry import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.trace.Span import io.opentelemetry.semconv.trace.attributes.SemanticAttributes -import me.ahoo.cosec.CoSec +import me.ahoo.cosec.api.CoSec +import me.ahoo.cosec.api.principal.PolicyCapable import me.ahoo.cosec.context.request.RequestTenantIdParser -import me.ahoo.cosec.policy.PolicyCapable import me.ahoo.cosec.webflux.ServerWebExchanges.getSecurityContext import org.slf4j.LoggerFactory import org.springframework.web.server.ServerWebExchange diff --git a/cosec-opentelemetry/src/test/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilterTest.kt b/cosec-opentelemetry/src/test/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilterTest.kt index a062bd83..6a586d35 100644 --- a/cosec-opentelemetry/src/test/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilterTest.kt +++ b/cosec-opentelemetry/src/test/kotlin/me/ahoo/cosec/opentelemetry/ReactiveTraceFilterTest.kt @@ -23,7 +23,7 @@ import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.sdk.OpenTelemetrySdk import io.opentelemetry.sdk.trace.SdkTracerProvider import io.opentelemetry.semconv.trace.attributes.SemanticAttributes -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.context.SimpleSecurityContext import me.ahoo.cosec.webflux.ServerWebExchanges.getSecurityContext import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.`is` @@ -64,7 +64,6 @@ class ReactiveTraceFilterTest { } finally { span.end() } - } @Test @@ -82,7 +81,7 @@ class ReactiveTraceFilterTest { @Test fun filterWithSecurityContext() { val exchange = mockk() { - every { getSecurityContext() } returns SecurityContext.ANONYMOUS + every { getSecurityContext() } returns SimpleSecurityContext.ANONYMOUS } ReactiveTraceFilter.filter(exchange) { @@ -93,13 +92,12 @@ class ReactiveTraceFilterTest { @Test fun filter() { - val span = tracer.spanBuilder("test").startSpan() try { assertThat(span.isRecording, `is`(true)) span.makeCurrent().use { val exchange = mockk() { - every { getSecurityContext() } returns SecurityContext.ANONYMOUS + every { getSecurityContext() } returns SimpleSecurityContext.ANONYMOUS } ReactiveTraceFilter.filter(exchange) { @@ -111,10 +109,17 @@ class ReactiveTraceFilterTest { it.name == "attributes" } attributesField.isAccessible = true + @Suppress("UNCHECKED_CAST") val attributes = attributesField.get(span) as Map, String> - assertThat(attributes[SemanticAttributes.ENDUSER_ID], `is`(SecurityContext.ANONYMOUS.principal.id)) + assertThat( + attributes[SemanticAttributes.ENDUSER_ID], + `is`(SimpleSecurityContext.ANONYMOUS.principal.id) + ) assertThat(attributes[SemanticAttributes.ENDUSER_ROLE], `is`("")) - assertThat(attributes[COSEC_TENANT_ID_ATTRIBUTE_KEY], `is`(SecurityContext.ANONYMOUS.tenant.tenantId)) + assertThat( + attributes[COSEC_TENANT_ID_ATTRIBUTE_KEY], + `is`(SimpleSecurityContext.ANONYMOUS.tenant.tenantId) + ) assertThat(attributes[COSEC_POLICY_ATTRIBUTE_KEY], `is`("")) } } finally { diff --git a/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/PolicyCache.kt b/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/PolicyCache.kt index 0f641088..227e1b4c 100644 --- a/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/PolicyCache.kt +++ b/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/PolicyCache.kt @@ -14,7 +14,7 @@ package me.ahoo.cosec.redis import me.ahoo.cache.Cache import me.ahoo.cosec.Delegated -import me.ahoo.cosec.policy.Policy +import me.ahoo.cosec.api.policy.Policy /** * Policy Cache . diff --git a/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/RedisPermissionRepository.kt b/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/RedisPermissionRepository.kt index 9bcf0814..309833d5 100644 --- a/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/RedisPermissionRepository.kt +++ b/cosec-redis/src/main/kotlin/me/ahoo/cosec/redis/RedisPermissionRepository.kt @@ -13,8 +13,8 @@ package me.ahoo.cosec.redis +import me.ahoo.cosec.api.policy.Policy import me.ahoo.cosec.authorization.PermissionRepository -import me.ahoo.cosec.policy.Policy import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.toMono diff --git a/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/PolicyCodecExecutorTest.kt b/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/PolicyCodecExecutorTest.kt index 950a7fa8..6d3f44ee 100644 --- a/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/PolicyCodecExecutorTest.kt +++ b/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/PolicyCodecExecutorTest.kt @@ -15,9 +15,9 @@ package me.ahoo.cosec.redis import me.ahoo.cache.CacheValue import me.ahoo.cache.TtlAt import me.ahoo.cache.spring.redis.codec.ObjectToJsonCodecExecutor -import me.ahoo.cosec.policy.Policy +import me.ahoo.cosec.api.policy.Policy +import me.ahoo.cosec.api.policy.PolicyType import me.ahoo.cosec.policy.PolicyData -import me.ahoo.cosec.policy.PolicyType import me.ahoo.cosec.policy.StatementData import me.ahoo.cosec.policy.serialization.CoSecJsonSerializer import me.ahoo.cosid.test.MockIdGenerator diff --git a/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/RedisPermissionRepositoryTest.kt b/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/RedisPermissionRepositoryTest.kt index f501041f..98eb0b46 100644 --- a/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/RedisPermissionRepositoryTest.kt +++ b/cosec-redis/src/test/kotlin/me/ahoo/cosec/redis/RedisPermissionRepositoryTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.redis import io.mockk.every import io.mockk.mockk +import me.ahoo.cosec.api.policy.PolicyType import me.ahoo.cosec.policy.PolicyData -import me.ahoo.cosec.policy.PolicyType import org.junit.jupiter.api.Test import reactor.kotlin.test.test diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/CoSecProperties.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/CoSecProperties.kt index 54295606..b4755356 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/CoSecProperties.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/CoSecProperties.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.spring.boot.starter -import me.ahoo.cosec.CoSec +import me.ahoo.cosec.api.CoSec import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConstructorBinding diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/ConditionalOnCoSecEnabled.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/ConditionalOnCoSecEnabled.kt index c1fed714..ea1aec39 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/ConditionalOnCoSecEnabled.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/ConditionalOnCoSecEnabled.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.spring.boot.starter -import me.ahoo.cosec.CoSec +import me.ahoo.cosec.api.CoSec import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty /** diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/AuthenticationProperties.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/AuthenticationProperties.kt index 48102290..bdfd9797 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/AuthenticationProperties.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/AuthenticationProperties.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.spring.boot.starter.authentication -import me.ahoo.cosec.CoSec +import me.ahoo.cosec.api.CoSec import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConstructorBinding diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfiguration.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfiguration.kt index 4451512d..a6dc1ffe 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfiguration.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfiguration.kt @@ -12,8 +12,9 @@ */ package me.ahoo.cosec.spring.boot.starter.authentication -import me.ahoo.cosec.authentication.Authentication -import me.ahoo.cosec.authentication.AuthenticationProvider +import me.ahoo.cosec.api.authentication.Authentication +import me.ahoo.cosec.api.authentication.AuthenticationProvider +import me.ahoo.cosec.authentication.DefaultAuthenticationProvider import me.ahoo.cosec.spring.boot.starter.ConditionalOnCoSecEnabled import org.springframework.boot.autoconfigure.AutoConfiguration import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean @@ -37,12 +38,11 @@ class CoSecAuthenticationAutoConfiguration { fun authenticationProvider( authentications: List> ): AuthenticationProvider { - val authenticationProvider = AuthenticationProvider.DEFAULT authentications.forEach { - authenticationProvider.register( + DefaultAuthenticationProvider.register( it ) } - return authenticationProvider + return DefaultAuthenticationProvider } } diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/AuthorizationProperties.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/AuthorizationProperties.kt index 3f704059..3fa8be89 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/AuthorizationProperties.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/AuthorizationProperties.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.spring.boot.starter.authorization -import me.ahoo.cosec.CoSec +import me.ahoo.cosec.api.CoSec import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConstructorBinding import org.springframework.boot.context.properties.NestedConfigurationProperty diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfiguration.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfiguration.kt index e871852d..ced65964 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfiguration.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfiguration.kt @@ -13,7 +13,7 @@ package me.ahoo.cosec.spring.boot.starter.authorization import com.auth0.jwt.algorithms.Algorithm -import me.ahoo.cosec.authorization.Authorization +import me.ahoo.cosec.api.authorization.Authorization import me.ahoo.cosec.authorization.PermissionRepository import me.ahoo.cosec.authorization.SimpleAuthorization import me.ahoo.cosec.context.SecurityContextParser diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CacheProperties.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CacheProperties.kt index 47e06541..c7856945 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CacheProperties.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CacheProperties.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.spring.boot.starter.authorization.cache -import me.ahoo.cosec.CoSec +import me.ahoo.cosec.api.CoSec import me.ahoo.cosec.spring.boot.starter.authorization.AuthorizationProperties import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConstructorBinding diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CoSecCacheAutoConfiguration.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CoSecCacheAutoConfiguration.kt index 5868e516..c008581f 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CoSecCacheAutoConfiguration.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/cache/CoSecCacheAutoConfiguration.kt @@ -22,8 +22,8 @@ import me.ahoo.cache.distributed.DistributedCache import me.ahoo.cache.spring.redis.RedisDistributedCache import me.ahoo.cache.spring.redis.codec.ObjectToJsonCodecExecutor import me.ahoo.cache.spring.redis.codec.SetToSetCodecExecutor +import me.ahoo.cosec.api.policy.Policy import me.ahoo.cosec.authorization.PermissionRepository -import me.ahoo.cosec.policy.Policy import me.ahoo.cosec.policy.serialization.CoSecJsonSerializer import me.ahoo.cosec.redis.GlobalPolicyIndexCache import me.ahoo.cosec.redis.GlobalPolicyIndexKey diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/gateway/CoSecGatewayAuthorizationAutoConfiguration.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/gateway/CoSecGatewayAuthorizationAutoConfiguration.kt index 738a9fef..56bfc42a 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/gateway/CoSecGatewayAuthorizationAutoConfiguration.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/gateway/CoSecGatewayAuthorizationAutoConfiguration.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.spring.boot.starter.authorization.gateway -import me.ahoo.cosec.authorization.Authorization +import me.ahoo.cosec.api.authorization.Authorization import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.context.request.RequestParser import me.ahoo.cosec.gateway.AuthorizationGatewayFilter diff --git a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/inject/InjectSecurityContextProperties.kt b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/inject/InjectSecurityContextProperties.kt index 529e5c5a..190baebb 100644 --- a/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/inject/InjectSecurityContextProperties.kt +++ b/cosec-spring-boot-starter/src/main/kotlin/me/ahoo/cosec/spring/boot/starter/inject/InjectSecurityContextProperties.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.spring.boot.starter.inject -import me.ahoo.cosec.CoSec +import me.ahoo.cosec.api.CoSec import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConstructorBinding diff --git a/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfigurationTest.kt b/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfigurationTest.kt index 8699b321..352c5209 100644 --- a/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfigurationTest.kt +++ b/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/CoSecAuthenticationAutoConfigurationTest.kt @@ -13,7 +13,7 @@ package me.ahoo.cosec.spring.boot.starter.authentication -import me.ahoo.cosec.authentication.AuthenticationProvider +import me.ahoo.cosec.api.authentication.AuthenticationProvider import org.assertj.core.api.AssertionsForInterfaceTypes import org.junit.jupiter.api.Test import org.springframework.boot.test.context.assertj.AssertableApplicationContext diff --git a/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/oauth/CoSecOAuthClientAuthenticationAutoConfigurationTest.kt b/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/oauth/CoSecOAuthClientAuthenticationAutoConfigurationTest.kt index c9aafb2e..0bf82fa0 100644 --- a/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/oauth/CoSecOAuthClientAuthenticationAutoConfigurationTest.kt +++ b/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authentication/oauth/CoSecOAuthClientAuthenticationAutoConfigurationTest.kt @@ -13,12 +13,12 @@ package me.ahoo.cosec.spring.boot.starter.authentication.oauth -import me.ahoo.cosec.authentication.AuthenticationProvider +import me.ahoo.cosec.api.authentication.AuthenticationProvider +import me.ahoo.cosec.api.principal.CoSecPrincipal import me.ahoo.cosec.oauth.client.OAuthClientAuthentication import me.ahoo.cosec.oauth.client.OAuthClientCredentials import me.ahoo.cosec.oauth.client.OAuthClientManager import me.ahoo.cosec.oauth.client.OAuthClientPrincipalConverter -import me.ahoo.cosec.principal.CoSecPrincipal import me.ahoo.cosec.spring.boot.starter.authentication.CoSecAuthenticationAutoConfiguration import me.ahoo.cosec.spring.boot.starter.authentication.ConditionalOnAuthenticationEnabled import me.ahoo.cosid.IdGenerator diff --git a/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfigurationTest.kt b/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfigurationTest.kt index f080ab63..49f41fc1 100644 --- a/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfigurationTest.kt +++ b/cosec-spring-boot-starter/src/test/kotlin/me/ahoo/cosec/spring/boot/starter/authorization/CoSecAuthorizationAutoConfigurationTest.kt @@ -15,7 +15,7 @@ package me.ahoo.cosec.spring.boot.starter.authorization import com.auth0.jwt.algorithms.Algorithm import me.ahoo.cache.spring.boot.starter.CoCacheAutoConfiguration -import me.ahoo.cosec.authorization.Authorization +import me.ahoo.cosec.api.authorization.Authorization import me.ahoo.cosec.servlet.AuthorizationFilter import me.ahoo.cosec.spring.boot.starter.authorization.cache.CoSecCacheAutoConfiguration import me.ahoo.cosec.token.TokenConverter diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilter.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilter.kt index 62c7a894..985fdb66 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilter.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilter.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.webflux -import me.ahoo.cosec.authorization.Authorization +import me.ahoo.cosec.api.authorization.Authorization import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.context.request.RequestParser import org.springframework.core.Ordered diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextParser.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextParser.kt index 6ca39d73..656a5eaa 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextParser.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextParser.kt @@ -12,12 +12,12 @@ */ package me.ahoo.cosec.webflux +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.AccessToken import me.ahoo.cosec.context.AbstractSecurityContextParser import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.jwt.Jwts.asPrincipal import me.ahoo.cosec.jwt.Jwts.parseAccessToken -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.token.AccessToken import org.springframework.web.server.ServerWebExchange /** diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilter.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilter.kt index a9198365..620d3da1 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilter.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilter.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.webflux -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.context.SecurityContext import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.webflux.ServerWebExchanges.setSecurityContext import org.springframework.core.Ordered diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequest.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequest.kt index 6dad4e66..d7703676 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequest.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequest.kt @@ -14,7 +14,7 @@ package me.ahoo.cosec.webflux import me.ahoo.cosec.Delegated -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.request.Request import org.springframework.web.server.ServerWebExchange data class ReactiveRequest( diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequestParser.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequestParser.kt index 30ebbfd7..022ff782 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequestParser.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveRequestParser.kt @@ -13,7 +13,7 @@ package me.ahoo.cosec.webflux -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.request.Request import me.ahoo.cosec.context.request.RequestParser import me.ahoo.cosec.context.request.RequestTenantIdParser import org.springframework.web.server.ServerWebExchange diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityContextParser.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityContextParser.kt index feedf41d..c6362aed 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityContextParser.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityContextParser.kt @@ -12,11 +12,11 @@ */ package me.ahoo.cosec.webflux +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.AccessToken import me.ahoo.cosec.context.AbstractSecurityContextParser import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.jwt.Jwts.parseAccessToken -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.token.AccessToken import me.ahoo.cosec.token.TokenConverter import org.springframework.web.server.ServerWebExchange diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityFilter.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityFilter.kt index 326edcfd..3a5e216f 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityFilter.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ReactiveSecurityFilter.kt @@ -13,8 +13,8 @@ package me.ahoo.cosec.webflux -import me.ahoo.cosec.authorization.Authorization -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.authorization.Authorization +import me.ahoo.cosec.api.context.SecurityContext import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.context.request.RequestParser import me.ahoo.cosec.policy.serialization.CoSecJsonSerializer diff --git a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ServerWebExchanges.kt b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ServerWebExchanges.kt index 14e8e222..5271b1e2 100644 --- a/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ServerWebExchanges.kt +++ b/cosec-webflux/src/main/kotlin/me/ahoo/cosec/webflux/ServerWebExchanges.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.webflux -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.context.SecurityContext import org.springframework.web.server.ServerWebExchange /** diff --git a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilterTest.kt b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilterTest.kt index 97fe6c02..3fef34f2 100644 --- a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilterTest.kt +++ b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveAuthorizationFilterTest.kt @@ -18,11 +18,10 @@ import io.mockk.just import io.mockk.mockk import io.mockk.runs import io.mockk.verify -import me.ahoo.cosec.authorization.Authorization -import me.ahoo.cosec.authorization.AuthorizeResult +import me.ahoo.cosec.api.authorization.Authorization +import me.ahoo.cosec.api.authorization.AuthorizeResult import me.ahoo.cosec.context.request.RequestTenantIdParser import me.ahoo.cosec.jwt.Jwts -import me.ahoo.cosec.policy.serialization.CoSecJsonSerializer import me.ahoo.cosec.webflux.ServerWebExchanges.setSecurityContext import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -33,7 +32,6 @@ import org.springframework.web.server.ServerWebExchange import org.springframework.web.server.WebFilterChain import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.toMono -import java.nio.ByteBuffer internal class ReactiveAuthorizationFilterTest { diff --git a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilterTest.kt b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilterTest.kt index 5f5c9485..06400fef 100644 --- a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilterTest.kt +++ b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveInjectSecurityContextWebFilterTest.kt @@ -18,9 +18,7 @@ import io.mockk.just import io.mockk.mockk import io.mockk.runs import io.mockk.verify -import me.ahoo.cosec.authorization.Authorization -import me.ahoo.cosec.authorization.AuthorizeResult -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.context.SimpleSecurityContext import me.ahoo.cosec.context.request.RequestTenantIdParser import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.webflux.ServerWebExchanges.setSecurityContext @@ -31,7 +29,6 @@ import org.springframework.core.Ordered import org.springframework.web.server.ServerWebExchange import org.springframework.web.server.WebFilterChain import reactor.core.publisher.Mono -import reactor.kotlin.core.publisher.toMono internal class ReactiveInjectSecurityContextWebFilterTest { @@ -56,7 +53,7 @@ internal class ReactiveInjectSecurityContextWebFilterTest { } filter.filter(exchange, filterChain).block() verify { - exchange.setSecurityContext(SecurityContext.ANONYMOUS) + exchange.setSecurityContext(SimpleSecurityContext.ANONYMOUS) } } } diff --git a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveRequestTenantIdParserTest.kt b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveRequestTenantIdParserTest.kt index 8b5354e7..e64db946 100644 --- a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveRequestTenantIdParserTest.kt +++ b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ReactiveRequestTenantIdParserTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.webflux import io.mockk.every import io.mockk.mockk +import me.ahoo.cosec.api.tenant.Tenant import me.ahoo.cosec.context.request.RequestTenantIdParser -import me.ahoo.cosec.tenant.Tenant import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.* import org.junit.jupiter.api.Test diff --git a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/SecurityContextParserSpec.kt b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/SecurityContextParserSpec.kt index fd7a1bda..62febe45 100644 --- a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/SecurityContextParserSpec.kt +++ b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/SecurityContextParserSpec.kt @@ -16,13 +16,13 @@ package me.ahoo.cosec.webflux import com.auth0.jwt.algorithms.Algorithm import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext import me.ahoo.cosec.context.SecurityContextParser +import me.ahoo.cosec.context.SimpleSecurityContext import me.ahoo.cosec.jwt.JwtTokenConverter import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.principal.SimplePrincipal import me.ahoo.cosid.test.MockIdGenerator -import org.hamcrest.MatcherAssert +import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test import org.springframework.web.server.ServerWebExchange @@ -39,7 +39,7 @@ abstract class SecurityContextParserSpec { every { request.headers.getFirst(Jwts.AUTHORIZATION_KEY) } returns null } val securityContext = createSecurityContextParser().parse(exchange) - MatcherAssert.assertThat(securityContext, equalTo(SecurityContext.ANONYMOUS)) + assertThat(securityContext, equalTo(SimpleSecurityContext.ANONYMOUS)) } @Test @@ -51,7 +51,7 @@ abstract class SecurityContextParserSpec { } val securityContext = createSecurityContextParser().parse(exchange) - MatcherAssert.assertThat(securityContext.principal.id, equalTo(principal.id)) - MatcherAssert.assertThat(securityContext.principal.name, equalTo(principal.name)) + assertThat(securityContext.principal.id, equalTo(principal.id)) + assertThat(securityContext.principal.name, equalTo(principal.name)) } } diff --git a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ServerRequestTenantIdParserTest.kt b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ServerRequestTenantIdParserTest.kt index fa5e6bfc..4b8517c1 100644 --- a/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ServerRequestTenantIdParserTest.kt +++ b/cosec-webflux/src/test/kotlin/me/ahoo/cosec/webflux/ServerRequestTenantIdParserTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.webflux import io.mockk.every import io.mockk.mockk +import me.ahoo.cosec.api.tenant.Tenant import me.ahoo.cosec.context.request.RequestTenantIdParser -import me.ahoo.cosec.tenant.Tenant import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.`is` diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AbstractAuthorizationInterceptor.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AbstractAuthorizationInterceptor.kt index 4713cfb2..d2823b01 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AbstractAuthorizationInterceptor.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AbstractAuthorizationInterceptor.kt @@ -12,8 +12,8 @@ */ package me.ahoo.cosec.servlet -import me.ahoo.cosec.authorization.Authorization -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.authorization.Authorization +import me.ahoo.cosec.api.context.SecurityContext import me.ahoo.cosec.context.SecurityContextHolder import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.context.request.RequestParser diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AuthorizationFilter.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AuthorizationFilter.kt index 4267bcfc..3dfe08b7 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AuthorizationFilter.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/AuthorizationFilter.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.servlet -import me.ahoo.cosec.authorization.Authorization +import me.ahoo.cosec.api.authorization.Authorization import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.context.request.RequestParser import java.io.IOException diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/CoSecServletRequest.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/CoSecServletRequest.kt index 16a2d5af..27790a1f 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/CoSecServletRequest.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/CoSecServletRequest.kt @@ -14,7 +14,7 @@ package me.ahoo.cosec.servlet import me.ahoo.cosec.Delegated -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.request.Request import javax.servlet.http.HttpServletRequest data class CoSecServletRequest( diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilter.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilter.kt index b2907b35..507c9755 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilter.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilter.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.servlet -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.context.SecurityContext import me.ahoo.cosec.context.SecurityContextHolder import me.ahoo.cosec.context.SecurityContextParser import me.ahoo.cosec.servlet.ServletRequests.setSecurityContext diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextParser.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextParser.kt index f8fa6038..63898762 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextParser.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextParser.kt @@ -12,12 +12,12 @@ */ package me.ahoo.cosec.servlet +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.AccessToken import me.ahoo.cosec.context.AbstractSecurityContextParser import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.jwt.Jwts.asPrincipal import me.ahoo.cosec.jwt.Jwts.parseAccessToken -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.token.AccessToken import javax.servlet.http.HttpServletRequest /** diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestParser.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestParser.kt index 10760fc1..d5f13160 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestParser.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestParser.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.servlet -import me.ahoo.cosec.context.request.Request +import me.ahoo.cosec.api.context.request.Request import me.ahoo.cosec.context.request.RequestParser import me.ahoo.cosec.context.request.RequestTenantIdParser import javax.servlet.http.HttpServletRequest diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestSecurityContextParser.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestSecurityContextParser.kt index 58aa8e17..f8ef8985 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestSecurityContextParser.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequestSecurityContextParser.kt @@ -12,11 +12,11 @@ */ package me.ahoo.cosec.servlet +import me.ahoo.cosec.api.principal.CoSecPrincipal +import me.ahoo.cosec.api.token.AccessToken import me.ahoo.cosec.context.AbstractSecurityContextParser import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.jwt.Jwts.parseAccessToken -import me.ahoo.cosec.principal.CoSecPrincipal -import me.ahoo.cosec.token.AccessToken import me.ahoo.cosec.token.TokenConverter import javax.servlet.http.HttpServletRequest diff --git a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequests.kt b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequests.kt index bded3e12..d177d637 100644 --- a/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequests.kt +++ b/cosec-webmvc/src/main/kotlin/me/ahoo/cosec/servlet/ServletRequests.kt @@ -12,7 +12,7 @@ */ package me.ahoo.cosec.servlet -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.context.SecurityContext import javax.servlet.http.HttpServletRequest /** diff --git a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/AuthorizationFilterTest.kt b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/AuthorizationFilterTest.kt index 7a58727a..6511dea4 100644 --- a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/AuthorizationFilterTest.kt +++ b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/AuthorizationFilterTest.kt @@ -15,13 +15,12 @@ package me.ahoo.cosec.servlet import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.authorization.Authorization -import me.ahoo.cosec.authorization.AuthorizeResult -import me.ahoo.cosec.context.SecurityContext +import me.ahoo.cosec.api.authorization.Authorization +import me.ahoo.cosec.api.authorization.AuthorizeResult import me.ahoo.cosec.context.SecurityContextHolder +import me.ahoo.cosec.context.SimpleSecurityContext import me.ahoo.cosec.context.request.RequestTenantIdParser import me.ahoo.cosec.jwt.Jwts -import me.ahoo.cosec.policy.serialization.CoSecJsonSerializer import me.ahoo.cosec.servlet.ServletRequests.setSecurityContext import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -55,7 +54,7 @@ internal class AuthorizationFilterTest { every { doFilter(servletRequest, any()) } returns Unit } filter.doFilter(servletRequest, mockk(), filterChain) - assertThat(SecurityContextHolder.requiredContext, equalTo(SecurityContext.ANONYMOUS)) + assertThat(SecurityContextHolder.requiredContext, equalTo(SimpleSecurityContext.ANONYMOUS)) } @Test @@ -84,6 +83,6 @@ internal class AuthorizationFilterTest { every { doFilter(servletRequest, any()) } returns Unit } filter.doFilter(servletRequest, servletResponse, filterChain) - assertThat(SecurityContextHolder.requiredContext, equalTo(SecurityContext.ANONYMOUS)) + assertThat(SecurityContextHolder.requiredContext, equalTo(SimpleSecurityContext.ANONYMOUS)) } } diff --git a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilterTest.kt b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilterTest.kt index 0f0f74d0..bf5db66f 100644 --- a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilterTest.kt +++ b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/InjectSecurityContextFilterTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.servlet import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext import me.ahoo.cosec.context.SecurityContextHolder +import me.ahoo.cosec.context.SimpleSecurityContext import me.ahoo.cosec.jwt.Jwts import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -36,7 +36,7 @@ internal class InjectSecurityContextFilterTest { every { doFilter(request, any()) } returns Unit } filter.doFilter(request, mockk(), filterChain) - assertThat(SecurityContextHolder.requiredContext, equalTo(SecurityContext.ANONYMOUS)) + assertThat(SecurityContextHolder.requiredContext, equalTo(SimpleSecurityContext.ANONYMOUS)) } @Test diff --git a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/SecurityContextParserSpec.kt b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/SecurityContextParserSpec.kt index 5a2eb104..0c09d8e6 100644 --- a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/SecurityContextParserSpec.kt +++ b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/SecurityContextParserSpec.kt @@ -16,8 +16,8 @@ package me.ahoo.cosec.servlet import com.auth0.jwt.algorithms.Algorithm import io.mockk.every import io.mockk.mockk -import me.ahoo.cosec.context.SecurityContext import me.ahoo.cosec.context.SecurityContextParser +import me.ahoo.cosec.context.SimpleSecurityContext import me.ahoo.cosec.jwt.JwtTokenConverter import me.ahoo.cosec.jwt.Jwts import me.ahoo.cosec.principal.SimplePrincipal @@ -39,7 +39,7 @@ abstract class SecurityContextParserSpec { every { getHeader(Jwts.AUTHORIZATION_KEY) } returns null } val securityContext = createSecurityContextParser().parse(request) - MatcherAssert.assertThat(securityContext, equalTo(SecurityContext.ANONYMOUS)) + MatcherAssert.assertThat(securityContext, equalTo(SimpleSecurityContext.ANONYMOUS)) } @Test diff --git a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/ServletRequestTenantIdParserTest.kt b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/ServletRequestTenantIdParserTest.kt index 69cd5a4d..ce1ff745 100644 --- a/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/ServletRequestTenantIdParserTest.kt +++ b/cosec-webmvc/src/test/kotlin/me/ahoo/cosec/servlet/ServletRequestTenantIdParserTest.kt @@ -15,8 +15,8 @@ package me.ahoo.cosec.servlet import io.mockk.every import io.mockk.mockk +import me.ahoo.cosec.api.tenant.Tenant import me.ahoo.cosec.context.request.RequestTenantIdParser -import me.ahoo.cosec.tenant.Tenant import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test diff --git a/gradle.properties b/gradle.properties index 91abe945..9660b8e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ # limitations under the License. # group=me.ahoo.cosec -version=1.0.5 +version=1.1.0 description=RBAC-based And Policy-based Multi-Tenant Reactive Security Framework website=https://github.com/Ahoo-Wang/CoSec issues=https://github.com/Ahoo-Wang/CoSec/issues diff --git a/settings.gradle.kts b/settings.gradle.kts index c3059c0c..c31f8518 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,6 +15,7 @@ rootProject.name = "CoSec" include(":cosec-bom") include(":cosec-dependencies") +include(":cosec-api") include(":cosec-core") include(":cosec-jwt") include(":cosec-redis")