Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,56 @@

import java.util.concurrent.TimeUnit;

/**
* Benchmark for ABAC (Attribute-Based Access Control) model.
*
* <p>This benchmark tests ABAC authorization performance using attribute-based expressions.
* ABAC allows access decisions based on attributes of the subject, resource, and environment
* without requiring explicit policies for each permission combination.
* The scenario uses deterministic policy generation to ensure reproducible results across runs.
*
* <p><b>Data Scale:</b>
* <ul>
* <li>Total rules: 0</li>
* <li>Total users: 0</li>
* </ul>
*
* <p><b>Authorization Logic:</b>
* The model uses attribute matching defined in the ABAC model configuration.
* Access is granted when the resource owner matches the requesting user.
*
* <p><b>Test Case:</b> Enforce "alice", data1 (owned by "alice"), "read"
*
* <p><b>Recommended JMH Options:</b>
* <pre>
* -f 2 -wi 3 -i 5 -t 1
* (2 forks, 3 warmup iterations, 5 measurement iterations, 1 thread)
* </pre>
*
* @see <a href="https://casbin.org/docs/en/abac">Casbin ABAC Model</a>
*/
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
public class BenchmarkABACModel {
private static Enforcer e = new Enforcer("examples/abac_model.conf", "",false);
private static Enforcer e = new Enforcer("examples/abac_model.conf", "", false);
private static ModelUnitTest.TestResource data1 = new ModelUnitTest.TestResource("data1", "alice");

public static void main(String args[]) throws RunnerException {
Options opt = new OptionsBuilder()
.include(BenchmarkABACModel.class.getName())
.exclude("Pref")
.warmupIterations(3)
.measurementIterations(3)
.measurementIterations(5)
.addProfiler(GCProfiler.class)
.forks(1)
.forks(2)
.threads(1)
.build();
new Runner(opt).run();
}

@Threads(1)
@Benchmark
public static void benchmarkABACModel() {
for (int i = 0; i < 1000; i++) {
e.enforce("alice", data1, "read");
}
e.enforce("alice", data1, "read");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@

import java.util.concurrent.TimeUnit;

/**
* Benchmark for ACL (Access Control List) model.
*
* <p>This benchmark tests basic ACL authorization performance with a simple subject-object-action policy.
* The scenario uses deterministic policy generation to ensure reproducible results across runs.
*
* <p><b>Data Scale:</b>
* <ul>
* <li>Total rules: 2</li>
* <li>Total users: 2</li>
* </ul>
*
* <p><b>Policy Structure:</b>
* <pre>
* p, alice, data1, read
* p, bob, data2, write
* </pre>
*
* <p><b>Test Case:</b> Enforce "alice", "data1", "read"
*
* <p><b>Recommended JMH Options:</b>
* <pre>
* -f 2 -wi 3 -i 5 -t 1
* (2 forks, 3 warmup iterations, 5 measurement iterations, 1 thread)
* </pre>
*
* @see <a href="https://casbin.org/docs/en/supported-models#acl">Casbin ACL Model</a>
*/
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
public class BenchmarkBasicModel {
Expand All @@ -34,18 +62,17 @@ public static void main(String args[]) throws RunnerException {
.include(BenchmarkBasicModel.class.getName())
.exclude("Pref")
.warmupIterations(3)
.measurementIterations(3)
.measurementIterations(5)
.addProfiler(GCProfiler.class)
.forks(1)
.forks(2)
.threads(1)
.build();
new Runner(opt).run();
}

@Threads(1)
@Benchmark
public static void benchmarkBasicModel() {
for (int i = 0; i < 1000; i++) {
e.enforce("alice", "data1", "read");
}
e.enforce("alice", "data1", "read");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,39 @@

import java.util.concurrent.TimeUnit;

/**
* Benchmark for RESTful/KeyMatch model.
*
* <p>This benchmark tests RESTful authorization performance with pattern matching.
* The KeyMatch model allows flexible URL pattern matching for RESTful APIs,
* supporting wildcards and path parameters.
* The scenario uses deterministic policy generation to ensure reproducible results across runs.
*
* <p><b>Data Scale:</b>
* <ul>
* <li>Total rules: 5</li>
* <li>Total users: 3 (alice, bob, cathy)</li>
* </ul>
*
* <p><b>Policy Structure:</b>
* <pre>
* p, alice, /alice_data/*, GET
* p, alice, /alice_data/resource1, POST
* p, bob, /alice_data/resource2, GET
* p, bob, /bob_data/*, POST
* p, cathy, /cathy_data, (GET)|(POST)
* </pre>
*
* <p><b>Test Case:</b> Enforce "alice", "/alice_data/resource1", "GET"
*
* <p><b>Recommended JMH Options:</b>
* <pre>
* -f 2 -wi 3 -i 5 -t 1
* (2 forks, 3 warmup iterations, 5 measurement iterations, 1 thread)
* </pre>
*
* @see <a href="https://casbin.org/docs/en/function#keymatch">Casbin KeyMatch Functions</a>
*/
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
public class BenchmarkKeyMatchModel {
Expand All @@ -34,18 +67,17 @@ public static void main(String args[]) throws RunnerException {
.include(BenchmarkKeyMatchModel.class.getName())
.exclude("Pref")
.warmupIterations(3)
.measurementIterations(3)
.measurementIterations(5)
.addProfiler(GCProfiler.class)
.forks(1)
.forks(2)
.threads(1)
.build();
new Runner(opt).run();
}

@Threads(1)
@Benchmark
public static void benchmarkKeyMatchModel() {
for (int i = 0; i < 1000; i++) {
e.enforce("alice", "/alice_data/resource1", "GET");
}
e.enforce("alice", "/alice_data/resource1", "GET");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,44 @@

import java.util.concurrent.TimeUnit;

/**
* Benchmark for priority-based model.
*
* <p>This benchmark tests priority-based authorization performance.
* The priority model allows policy evaluation based on explicit priority ordering,
* where higher priority policies override lower priority ones.
* The scenario uses deterministic policy generation to ensure reproducible results across runs.
*
* <p><b>Data Scale:</b>
* <ul>
* <li>Total rules: 9 (7 policies + 2 role assignments)</li>
* <li>Total users: 2 (alice, bob)</li>
* <li>Total roles: 2 (data1_deny_group, data2_allow_group)</li>
* </ul>
*
* <p><b>Policy Structure:</b>
* <pre>
* p, alice, data1, read, allow
* p, data1_deny_group, data1, read, deny
* p, data1_deny_group, data1, write, deny
* p, alice, data1, write, allow
* g, alice, data1_deny_group
* p, data2_allow_group, data2, read, allow
* p, bob, data2, read, deny
* p, bob, data2, write, deny
* g, bob, data2_allow_group
* </pre>
*
* <p><b>Test Case:</b> Enforce "alice", "data1", "read"
*
* <p><b>Recommended JMH Options:</b>
* <pre>
* -f 2 -wi 3 -i 5 -t 1
* (2 forks, 3 warmup iterations, 5 measurement iterations, 1 thread)
* </pre>
*
* @see <a href="https://casbin.org/docs/en/syntax-for-models#policy-effect">Casbin Priority Model</a>
*/
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
public class BenchmarkPriorityModel {
Expand All @@ -34,18 +72,17 @@ public static void main(String args[]) throws RunnerException {
.include(BenchmarkPriorityModel.class.getName())
.exclude("Pref")
.warmupIterations(3)
.measurementIterations(3)
.measurementIterations(5)
.addProfiler(GCProfiler.class)
.forks(1)
.forks(2)
.threads(1)
.build();
new Runner(opt).run();
}

@Threads(1)
@Benchmark
public static void benchmarkPriorityModel() {
for (int i = 0; i < 1000; i++) {
e.enforce("alice", "data1", "read");
}
e.enforce("alice", "data1", "read");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@

import java.util.concurrent.TimeUnit;

/**
* Benchmark for RBAC model with large-scale data.
*
* <p>This benchmark tests RBAC authorization performance with a large dataset.
* The scenario uses deterministic policy generation to ensure reproducible results across runs.
*
* <p><b>Data Scale:</b>
* <ul>
* <li>Total rules: 110000 (10000 role policies + 100000 user-role assignments)</li>
* <li>Total users: 100000</li>
* <li>Total roles: 10000</li>
* <li>Total resources: 1000</li>
* </ul>
*
* <p><b>Generation Logic:</b>
* <ul>
* <li>For each role i (0-9999): p, group{i}, data{i/10}, read</li>
* <li>For each user i (0-99999): g, user{i}, group{i/10}</li>
* <li>Each 10 roles are bound to 1 resource</li>
* <li>Each 10 users are bound to 1 role</li>
* </ul>
*
* <p><b>Test Case:</b> Enforce "user50001", "data1500", "read"
*
* <p><b>Recommended JMH Options:</b>
* <pre>
* -f 2 -wi 3 -i 5 -t 1
* (2 forks, 3 warmup iterations, 5 measurement iterations, 1 thread)
* </pre>
*
* @see <a href="https://casbin.org/docs/en/supported-models#rbac">Casbin RBAC Model</a>
*/
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
public class BenchmarkRBACModelLarge {
Expand All @@ -33,30 +65,29 @@ public static void main(String args[]) throws RunnerException {
Options opt = new OptionsBuilder()
.include(BenchmarkRBACModelLarge.class.getName())
.exclude("Pref")
.warmupIterations(1)
.measurementIterations(1)
.warmupIterations(3)
.measurementIterations(5)
.addProfiler(GCProfiler.class)
.forks(1)
.forks(2)
.threads(1)
.build();
new Runner(opt).run();
}

@Threads(1)
@Benchmark
public static void benchmarkRBACModelLarge() {
for (int i = 0; i < 100000; i++) {
e.enforce("user50001", "data1500", "read");
}
e.enforce("user50001", "data1500", "read");
}

static {
e.enableAutoBuildRoleLinks(false);
// 10000 roles, 1000 resources.
e.enableAutoBuildRoleLinks(false);
for (int i=0;i<10000;i++) {
for (int i = 0; i < 10000; i++) {
e.addPolicy(String.format("group%d", i), String.format("data%d", i/10), "read");
}
for (int i=0;i<100000;i++) {
// 100000 users.
for (int i = 0; i < 100000; i++) {
e.addGroupingPolicy(String.format("user%d", i), String.format("group%d", i/10));
}
e.buildRoleLinks();
Expand Down
Loading