Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ Then the `myOpaAuth` authorizer needs to be referenced in your authenticator.
The authorizer will send a request to the `uri` specified in the config. The input will be:

{
user: <String: user name>
authenticationResult: {
identity: <String: user name>
authorizerName: <String>
authenticatedBy: <String>
context: Map<String, Object>
}
action: <String: READ|WRITE>
resource: {
name: <String>
Expand Down
4 changes: 2 additions & 2 deletions example/druid.rego
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ allow {
# user_is_admin is true if...
user_is_admin {
# "admin" is among the user's roles as per data.user_roles
"admin" in data.user_roles[input.user]
"admin" in data.user_roles[input.authenticationResult.identity]
}

# user_is_granted is a set of grants for the user identified in the request.
# The `grant` will be contained if the set `user_is_granted` for every...
user_is_granted[grant] {
# `role` assigned an element of the user_roles for this user...
some role in data.user_roles[input.user]
some role in data.user_roles[input.authenticationResult.identity]

# `grant` assigned a single grant from the grants list for 'role'...
some grant in data.role_grants[role]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ public Access authorize(
authenticationResult.getIdentity(), action.name(), resource.toString());
LOG.trace("Creating OPA request JSON.");
OpaMessage msg =
new OpaMessage(
authenticationResult.getIdentity(),
action.name(),
resource.getName(),
resource.getType());
new OpaMessage(authenticationResult, action.name(), resource.getName(), resource.getType());
String msgJson;
try {
msgJson = objectMapper.writeValueAsString(msg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package tech.stackable.druid.opaauthorizer.opatypes;

import org.apache.druid.server.security.AuthenticationResult;

public class OpaInput {
public String user;
public AuthenticationResult authenticationResult;
public String action;
public OpaResource resource;

public OpaInput(String user, String action, String resourceName, String resourceType) {
this.user = user;
public OpaInput(
AuthenticationResult authenticationResult,
String action,
String resourceName,
String resourceType) {
this.authenticationResult = authenticationResult;
this.action = action;
this.resource = new OpaResource(resourceName, resourceType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package tech.stackable.druid.opaauthorizer.opatypes;

import org.apache.druid.server.security.AuthenticationResult;

public class OpaMessage {
public OpaInput input;

public OpaMessage(String user, String action, String resourceName, String resourceType) {
this.input = new OpaInput(user, action, resourceName, resourceType);
public OpaMessage(
AuthenticationResult authenticationResult,
String action,
String resourceName,
String resourceType) {
this.input = new OpaInput(authenticationResult, action, resourceName, resourceType);
}
}