New advertisers: 50% off your first month with code FIRSTMONTHSee slots
giuseppe-trisciuoglio avatar

Unit Test Security Authorization

Unit test patterns for Spring Security method authorization, covering RBAC rules and custom permission evaluators.

skills.sh installs
3.9K
GitHub stars
372
last updated
Aug 21, 2026
View on GitHub

What it does

  • Covers @PreAuthorize, @Secured, and @RolesAllowed testing with allow and deny cases for each rule
  • Includes @WithMockUser and @WithUserDetails setups, plus direct tests for custom permission evaluators
  • Enforces a sanity check that method security is enabled, since a missing @EnableMethodSecurity silently bypasses checks
  • Designed for Java teams testing service-layer access control without a full Spring Security context

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-security-authorization -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Unit Testing Security and Authorization

Overview

This skill provides patterns for unit testing Spring Security authorization logic using @PreAuthorize, @Secured, @RolesAllowed, and custom permission evaluators. It covers testing role-based access control (RBAC), expression-based authorization, custom permission evaluators, and verifying access denied scenarios without full Spring Security context.

When to Use

Use this skill when:

  • Testing @PreAuthorize and @Secured method-level security
  • Testing role-based access control (RBAC)
  • Testing custom permission evaluators
  • Verifying access denied scenarios
  • Testing authorization with authenticated principals
  • Want fast authorization tests without full Spring Security context

Instructions

Follow these steps to test Spring Security authorization:

1. Set Up Security Testing Dependencies

Add spring-security-test to your test dependencies:

<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-test</artifactId>
  <scope>test</scope>
</dependency>

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Testing & QA, Java & JVM, Security
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 95

Similar to Unit Test Security Authorization

More Testing & QA