Careeroza
Real World Example
Where You See This
- Teams at banks and fintechs (Razorpay, PhonePe) keep an access-control matrix and test every cell in CI; security audits ask for this evidence.
- Open-source Spring projects (Spring PetClinic, JHipster-generated apps) ship security slice tests for every controller.
ShopEase Access Matrix as a Test
| Endpoint | Anonymous | CUSTOMER | SELLER | ADMIN |
|---|---|---|---|---|
| GET /api/products | 200 | 200 | 200 | 200 |
| GET /api/orders | 401 | 200 | 200 | 200 |
| POST /api/seller/products | 401 | 403 | 201 | 201 |
| DELETE /api/admin/products/7 | 401 | 403 | 403 | 204 |
@WebMvcTest({ProductController.class, OrderController.class, SellerController.class, AdminProductController.class})
@Import(SecurityConfig.class)
class AccessMatrixTest {
@Autowired MockMvc mvc;
@MockitoBean ProductService productService;
@MockitoBean OrderService orderService;
@ParameterizedTest(name = "{0} {1} as {2} -> {3}")
@CsvSource({
"GET, /api/products, ANONYMOUS, 200",
"GET, /api/orders, ANONYMOUS, 401",
"GET, /api/orders, CUSTOMER, 200",
"POST, /api/seller/products, CUSTOMER, 403",
"POST, /api/seller/products, SELLER, 201",
"DELETE, /api/admin/products/7, SELLER, 403",
"DELETE, /api/admin/products/7, ADMIN, 204"
})
void accessMatrix(String method, String url, String role, int expected) throws Exception {
MockHttpServletRequestBuilder request = request(HttpMethod.valueOf(method), url)
.contentType(MediaType.APPLICATION_JSON)
.content("{\"name\":\"Steel Bottle\",\"price\":499,\"stock\":20,\"categoryId\":3}")
.with(csrf());
if (!role.equals("ANONYMOUS")) request.with(user("test").roles(role));
mvc.perform(request).andExpect(status().is(expected));
}
}Run
./mvnw -q test -Dtest=AccessMatrixTestExample output
[INFO] Running in.shopease.security.AccessMatrixTest [INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.117 s - in in.shopease.security.AccessMatrixTest [INFO] BUILD SUCCESS
Tip: When someone adds a new endpoint, they add one CSV line per role. A reviewer can read the whole security policy of the app in this one test.