lgwillmore / warden

Kotlin Attribute Based Access Control
MIT License
19 stars 3 forks source link

Turn the library truly multiplatform #45

Open fischertayna opened 11 months ago

fischertayna commented 11 months ago

The code in the core library isn't JVM specific and could be turned into multiplatform.

In order to do that you should update the kotlin version (1.9.21) and then change the build.gradle of the core to:

kotlin {
    targetHierarchy.default()

    jvm()
    ios()
    iosSimulatorArm64()

    sourceSets {
...

The targetHierarchy.default() allows the commonMain code to be builded separatedely.

The only problem is in the commonTest. It has two JVM specific libraries as dependencies: assertk and mockk. The first is easy to remove, we can use the set of assert functions provided by kotlin.test. Mockk is trickier. We could move the tests into the sourceSet jvmTest or we could replace mockk with a multiplatform mock library, such as mockative.

fischertayna commented 11 months ago

If you agree, I can make these alterations and submit a pull request

lgwillmore commented 11 months ago

@fischertayna I am open to considering it.

I did make this multiplatform in the beginning more on a whim than anything else. Most of the functionality is really server side stuff, and which server side frameworks would need this to be multiplatform?

Basically, I know it is multiform, but who/how would it actually be used by non-jvm? It might even make sense to remove the multiplatform support and go pure jvm? Dunno.

What is your need for the changes you wan to make?

fischertayna commented 11 months ago

We are actually using it multiplatform.

We have a multiplatform project that has all the common server code in kotlin, and the client is in flutter. For the web product we use the JVM version of the server, but for the mobile we are able to use most of the common code from kotlin, and basically only rewrite the apis to communicate with the kotlin code using methodChannel (or eventChannel).

This way we can write the code only once and use in different products. We only have to rewrite the parts of the code that are specific to certain platforms (like io per example).

We would like to use warden to write the authorization policies. We did some tests, and doing the changes I've told you we are able to use it both in the web and mobile version. We just had to rewrite some of the atts library (that is JVM specific). As all the rules and the enforcement part are in the common, we wrote the policies only once.

lgwillmore commented 11 months ago

@fischertayna okay - that is cool. If anyone is using that component in multiplatform, then it is worth doing I reckon.

If you have a PR, then I am sure we can do the work to get it through - if you want to make the atts module multiplatform as well, then happy to see that one if you are up for it :smile:

I am also using warden, but it is at a point where it satisfies most of our needs - would like to spend some time updating docs etc and also bulding more powerful DSL tools for building policies. Like being able to look up attributes with the value of another attribute - almost a join functionality.

Any way rambling - please do what you need to to make it properly multiplatform.

lgwillmore commented 11 months ago

@fischertayna if you need a hand with any part then let me know and we can look at a combined effort

fischertayna commented 11 months ago

@lgwillmore Thank you for the offer! I've had some trouble with the tests and combining the version of gradle and kotlin multiplatform, but I've managed to find the combination (kotlin 1.9.10 and gradle 8.4)

I created the pull request: https://github.com/lgwillmore/warden/pull/46

For now, I've worked only with core, atts and ktor remains jvm only