Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to secure a Spring Security client application with OIDC (using pac4j)

If you already have Spring Security in your application, with hasRole rules, @PreAuthorize on services and code reading SecurityContextHolder and you want to add an OpenID Connect login, while keeping that authorization code, you can use pac4j for that. Whatever the provider (Keycloak, Microsoft Entra ID, Okta, a CAS server, etc.), once pac4j has authenticated the user, it can make that user…

To integrate OpenID Connect (OIDC) login into an existing Spring Security application using pac4j, follow these steps:

1. Set up a new Maven project with Java 17 or later and Spring Boot v4.x, which includes Spring Security v7 or Spring Boot v3.x with Spring Security v6. The bridge supports both versions.

2. Create the pom.xml file with Spring Boot parent dependency and specify Java version and project details.

3. Add the necessary Maven dependencies in pom.xml:

- spring-boot-starter-webmvc for MVC support

- spring-boot-starter-security for Spring Security

- org.pac4j:jakartaee-pac4j (version 8.0.4) for the OIDC authentication implementation

- org.pac4j:pac4j-oidc (version 6.5.9) for OpenID Connect support

- org.pac4j:spring-security-pac4j (version 10.1.0) as the bridge to integrate pac4j with Spring Security

4. Configure pac4j by creating a Pac4jConfig.java class annotated with @Configuration. Declare an OidcClient bean with OIDC client configuration and an authorization generator to convert trusted profile attributes into application roles.

5. Ensure your Spring Security application is configured with SpringBootApp.java as the main class.

By following these steps and using the appropriate pac4j artifacts and configuration, you can seamlessly integrate OIDC login into an existing Spring Security application while preserving the existing authorization mechanism.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Start and End Dates of the Longest Rising Period

Problem Description The stock table records the daily closing prices of many stocks, with the fields CODE (stock code), DT (trading date) and CL (closing price).

  • Longest rising period for stock CODE 100046
  • Started on 1 January and ended on 31 March
  • Consisted of 92 consecutive trading days

Why Java is Still the Quiet Engine of the Web (And Why It’s Not Going Anywhere)

There’s a long-running running joke in developer circles that Java is the "dinosaur" of modern programming languages. It’s heavy, it’s verbose, and everyone seems to move on to whatever lightweight…

  • Java powers millions of transactions per second in finance and e-commerce
  • JVM enables write-once, run-anywhere code across platforms
  • Recent Java 8+ features streamline high-concurrency programming

I Built CouponLab with AI Help. The Coupon Codes Still Have to Survive Checkout.

There’s a very specific kind of optimism involved in copying a coupon code. You see “20% off.” You picture the cheaper total. You paste the code.

  • Author built CouponLab to help users find and understand coupon codes.
  • AI assists in discovering offers, while author verifies coupon codes.
  • Design focuses on presenting relevant information without overwhelming users.

More from Thursday 8 October →