You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey 👋 Finally getting around to trialing Oso as an auth solution for a Kotlin application that I'm building.
However, it seems that Oso does not support Kotlin data classes :( Or, as is always possible... I'm just doing something dumb
I am trying to emulate the Java quickstart example, with a User trying to read from a repository.
I have the following models
data classRepo(
valid:UUID,
valname:String,
valisPublic:Boolean
)
data classUser (
valid:UUID,
valemail:String,
valrepoRoles:List<RepoRole>
)
I have set up OSO with the following
privateval oso:Oso=Oso()
init {
// On a tangent... it doesn't seem to even load // unless I explicitly repeat the class name as the second param
oso.registerClass(Repo::class.java, "Repo")
oso.registerClass(User::class.java, "User")
oso.loadStr(
"""allow(actor, action, resource) ifhas_permission(actor, action, resource);actor User {}resource Repo {permissions = ["read", "push", "delete"];roles = ["contributor", "maintainer", "admin"];"read" if "contributor";"push" if "maintainer";"delete" if "admin";"maintainer" if "admin";"contributor" if "maintainer";}# This rule tells Oso how to fetch roles for a Repohas_role(actor: User, role_name: String, Repo: Repo) ifrole in actor.repoRoles androle_name = role.name andRepo = role.Repo;has_permission(_actor: User, "read", Repo: Repo) ifRepo.isPublic;allow(actor, action, resource) ifhas_permission(actor, action, resource);""".trimIndent()
)
}
Just as a test, I have created a repo with isPublic=true with name test. However, when I run the following
funreadByName(name:String): RepoModels.Response {
val result =Repo(
id =UUID.randomUUID(),
name = name,
isPublic =true
)
val user =User(
id =UUID.randomUUID(),
email ="[email protected]",
repoRoles =listOf(RepoRole(role ="admin", repo = result))
)
oso.authorize(user, "read", result)
returnRepoModels.Response.fromRepo(result)
}
I get an authorization error from oso
com.osohq.oso.Exceptions$NotFoundException: Oso NotFoundException -- The current user does not have permission to read the given resource. You should handle this error by returning a 404 error to the client.
at com.osohq.oso.Oso.authorize(Oso.java:110)
at com.osohq.oso.Oso.authorize(Oso.java:118)
at io.bkbn.sourdough.api.service.RepoService.readByName(RepoService.kt:81)
// ...
If it helps, I have pushed all of this code to a repo https://github.com/bkbnio/oso-poc Instructions in the README for how to run the app. If you have any issues with getting it set up just let me know :)
You can emulate this error by running GET localhost:8080/repo?name=test
The text was updated successfully, but these errors were encountered:
Hey 👋 Finally getting around to trialing Oso as an auth solution for a Kotlin application that I'm building.
However, it seems that Oso does not support Kotlin data classes :( Or, as is always possible... I'm just doing something dumb
I am trying to emulate the Java quickstart example, with a User trying to read from a repository.
I have the following models
I have set up OSO with the following
Just as a test, I have created a repo with
isPublic=true
with nametest
. However, when I run the followingI get an authorization error from oso
If it helps, I have pushed all of this code to a repo https://github.com/bkbnio/oso-poc Instructions in the README for how to run the app. If you have any issues with getting it set up just let me know :)
You can emulate this error by running GET
localhost:8080/repo?name=test
The text was updated successfully, but these errors were encountered: