Skip to content

Commit

Permalink
add customize ActionMatcher/ConditionMatcher to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Jan 10, 2023
1 parent 2c3652b commit 1a62f30
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,78 @@ RBAC-based And Policy-based Multi-Tenant Reactive Security Framework.

![ActionMatcher](document/design/assets/ActionMatcher.svg)

#### How to customize `ActionMatcher` (SPI)

> Refer to [RegularActionMatcher](cosec-core/src/main/kotlin/me/ahoo/cosec/policy/action/RegularActionMatcher.kt)
```kotlin
class CustomActionMatcherFactory : ActionMatcherFactory {
companion object {
const val TYPE = "[CustomActionType]"
}

override val type: String
get() = TYPE

override fun create(onfiguration: Configuration): ActionMatcher {
return CustomActionMatcher(onfiguration)
}
}
class CustomActionMatcher(configuration: Configuration) :
AbstractActionMatcher(CustomActionMatcherFactory.TYPE, configuration) {
override val type: String
get() = CustomActionMatcherFactory.TYPE

override fun internalMatch(request: Request, securityContext: SecurityContext): Boolean {
//Custom matching logic
}
}
```

> META-INF/services/me.ahoo.cosec.policy.action.ActionMatcherFactory
```properties
# CustomActionMatcherFactory fully qualified name
```

### ConditionMatcher

![ConditionMatcher](document/design/assets/ConditionMatcher.svg)

#### How to customize `ConditionMatcher` (SPI)

> Refer to [ContainsConditionMatcher](cosec-core/src/main/kotlin/me/ahoo/cosec/policy/condition/part/ContainsConditionMatcher.kt)
```kotlin
class CustomConditionMatcherFactory : ConditionMatcherFactory {
companion object {
const val TYPE = "[CustomConditionType]"
}

override val type: String
get() = TYPE

override fun create(configuration: Configuration): ConditionMatcher {
return CustomConditionMatcher(configuration)
}
}
class CustomConditionMatcher(configuration: Configuration) :
AbstractActionMatcher(CustomActionMatcherFactory.TYPE, configuration) {
override val type: String
get() = CustomConditionMatcherFactory.TYPE

override fun internalMatch(request: Request, securityContext: SecurityContext): Boolean {
//Custom matching logic
}
}
```

> META-INF/services/me.ahoo.cosec.policy.condition.ConditionMatcherFactory
```properties
# CustomConditionMatcherFactory fully qualified name
```

## Policy Schema

[Policy Schema](document/cosec-policy.schema.json)
Expand Down
68 changes: 68 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,78 @@

![ActionMatcher](document/design/assets/ActionMatcher.svg)

#### 如何自定义 `ActionMatcher` (SPI)

> 参考 [RegularActionMatcher](cosec-core/src/main/kotlin/me/ahoo/cosec/policy/action/RegularActionMatcher.kt)
```kotlin
class CustomActionMatcherFactory : ActionMatcherFactory {
companion object {
const val TYPE = "[CustomActionType]"
}

override val type: String
get() = TYPE

override fun create(onfiguration: Configuration): ActionMatcher {
return CustomActionMatcher(onfiguration)
}
}
class CustomActionMatcher(configuration: Configuration) :
AbstractActionMatcher(CustomActionMatcherFactory.TYPE, configuration) {
override val type: String
get() = CustomActionMatcherFactory.TYPE

override fun internalMatch(request: Request, securityContext: SecurityContext): Boolean {
//Custom matching logic
}
}
```

> META-INF/services/me.ahoo.cosec.policy.action.ActionMatcherFactory
```properties
# CustomActionMatcherFactory fully qualified name
```

### ConditionMatcher

![ConditionMatcher](document/design/assets/ConditionMatcher.svg)

#### 如何自定义 `ConditionMatcher` (SPI)

> 参考 [ContainsConditionMatcher](cosec-core/src/main/kotlin/me/ahoo/cosec/policy/condition/part/ContainsConditionMatcher.kt)
```kotlin
class CustomConditionMatcherFactory : ConditionMatcherFactory {
companion object {
const val TYPE = "[CustomConditionType]"
}

override val type: String
get() = TYPE

override fun create(configuration: Configuration): ConditionMatcher {
return CustomConditionMatcher(configuration)
}
}
class CustomConditionMatcher(configuration: Configuration) :
AbstractActionMatcher(CustomActionMatcherFactory.TYPE, configuration) {
override val type: String
get() = CustomConditionMatcherFactory.TYPE

override fun internalMatch(request: Request, securityContext: SecurityContext): Boolean {
//Custom matching logic
}
}
```

> META-INF/services/me.ahoo.cosec.policy.condition.ConditionMatcherFactory
```properties
# CustomConditionMatcherFactory fully qualified name
```

## 策略 Schema

[Policy Schema](document/cosec-policy.schema.json)
Expand Down

0 comments on commit 1a62f30

Please sign in to comment.