Spring Boot 3 + Spring Security 6 - JWT Authentication and Authorisation [NEW] [2023]

Amigoscode · 950K views · 2023 · 2:05:52

Open on YouTube

Web developmentSecurity & hackingSoftware architecture & designtutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the tutorial their Spring Security 6 JWT setup was copied from, usually when debugging 403 errors, deprecated config methods or whitelisting endpoints.

Recommended by 1 people across 1 different months, 2023 to 2023.

What it is

A two-hour tutorial by Amigoscode, with code by Ali Bouali, on building JWT authentication and authorisation in a Spring Boot 3 app using Spring Security 6. It sets up a Postgres user table, configures the security filter chain and tests endpoints with Postman.

What people said

Recommends Bogdan Oloeriu · 2023-11 · Stack Overflow · on “How to configure Spring security white list in filter chain properly?”

I appreciate your insights on JWT usage. Regarding our discussion: JWTs can be secure in browsers without exposing sensitive info. My integration needs endpoint protection and whitelisting. A token is required for endpoint access, regardless of the client. Extensive comments led to a discussion somewhat divergent from the main query. The tutorialachieves the desired functionality but lacks step-wise clarity ( [this video] ) Let's keep the discussion focused on finding a working solution please. Appreciate help refining my implementation.

Cites Click me Plzzz · 2023-02 · Stack Overflow · on “Cant access User Entity Fields that implements UserDetails”

So i have this entity on spring boot @Table(name = "user_table") @Data @Builder @NoArgsConstructor @AllArgsConstructor @Entity public class User implements UserDetails { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) @Column(name = "user_id") private Long userId; private String name; private String email; private String password; @Enumerated(EnumType.STRING) private Role role; @ManyToMany @JoinTable( name = "user_course", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "course_id") ) private List < Course > courses; public List < Course > getCourses() { return courses; } public void setCourses(List < Course > courses) { this.courses = courses; }

Cites Kabil · 2023-08 · Stack Overflow · on “Spring Security deprecated methods”

recently I also found this difficult, but somehow I managed to tackle this by learning the lambda [LINK] a little deeper. and this is how I configured the ' securityFilterChain [this video] ()' @Configuration @EnableWebSecurity @RequiredArgsConstructor public class SecurityConfiguration { private final JwtAuthenticationFilter jwtAuthFilter; private final AuthenticationProvider authProvider; @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .csrf(AbstractHttpConfigurer::disable); http .authorizeHttpRequests( (request)-> request .requestMatchers("api/auth/**").permitAll().anyRequest().authenticated()); http .sessionManagement( (session)-> session .sessi

Cites TheAmygdala · 2023-10 · Stack Overflow · on “Spring Boot Security - Every endpoint is 403 forbidden and Spring logs a BasicErrorController#error(HttpServletRequest)”

My application sends a list of servers as json from my database (endpoint "/server/list"). It works fine without all the authentication stuff. I implemented everything from this Tutorial [this video] into my application and I can register a user without any problems, when I send a postman request: [LINK] { "firstname": "Mary", "lastname": "Hyne", "email": "maryhyne@google.com", "password": "asdf" } A JWT Token is generated and I use them in the Authorization header of my other request: [LINK] (Authorization -> Bearer Token) But I always get a 403 Forbidden answer. There is also no helpful Exception. Only the message "Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorCon