giuseppe-trisciuoglio avatar

Unit Test Security Authorization

Testing Spring Security authorization often means spinning up full contexts or discovering your @PreAuthorize annotations aren't actually doing anything because you forgot @EnableMethodSecurity. This skill gives you the patterns to test role-based access control with @WithMockUser, verify both allow and deny cases, and catch the silent failure modes where security gets bypassed. It covers @PreAuthorize, @Secured, @RolesAllowed, custom permission evaluators, and expression-based rules. The included validation tips are solid, especially the reminder that method security works through proxies and that you need to test the access denied path just as much as the happy path.

skills.sh installs
3.9K
GitHub stars
369
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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>

Sponsors

Details

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

More from giuseppe-trisciuoglio/developer-kit

All 102
1giuseppe-trisciuoglio avatarunit-test-scheduled-asyncgiuseppe-trisciuoglio/developer-kitProvides patterns for unit testing Spring `@Scheduled` and `@Async` methods using JUnit 5, CompletableFuture, Awaitility, and Mockito. Covers mocking task execu3.9Kskills.sh installs
2giuseppe-trisciuoglio avatarunit-test-utility-methodsgiuseppe-trisciuoglio/developer-kitProvides patterns for testing utility classes, static methods, and helper functions. Validates pure functions, null handling, edge cases, and boundary condition3.9Kskills.sh installs
3giuseppe-trisciuoglio avatarunit-test-exception-handlergiuseppe-trisciuoglio/developer-kitProvides patterns for unit testing `@ExceptionHandler` and `@ControllerAdvice` in Spring Boot applications. Validates error response formatting, mocks exception3.9Kskills.sh installs
4giuseppe-trisciuoglio avatarunit-test-config-propertiesgiuseppe-trisciuoglio/developer-kitProvides patterns for unit testing `@ConfigurationProperties` classes with `@ConfigurationPropertiesTest`. Validates property binding, tests validation constrai3.8Kskills.sh installs
5hyva-themes avatarhyva-playwright-testhyva-themes/hyva-ai-toolsWrite Playwright tests for Hyvä themes with Alpine.js components. This skill should be used when writing e2e tests, creating page objects, or debugging selector1.3Kskills.sh installs
6levnikolaevich avatarln-632-test-e2e-priority-auditorlevnikolaevich/claude-code-skillsAudits E2E coverage for critical user-visible journeys and wasteful E2E tests. Use when reviewing E2E journey value.381skills.sh installs