Warum geht es nicht (Spring Security)?

Hallo,ich mache derzeit bei einem Kurs über Udemy mit und lerne dabei Spring Security. Leider ist der Kurs für Spring Security 6. Aber ich verwende die neuste Version, da dies ja irgendwie sinn macht damit anzufangen, anstatt die ältere Version zu lernen. Nun wollte ich wie im Kurs die SecurityConfig einstellen also mit SecurityFilterChain. Auch in den Docs für die neuste version sieht alles aus wie bei mir jetzt. Aber es möchte einfach nicht funktionieren. Ich werde bei allen Endpunkten nach einem Login gefragt, obwohl ich für 2 Endpunkte “permitAll()” verwende

So sieht meine Configuration aus:

In Postman kommt Unauthorized. Im Webbrowser wird nach Logindaten gefragt.

Warum geht es nur bei mir nicht… Hilfe bitte 🙁

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
3 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
regex9
1 year ago

I could not reproduce your problem so far, so I would suggest you go the same way as I go.

  1. Charge this preconfigured project (via Generate) down. If you don’t use Maven but Gradle or already work with JDK 21, you have to change the configuration beforehand.
  2. Unpack the ZIP archive and open the folder in your IDE (Eclipse/IntelliJ/NetBeans/…).
  3. Pack your ContactController and WebSecurityConfig in src/main/java/com/example/security and adjust the package in both files (com.example.security).
  4. Start the project via mvnw jump-boot:run (Maven) or gradlew bootRun (Gradle)

Open now http://localhost:8080/contactwill Contact returned. Other URLs go to a login page. This also applies to the moment /notices, because this URL is not yet mapped to any page/controller.

Suiram1
1 year ago

I am not an expert for Java and Spring Security, but in the route mapping examples I found, I have always seen that not requestMatchers(), but antMatchers() was used. You could try that.

regex9
1 year ago
Reply to  Suiram1

The antMatcher– Method is obsolete. It has already been removed in version 6.