Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wildcard support #390

Merged
merged 18 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class AuthorizationBenchmarks {
@State(Scope.Thread)
public static class SimpleAuthRequest extends PolicyTestState {

final AuthorizationRequest basicRequest = AuthorizationRequest.builder()
final AuthorizationRequest request = AuthorizationRequest.builder()
.operation("mqtt:publish")
.resource("mqtt:topic:humidity")
.sessionId("sessionId")
Expand All @@ -58,7 +58,7 @@ public void doSetup() throws ParseException, AuthorizationException {
groupManager.setGroupConfiguration(GroupConfiguration.builder()
.definitions(Collections.singletonMap(
"group1", GroupDefinition.builder()
.selectionRule("thingName: " + "MyThingName")
.selectionRule("thingName: MyThingName")
.policyName("policy1")
.build()))
.policies(Collections.singletonMap(
Expand All @@ -76,7 +76,7 @@ public void doSetup() throws ParseException, AuthorizationException {
@State(Scope.Thread)
public static class PolicyVariableAuthRequest extends PolicyTestState {

final AuthorizationRequest thingNameRequest = AuthorizationRequest.builder()
final AuthorizationRequest request = AuthorizationRequest.builder()
.operation("mqtt:publish")
.resource("mqtt:topic:MyThingName/humidity")
.sessionId("sessionId")
Expand All @@ -88,7 +88,7 @@ public void doSetup() throws ParseException, AuthorizationException {
groupManager.setGroupConfiguration(GroupConfiguration.builder()
.definitions(Collections.singletonMap(
"group1", GroupDefinition.builder()
.selectionRule("thingName: " + "MyThingName")
.selectionRule("thingName: MyThingName")
.policyName("policy1")
.build()))
.policies(Collections.singletonMap(
Expand All @@ -103,14 +103,49 @@ public void doSetup() throws ParseException, AuthorizationException {
}
}

@State(Scope.Thread)
public static class WildcardAuthRequest extends PolicyTestState {

final AuthorizationRequest request = AuthorizationRequest.builder()
.operation("mqtt:publish")
.resource("mqtt:topic:a/b/c/d/e/f")
.sessionId("sessionId")
.build();

@Setup
public void doSetup() throws ParseException, AuthorizationException {
sessionManager.registerSession("sessionId", FakeSession.forDevice("MyThingName"));
groupManager.setGroupConfiguration(GroupConfiguration.builder()
.definitions(Collections.singletonMap(
"group1", GroupDefinition.builder()
.selectionRule("thingName: MyThingName")
.policyName("policy1")
.build()))
.policies(Collections.singletonMap(
"policy1", Collections.singletonMap(
"Statement1", AuthorizationPolicyStatement.builder()
.statementDescription("Policy description")
.effect(AuthorizationPolicyStatement.Effect.ALLOW)
.resources(new HashSet<>(Collections.singleton("mqtt:topic:*/*/*/*/*/*")))
.operations(new HashSet<>(Collections.singleton("mqtt:publish")))
.build())))
.build());
}
}

@Benchmark
public boolean GIVEN_single_group_permission_WHEN_simple_auth_request_THEN_successful_auth(SimpleAuthRequest state) throws Exception {
return state.deviceAuthClient.canDevicePerform(state.basicRequest);
return state.deviceAuthClient.canDevicePerform(state.request);
}

@Benchmark
public boolean GIVEN_policy_with_thing_name_variable_WHEN_auth_request_THEN_successful_auth(PolicyVariableAuthRequest state) throws Exception {
return state.deviceAuthClient.canDevicePerform(state.thingNameRequest);
return state.deviceAuthClient.canDevicePerform(state.request);
}

@Benchmark
public boolean GIVEN_policy_with_wildcards_WHEN_auth_request_THEN_successful_auth(WildcardAuthRequest state) throws Exception {
return state.deviceAuthClient.canDevicePerform(state.request);
}

static abstract class PolicyTestState {
Expand Down

This file was deleted.

Loading
Loading