2021-07-14 04:00:51 +02:00
2021-06-30 23:01:43 +02:00
2021-06-26 01:15:37 +02:00
2021-06-29 04:28:03 +02:00
2021-06-26 01:15:37 +02:00
2021-06-30 23:01:43 +02:00
2021-06-29 04:28:03 +02:00
2021-06-26 01:15:37 +02:00
2021-06-26 01:15:37 +02:00
2021-07-14 04:00:51 +02:00
2021-06-29 04:28:03 +02:00

Access Kontrol

Helpers to create a simple Access Control in kotlin

Tests Coverage

Maintainability Rating Lines of Code

Example

Define AC

class AccessControlSample : AccessControl() {
    /** The user can view the object if it is connected and if it is the creator */
    fun canView(myObject: MyObject, user: User?): AccessResponse {
        return if (user != null && myObject.createdBy == user) {
            granted(message = "OK") // the message if optional on granted
        } else {
            denied(message = "You must be the creator", code = "creator.ko")
        }
    }

    fun canView(myObjects: List<MyObject>, user: User?): AccessResponses {
        return canAll(myObjects) { canView(it, user) }
    }
}

Usage

AccessControlSample().canView(MyObject(), User()).let { response ->
    response.message // "OK"
    response.decision == AccessDecision.GRANTED // true
}


try {
    AccessControlSample().canView(MyObject(), User()).assert() // throw exception if no access
} catch (e: AccessDeniedException) {
    e.getFirstMessage() // the access denied message: "You must be the creator"
    e.first.code // the access denied code: "creator.ko"
}


AccessControlSample().canView(MyObject(), User()).toBoolean() // return true if access is granted
Description
No description provided
Readme 103 KiB
Latest
2021-07-14 19:00:43 +02:00
Languages
Kotlin 100%