Skip to content

github/awesome-copilot / skills/spring-security

spring-security

Verified

Configure, test and review Spring Security 6/7 in Spring Boot 3/4 apps: SecurityFilterChain lambda DSL, method security, OAuth2 resource server with JWT, OIDC login, CSRF/CORS, password encoding, headers, actuator protection, and MockMvc security tests. Use when adding or auditing authentication and authorization.

references/oidc-login-oauth2-client.md

View on GitHub
# OIDC login and OAuth2 client

Dependency: `spring-boot-starter-oauth2-client` (Boot 3.x) or `spring-boot-starter-security-oauth2-client` (Boot 4.x; test companion `spring-boot-starter-security-oauth2-client-test`).

## Login with an OIDC provider

```yaml
spring:
  security:
    oauth2:
      client:
        registration:
          keycloak:
            client-id: ${OIDC_CLIENT_ID}
            client-secret: ${OIDC_CLIENT_SECRET}
            scope: openid,profile,email
        provider:
          keycloak:
            issuer-uri: https://issuer.example.com/realms/demo
```

```java
http
    .authorizeHttpRequests(a -> a.anyRequest().authenticated())
    .oauth2Login(Customizer.withDefaults())
    .logout(l -> l.logoutSuccessHandler(oidcLogoutHandler));
```

- Client id/secret come from environment variables or a secret store; never hard-code or print them.
- Common providers (Google, GitHub, Facebook) need only `client-id`/`client-secret`; Okta and other OIDC providers also need the `issuer-uri`.
- Use `OidcClientInitiatedLogoutSuccessHandler` for RP-initiated logout.
- Authorization Code with PKCE is the default for public clients; do not use the implicit or password grants.

## Mapping authorities

Customize with a `GrantedAuthoritiesMapper` bean or an `OAuth2UserService`/`OidcUserService` to turn provider claims (groups, roles) into `ROLE_*` authorities.

## Calling other APIs (OAuth2 client)

- Servlet apps: configure `OAuth2AuthorizedClientManager` and use `RestClient` with an `OAuth2ClientHttpRequestInterceptor`, or `WebClient` with `ServletOAuth2AuthorizedClientExchangeFilterFunction` (`ServerOAuth2AuthorizedClientExchangeFilterFunction` is for WebFlux only).
- Service-to-service uses `authorization-grant-type: client_credentials`.
- Check the Spring Security reference for the exact `RestClient` support available in your version.

## Sessions and BFF

OIDC login produces an HTTP session; keep CSRF enabled and configure cookies (`SameSite`, `Secure`, `HttpOnly`) as described in [web protections](csrf-cors-sessions-headers.md).
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall