Spring Security 6 | How to Create a Login System with Spring Data JPA and JWTs [NEW 2023]

Поделиться
HTML-код
  • Опубликовано: 27 дек 2024

Комментарии • 308

  • @kelvinwarui2982
    @kelvinwarui2982 Год назад +52

    You had me in the first 20 seconds , tutorial hell has brought me here i was almost loosing my mind on spring security

    • @user-zj6iz1rl8d
      @user-zj6iz1rl8d 2 месяца назад

      Spring is probebly the worst framework to learn their is so much bs

    • @44Ricko
      @44Ricko Месяц назад

      @@user-zj6iz1rl8dif it wouldnt be used so much in the industry, i would never fucking touch it again.

  • @cydoentis
    @cydoentis Год назад +28

    This video hit the nail on the head, I watched countless other videos from other people before I found this one, and the content was either outdated or poorly explained. I appreciate that you did everything from scratch and explained each step. Wish I found this video about 8 videos earlier, but I finally understand the whole implementation process for Jwt's. 11/10 will watch again.

  • @adarshpandey8526
    @adarshpandey8526 Год назад +7

    You just revived my passion for spring boot based backend development. Thank you so much. This is the best spring security crash course I've found on RUclips even better than the inspirations you mentioned in this video. The reason is, that you used less jargon and fancy Java. You showed basic Java skills to explain an already complex spring security concept which feels smooth.
    Most of the creators from the Java community tend to use a lot of fancy Java design patterns and advanced Java features which causes great difficulty for freshers to understand such complex concepts.
    Constructive Criticism:
    I have one small suggestion for you, the cutting of your voice is really not good. There are no pauses between your speech, leading to you sounding monotonous even when you're not. Also, it made me rewind many times since I never understood where one sentence ended and the other began.
    Love your content. keep going ♥

  • @vsaihruthikreddy7127
    @vsaihruthikreddy7127 10 месяцев назад +1

    All I could say this is an extraordinary tutorial. I tried all of the spring security tutorials but they did not cover the nitty gritty aspects of it like the jwt token creation and authorization but you just were superb. Thank you very much for uploading a gem ❤

  • @CarlosSousa-cq3jc
    @CarlosSousa-cq3jc 7 месяцев назад +1

    After thousands of videos on spring security, I finally found an excellent one

  • @tyjantefinn4791
    @tyjantefinn4791 3 месяца назад +1

    You are a true champion by not using Lombok Sir. Lol. When you did your first round of Encapsulation, I immediately implemented Lombok ;D

  • @maz1ogra
    @maz1ogra Год назад +2

    This video is a compilation of everything useful that is said in the other videos, discarding all the other useless things that are said, updating it to the latest versions of spring.
    Liked the video, keep it up.

  • @fetterollie54
    @fetterollie54 Год назад +7

    Great video and working around the deprecated methods wasn’t too bad and was a very good practice of working with documentation. Thanks for putting this all together. 👏🏼👏🏼👏🏼

    • @mathewfrancis4167
      @mathewfrancis4167 Год назад

      how did you get the JwtAuthenticationConverter to work in the SecureityFilterChain ?

    • @fetterollie54
      @fetterollie54 Год назад +1

      @@mathewfrancis4167 I’ll check in a bit and get back to you

    • @mathewfrancis4167
      @mathewfrancis4167 Год назад

      @@fetterollie54I'll be infinitely great-full when you will :)

    • @fetterollie54
      @fetterollie54 Год назад

      @@mathewfrancis4167
      Not sure if you can put code blocks in here:
      @Bean
      public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
      http
      // disable cross site request forgery
      .csrf(csrf -> csrf.disable())
      // any http requests are authorized
      .authorizeHttpRequests(auth -> {
      auth.requestMatchers("/auth/**").permitAll();
      auth.requestMatchers("/admin/**").hasRole("ADMIN");
      auth.requestMatchers("/user/**").hasAnyRole("ADMIN", "USER");
      auth.anyRequest().authenticated();
      });
      http
      .oauth2ResourceServer((oauth2) -> oauth2.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())));
      http
      .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
      // build into security chain
      return http.build();
      };

    • @fetterollie54
      @fetterollie54 Год назад +1

      Also I stepped away from the project a month ago and haven’t looked at it since. Hope this is what you are looking for…

  • @yousufbaig821
    @yousufbaig821 7 дней назад

    Just one word about this video - PERFECT.

  • @aman_deep21
    @aman_deep21 Год назад +10

    What a fantastic to the point video it is, Thank you so much Ethan for sharing valuable knowledge with all of us, my knowledge before and after watching this video has increased very much, looking forward to more of your videos.
    I had watched a bunch of videos on this topic, but your explanation made it much easy to follow and code along with you.

  • @cod4basterd
    @cod4basterd Год назад +10

    Holy crap. Thank you so much; this is amazing. Top tier content. I learned so much from this compared to hours of Amigoscode or Dan Vega. Nothing against those guys, they just have so much content to get through and a lot of it is outdated. Thank you so much for putting this together. I got what I needed out of it and then some.

  • @mohssinedardar410
    @mohssinedardar410 Год назад +1

    Thank you so much! I highly recommend this video to anyone who wants to learn about Spring Security. It is a comprehensive and informative resource :)

  • @sajithkumarganesan9823
    @sajithkumarganesan9823 Год назад +3

    Fantastic Video, Thank you for putting all this together in one place and having it explained very clearly and at a steady pace. Great work!!!

  • @apurvasaha8871
    @apurvasaha8871 Год назад +4

    Finally found a video for working around the older deprecated methods. Thank you very much.
    Edit:
    Unable to generate the jwt token during login, and getting a 401 Unauthorized error response back.
    Might be an issue with the deprecated jwt() method in oauth2ResourceServer(oauth2ResourceServerConfigurer::jwt()).
    But even with the new code oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults())) which provides a default implementation of the oauth2ResourceServerConfigurer class its not working.
    If anyone has faced the same issue and solved it, Please let me know. Thank you.

    • @TheMrBatica
      @TheMrBatica Год назад +2

      I had exact the same issue but I skipped the line 'daoProvider.setPasswordEncoder(passwordEncoder());' under SecurityConfiguration class -> AuthenticationManager ... i had only "daoProvider.setUserDetailsService(detailsService);" hope it helps.

    • @manmitapatnaik2513
      @manmitapatnaik2513 Год назад

      Yes please help in this. I am facing the same issue in intellij.

    • @manmitapatnaik2513
      @manmitapatnaik2513 Год назад

      ​@@TheMrBaticaBut here daoAuthenticationProvider.setUserDetailsService(detailsService) is used . So what did you exactly change

    • @TheMrBatica
      @TheMrBatica Год назад

      I wrote what was my problem. I didn't have -> 'daoProvider.setPasswordEncoder(passwordEncoder());

    • @bochunator1173
      @bochunator1173 9 месяцев назад

      @@TheMrBatica Thanks, I had the same problem. Maybe someone has the same issue, so here I put proper code: @Bean
      public AuthenticationManager authManager(UserDetailsService detailsService) {
      DaoAuthenticationProvider daoProvider = new DaoAuthenticationProvider();
      daoProvider.setUserDetailsService(detailsService);
      daoProvider.setPasswordEncoder(passwordEncoder());
      return new ProviderManager(daoProvider);
      }

  • @Mihai-mb4ew
    @Mihai-mb4ew Год назад +2

    Man, this video is top notch. It is exactly what was missing from youtube. Could you, please, share with us, how did you figure all this out? What materials did you use for documentation or how was your thought process? Or maybe is it just experience? I watched Dan Vegas' video about JWT and I was really wondering how to achieve role authorization. I wouldn't have figured it out by myself.

  • @superkobke
    @superkobke Год назад +3

    Well done. Had some troubles with dependencies but overall your video is quite amazing! Thank you so much!

  • @romanlobko1293
    @romanlobko1293 Год назад +1

    Amazing video! Such a complex topic was explained in a relatively simple way, thank you!

  • @sherlockholmes1605
    @sherlockholmes1605 Год назад +8

    Liked the video! Here's an idea for future tutorials, can you create git branches for each chapter? this way we can go back and forth between different chapters to compare and contrast the changes.

  • @pranavthakkar2720
    @pranavthakkar2720 11 месяцев назад

    The Best explanation I have even seen for spring security and jwt authentication. Thanks alot.

  • @mrowox
    @mrowox Год назад +6

    What I usually want to see in security videos is handling security for different type of roles. E.g a backend service for sellers and buyers, drivers and riders, students and teachers and so on

    • @jhonandersonperaltaochoa9833
      @jhonandersonperaltaochoa9833 Год назад

      lo que tu quieres es manejo de roles

    • @anywho3934
      @anywho3934 Год назад +2

      hey have you figured it out ? any other resources you found ? cause I have to implement it in project

    • @MyBinaryLife
      @MyBinaryLife Год назад +2

      this logic is implemented in the SecurityFilterChain bean in your security configuration class

  • @koffeetalk
    @koffeetalk Год назад +2

    Wow, first time I get it right. Thank you! This channel should have much more followers.
    I had some issues using Lombok, but when I did all the constructors, getters, setters manually it's finally worked! I guess I need more experience with constructors first, then use lombok.

    • @unknownkoder
      @unknownkoder  Год назад +3

      I have also had issues with Lombok and I know others sometimes do as well. That is why I chose not to use it in this video.

  • @SailBuddha
    @SailBuddha Год назад

    This was fantastic! I followed it, but changed JPA to jdbcTemplate, because the road to Hell is paved with too much abstraction. Doing it that way, everything made perfect sense. Thank you!

  • @aharoJ
    @aharoJ Месяц назад

    Absolute gold of a video

  • @DarkHid3
    @DarkHid3 11 месяцев назад

    Good video, I watched it to the end, kinda hard to understand the whole thing because I've just started learning this framework but with the time for sure I will comeback and watch it again!

  • @kwamekyeimonies
    @kwamekyeimonies Год назад

    Yeah, very true.about 80% of the videos sessions use deprecated modules

  • @ShermukhammadKarimov
    @ShermukhammadKarimov 4 месяца назад +1

    thanks for this amazing masterclass

  • @shauryatomer1058
    @shauryatomer1058 7 месяцев назад

    Thanks, for this great tutorial. Concise and blazingly fast.

  • @pradeepk2864
    @pradeepk2864 Год назад +1

    perfect video, everything will go smoothly without getting any blocker for me, thanks brother for such a nice video😍

  • @anurp4173
    @anurp4173 Год назад

    Wow, you had me in the first 20 seconds. Got the problem absolutely spot on. thanks

    • @anurp4173
      @anurp4173 11 месяцев назад

      I have done exactly as you have mentioned in the video upto configuring basic authentication, I keep getting 401 unauthorized exception despite supplying the username and password correctly

  • @daffarandika3148
    @daffarandika3148 5 месяцев назад

    clear and concise, great video mate!

  • @simeonrubko1218
    @simeonrubko1218 Год назад +2

    Fantastic video...only problem I recieved was at 1:35:00 during login There is no PasswordEncoder mapped for the id "null" i don't know if I have done something wrong or need to update spring security....it doesnt work with admin as well

    • @unknownkoder
      @unknownkoder  Год назад

      Double check the repository in the description, I believe you are missing the mapping for the password encoder in the SecurityConfig class.

    • @simeonrubko1218
      @simeonrubko1218 Год назад

      I double checked it and there was nothing missing..but when I copied all code from Config class it suddenly worked..thanks for the answer@@unknownkoder

    • @simeonrubko1218
      @simeonrubko1218 Год назад

      I have one more question though..now that we have functional webapp working through postman.. how can I set up this to work within webpage ? I mean now we have working hashing and tokens.. I created login and register form.html but don't know how to connect those parts together

    • @rohity294
      @rohity294 Год назад

      @@unknownkoder same error for me too.

    • @NishantBudia
      @NishantBudia Год назад

      I had the same problem,
      for me I had not set the password encoder in the AuthenticationManager Bean in security config
      @Bean
      public AuthenticationManager authManager(UserDetailsService detailsService){
      DaoAuthenticationProvider daoProvider = new DaoAuthenticationProvider();
      daoProvider.setUserDetailsService(detailsService);
      daoProvider.setPasswordEncoder(passwordEncoder()); //this line I had not written
      return new ProviderManager(daoProvider);
      }

  • @Justdiealready6
    @Justdiealready6 2 месяца назад

    this guy is a true legend fr

  • @maingawesley8212
    @maingawesley8212 10 месяцев назад

    Trust me I haven't started this tutorial, I just read the description and I know Spring Security is bagged already😆😅

  • @alexbrun6863
    @alexbrun6863 Год назад +1

    Absolute legend for making this

  • @kheydbeats
    @kheydbeats Год назад

    It was indeed an absolute Behemoth of a video! Great tutorial, loved the pacing and the explanations. My subscribe and like is your good sir.

  • @manmitapatnaik2513
    @manmitapatnaik2513 Год назад +4

    1:35:11 Here when i am trying to hit it on postman, i am getting 401 unauthorised error. The error was "No password mapped for id "null" .
    Please help !!
    Edit: This problem is solved using oauth2ResourceServer((oauth2) -> oauth2.jwt(Customizer.withDefaults()) because jwt is depriciated.
    Another one that could be helpful is using (oauth2) -> oauth2.jwt(jwtConfigurer -> jwtConfigurer.jwtAuthenticationConverter(jwtAuthenticationConverter())) ) while using convertor.

    • @rohity294
      @rohity294 Год назад

      same error and stuck

    • @mytestchannel8256
      @mytestchannel8256 Год назад

      thanks for the comment. can you please also write the jwtAuthenticationConverter method? @manmitapatnaik2513

    • @manmitapatnaik2513
      @manmitapatnaik2513 Год назад

      ​@@mytestchannel8256 the same as shown at 1:36:48

    • @mytestchannel8256
      @mytestchannel8256 Год назад +1

      I solved by the adding the line "daoProvider.setPasswordEncoder(passwordEncoder());" to the authManager method.
      @Bean
      public AuthenticationManager authManager(UserDetailsService detailsService) {
      DaoAuthenticationProvider daoProvider = new DaoAuthenticationProvider();
      daoProvider.setUserDetailsService(detailsService);
      daoProvider.setPasswordEncoder(passwordEncoder());
      return new ProviderManager(daoProvider);
      }

    • @batuhanerol1172
      @batuhanerol1172 Год назад +1

      Thank you for your solution! It helps me a lot!

  • @harshpratapsinghshekhawat3034
    @harshpratapsinghshekhawat3034 Год назад

    Much needed video on the upgraded ways of Spring Security, I'm glad that i was able to find it
    I have a request though, could you also post a video on formLogin using spring security

  • @lucaspraado
    @lucaspraado Год назад +3

    Hi man, i have this erro in my securityConfiguration.
    line : .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
    Error: 'jwt()' is deprecated and marked for removal
    Do you no fix?

    • @onadiranbayonle2368
      @onadiranbayonle2368 Год назад

      you can have it like this
      http
      .oauth2ResourceServer(oauth2 -> oauth2
      .jwt(jwt -> jwt
      .jwtAuthenticationConverter(jwtAuthenticationConverter())
      )
      );

    • @josefjanda4008
      @josefjanda4008 Год назад

      Is this some help for this part of code?

    • @ashishprakashsingh9073
      @ashishprakashsingh9073 10 месяцев назад

      If anyone please help

  • @KieranMueller
    @KieranMueller Год назад +4

    fyi if you are struggling with deprecated methods, or other things (example: I was unable to run project due to an error with the security filter chain method, request matchers specifically. You can always just downgrade the version of Spring Boot in your POM.xml to use what was used in the video and everything will work.

  • @amitgrover1992
    @amitgrover1992 Год назад +2

    Thank for the detailed explanation, please suggest how to do authentication for an application using Thymeleaf and MVC controller.

  • @rashidcollins6337
    @rashidcollins6337 Год назад

    one of the best security tutorial, clear explanation, am now confidence about spring security. Thank you @Unknown Coder

  • @kumar-mh6hy
    @kumar-mh6hy Год назад

    great content video with proper explanation keep doing contents like this 😍, i was looking for this type content for many days, i just wasted a lot of time but this saved my time and can explain how to save roles in DB annd retrieve it from DB and also about OAuth 2.0

  • @carlosmollapaza9267
    @carlosmollapaza9267 10 месяцев назад +1

    How to validate jwt is invalid or expired?

  • @malbunb
    @malbunb Год назад +2

    This is a greate tutorial. Thanks for that!

  • @professionalyoutubevideowa37
    @professionalyoutubevideowa37 Год назад

    Excellent tutorial. This is just what I needed to get started.

  • @dev-i2m
    @dev-i2m 10 месяцев назад

    Absolutely amazing video, learned a lot from this, Thanks!!

  • @jackedkarlmarx
    @jackedkarlmarx 6 месяцев назад +1

    Hey @Unknown Koder, I fixed the bug you encountered at 1:41:35, apparently this stems from a deprecated use of the jwt() Method, this is the correct way of configuring it as of Spring Security 6.1.x:
    .oauth2ResourceServer((oauth2) -> oauth2
    .jwt(jwtConfigurer -> jwtConfigurer.jwtAuthenticationConverter(jwtAuthenticationConverter())))

  • @dimkaddd7674
    @dimkaddd7674 9 месяцев назад

    why there is no doFilterInternal to filter the JWT and check if it was valid, and as I remember there was a secret key that is used to generate JWT

  • @maelina2222
    @maelina2222 6 месяцев назад

    This is a really great tutorial. Thanks for this

  • @curiosabouttech
    @curiosabouttech Год назад

    Thank you so much after searching alot i found this video that covered my ground up spring security and jwt thank you man.

  • @Justsomeguy492
    @Justsomeguy492 Год назад

    thanks for a clear video. its incredible how spring security team has no good documentation for spring security 6

  • @madukaPcm
    @madukaPcm 9 месяцев назад

    Greate tutorial,
    Am asking for getting an end-point which returns an access token by accepting refresh token, Note Access token should also be returned on login attempt.

  • @QmGhq2T7CzQ
    @QmGhq2T7CzQ Год назад

    I am using DOMA, I can't declare the Set authorities as it says it is not supported as persistent type.

  • @satyaprasannadash5401
    @satyaprasannadash5401 Год назад +1

    the video is really helpful, but faced a problem, can you help me out ?
    1:09:44 => there is no arg for httpBasic() method in Filtercahain config method
    1:09:47 => Suddunly a the arg appeared as httpBasic(withDefaults())
    can you explain the purpose of withDefault() method? did you create it or it will be refered from somewhere else

    • @unknownkoder
      @unknownkoder  Год назад +1

      If you take a look at the repository in the description, and go to the AuthConfiguration class you will see that withDefault() is a static import from Spring Security.

    • @satyaprasannadash5401
      @satyaprasannadash5401 Год назад +2

      @@unknownkoder Thanks for clarification, btw the actual problem is, I am facing while adding the permitAll() access to the auth/** for registraion at 1:09:50 , I got an error while starting the server after adding it i.e
      Factory method 'filterChain' threw exception with message: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).
      so I think it may prevented by adding withDefaults(), but showing same even after addding, can you help me out ?

  • @sanctusfides
    @sanctusfides 8 месяцев назад

    Is there any need for the JWT Auth Converter to set the roles to "ROLE_ROLENAME" if you just set the roles in the DB to be begin with "ROLE_"?

  • @khacthinh23.06
    @khacthinh23.06 Год назад

    tôi mới học khá lúng túng với spring security nhưng xem hết video của bạn tôi đã hiểu hơn rất nhiều, cảm ơn video của bạn.

  • @ajaypt1947
    @ajaypt1947 Год назад +3

    Spring Security is confusing but you did a great job.
    I found a lot of things in one place it helped me a lot.
    Thanks

  • @mathewfrancis4167
    @mathewfrancis4167 Год назад +1

    Lovely just what i needed ... i'm new to this level of spring security ... so I hope this question isn't a silly one ... i would like to know how and where you generated the public and private key in you code... thank you :)

  • @bajrangchapola6748
    @bajrangchapola6748 11 месяцев назад

    Great Content!!! Can you make a video on how this authentication backend works with API gateway ? Any of the members if know

  • @jumaiddotuya2797
    @jumaiddotuya2797 Год назад

    There is a problem casting the Principal to UserDetails as per your implementation.. any ideas? Am trying to get the logged in user via SecurityContextHolder.. thanks

  • @nguyenhoanganh7228
    @nguyenhoanganh7228 Год назад +2

    I'm following the tutorial but I get problem with login, I get 401 . Can you explaint it for me . Thanks

    • @unknownkoder
      @unknownkoder  Год назад

      401 means that the security configuration is not allowing connections through. So check that.

    • @nguyenhoanganh7228
      @nguyenhoanganh7228 Год назад +2

      @@unknownkoder I got the error : "There is no PasswordEndcoder mapped for the id "null" ". I created PasswordEncoder bean follow your tutorial. I dont know why login not working, I test api in register and it works normally

    • @unknownkoder
      @unknownkoder  Год назад

      @@nguyenhoanganh7228 I think later on in the video I made a correction where I missed a line of code for the password encoder.

    • @matasdanisas8864
      @matasdanisas8864 Год назад +1

      @@unknownkoder I have the same error and there is no fix in the later minutes of the video

    • @davidpinzon8440
      @davidpinzon8440 Год назад +1

      @@nguyenhoanganh7228 In your SecurityConfig code the authManager like this:
      @Bean
      public AuthenticationManager authManager(UserDetailsService detailsService){
      DaoAuthenticationProvider daoProvider = new DaoAuthenticationProvider();
      daoProvider.setUserDetailsService(detailsService);
      daoProvider.setPasswordEncoder(passwordEncoder());
      return new ProviderManager(daoProvider);
      }

  • @luky7143
    @luky7143 8 месяцев назад

    Do I understand it correctly that in the client after login i need to save the token from server response and put it to every request made afterwards?

  • @Blazs120gl
    @Blazs120gl Год назад

    Hi, this was an exhaustive example I've been looking for. Thank you very much!
    I would like to extend this project with static HTML pages. How can I do that?
    I've added HTML pages (e.g. an index.html under resources/static) but I can't access any of the pages. they're all blank and I get 401 responses to them.
    I tried to add the static path to auth request matchers, but no joy so far. Any ideas what's missing? Thanks in advance!

  • @Mihai-mb4ew
    @Mihai-mb4ew Год назад

    Hey guys! Is it normal for role authorization to not work without a Converter even if we set the role in DB as ROLE_ADMIN for example? Because I just spent a lot of time with it and it did not work at all even if I would use roles such as "ROLE_USER", "ROLE_ADMIN". It began working only after setting the roles in DB as simply "ADMIN" and "USER" then adding the converter as in the video.

  • @QmGhq2T7CzQ
    @QmGhq2T7CzQ Год назад

    Now I am experiencing dependencies cycle from AuthenticationService to SecurityConfiguration with the AuthenticationManager. How am I fix this?

  • @kaydanderson4487
    @kaydanderson4487 Год назад

    Awesome video, I followed everything you said (mostly) and got postman working at the end, but Im a bit confused on how to implement a login page and move to a secured page?

  • @WilliamBurroughs-q3b
    @WilliamBurroughs-q3b Год назад +2

    Thanks very much for the vid! Really enjoy your teaching style!
    I am having a bit of a problem though, when I change the loadUserByUsername() method inside the UserService class to call findUserByUsername on the repo, the app stops accepting a valid username & password combination of admin.
    I have checked the database and the user admin tuple is definately there but I get an error 401 no matter what I enter?
    Have been stuck on this for a few days so would appreciate any help!
    Thanks very much in advance!

    • @unknownkoder
      @unknownkoder  Год назад +1

      Sounds like a problem in the Spring security configuration most likely.

    • @WilliamBurroughs-q3b
      @WilliamBurroughs-q3b Год назад

      @@unknownkoder Configuration
      public class SecurityConfig {
      @Bean
      public PasswordEncoder passwordEncoder(){
      return new BCryptPasswordEncoder();
      }
      @Bean
      public AuthenticationManager authenticationManager(UserDetailsService detailsService){
      DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
      daoAuthenticationProvider.setUserDetailsService(detailsService);
      return new ProviderManager(daoAuthenticationProvider);
      }
      @Bean
      public SecurityFilterChain filterChain (HttpSecurity http) throws Exception{
      http
      .authorizeHttpRequests((authz) ->
      authz.anyRequest().authenticated()
      )
      .httpBasic(withDefaults());
      return http.build();
      }
      }
      This is my ssecurityConfig at 47 mins - Can you see anything that might be causing this?
      Thanks in advance!

    • @paulosamvrosiadis3484
      @paulosamvrosiadis3484 Год назад

      i have the same problem , have you solved it ?

    • @WilliamBurroughs-q3b
      @WilliamBurroughs-q3b Год назад

      @@paulosamvrosiadis3484 Yes!
      Turns out I wasn't sending the POST request properly. Using postman & ensuring I was sending a POST request properly helped solve it. Goodluck!

    • @hamzaazeem4602
      @hamzaazeem4602 Год назад

      Same problem :(

  • @abdulaibah9396
    @abdulaibah9396 Год назад +1

    towards the end when we were setting up the jwt auth converter alot of the stuff you shown was deprecated. So i switched it over to the more recent stuff but when i coded it im getting an 403 forbidden error.

    • @goshochernii
      @goshochernii 7 месяцев назад

      after getting the jwt token right? did you find a solution?

  • @Chrisbees
    @Chrisbees Год назад +1

    How do you use this with frontend? Do you have a tutorial for this?

    • @unknownkoder
      @unknownkoder  Год назад

      I dont have a one for one tutorial, but my twitter series shows building a login and registration system with react and spring security.

    • @Chrisbees
      @Chrisbees Год назад

      @@unknownkoder I have built one with react and Springboot before but I used Redux for my security and jwt tokens, but is there any other less complicated way?

  • @akhicj9071
    @akhicj9071 Год назад

    Hi bro,i have face one problem there is no error in my code.i have been writing commandlinner runner after i run this mhy progrma there is no error and go to postman send the username,password i was face 401 error.what i made mistake.why we are using commanlineer interface instade of we can create any onther classes

  • @houss3105
    @houss3105 Год назад

    Anyone else got stock with a error: "There is no PasswordEncoder mapped for the id "null" at 1:35 ?

    • @kadrimv5202
      @kadrimv5202 10 месяцев назад

      Hey! I have just reached this problem in my app. I got 40-1 while login. I just added PasswordEncoder in authenticationManager.
      @Bean
      public AuthenticationManager authenticationManager(UserDetailsService detailsService, PasswordEncoder passwordEncoder){
      DaoAuthenticationProvider daoAuthenticationProvider=new DaoAuthenticationProvider();
      daoAuthenticationProvider.setUserDetailsService(detailsService);
      daoAuthenticationProvider.setPasswordEncoder(passwordEncoder);
      return new ProviderManager(daoAuthenticationProvider);
      }

    • @moeking2627
      @moeking2627 9 месяцев назад

      @@kadrimv5202 was having the same issue and this fixed it THANK YOU SO MUCH

  • @sidof8065
    @sidof8065 Год назад

    I how to do to allow user to access and resource when his already been logged. and don't have toprovide access token again on the frond end?

  • @sanyamsharma9526
    @sanyamsharma9526 Год назад

    At 1:09:43 - "public SecurityFilterChain ....." is at line 30 but,
    at 1:09:44 - It is at line 32.

    • @sanyamsharma9526
      @sanyamsharma9526 Год назад

      After this step the program is not running and giving this error:
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filterChain' defined in class path resource [com/sanyam/springsecurity0609/configuration/SecurityConfiguration.class]: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'filterChain' threw exception with message: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).
      This is because there is more than one mappable servlet in your servlet context: {org.springframework.web.servlet.DispatcherServlet=[/], org.h2.server.web.JakartaWebServlet=[/h2-console/*]}.
      For each MvcRequestMatcher, call MvcRequestMatcher#setServletPath to indicate the servlet path.

    • @Arrturoo
      @Arrturoo Год назад

      ​@@sanyamsharma9526 I had the same issue. Below I am sending my solution.
      @Bean
      public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospector introspector) throws Exception{
      MvcRequestMatcher.Builder mvcMatcherBuilder = new MvcRequestMatcher.Builder(introspector);
      return http
      .csrf(csrf -> csrf.disable())
      .authorizeHttpRequests((requests) -> requests
      .requestMatchers(mvcMatcherBuilder.pattern("/auth/**")).permitAll()
      .anyRequest().authenticated()
      )
      .httpBasic(withDefaults())
      .build();
      }

  • @michaels2048
    @michaels2048 Год назад

    Thank you for the video, do you know how i can be able to display this information in my next js project

  • @tylerljohnson
    @tylerljohnson Год назад

    excellent tutorial, and thank you for the timestamps!

  • @billyburroughs2136
    @billyburroughs2136 Год назад

    Hi!
    When I run the Maven app and try and access an endpoint in browser I get: “Request Method ‘GET’ is not supported.
    Do you know what could be causing this?
    The only difference between yours is I am using Postgres driver.
    Thanks!

  • @rabbitrobe8872
    @rabbitrobe8872 8 месяцев назад

    does this implementation works with connecting to frontend angular ?

  • @duri467
    @duri467 8 месяцев назад

    mega tutorial man, THANKS !

  • @existence_zero1692
    @existence_zero1692 Год назад

    This video is the best spring security video ❤

  • @zigyias347
    @zigyias347 11 месяцев назад

    thank you very much, I stucked at OAuth2ResourceServiceConfigurer :: jwt it already depricated, how to solve could someone answer please

    • @sanctusfides
      @sanctusfides 8 месяцев назад +2

      Most of the security chain changes have moved them to similar styles with lamba functions. In this case I was able to solve it by using
      .oauth2ResourceServer((oauth2 -> oauth2
      .jwt(Customizer.withDefaults())))

  • @aihsdiaushfiuhidnva
    @aihsdiaushfiuhidnva Год назад

    hmm how strange when i send a username and password like 1:10:40, the json response that i got said "authorities: null" eventhough i checked with my database and everything was correct

    • @aihsdiaushfiuhidnva
      @aihsdiaushfiuhidnva Год назад

      nevermind i fixed it, turns out i left my getAuthorities method to return null.

  • @aashirsiddiqui177
    @aashirsiddiqui177 Год назад

    Thanks for the vid, the deprecated APIs were a pain in the ass!

  • @eugenesmith9940
    @eugenesmith9940 Год назад +1

    Do we really need to return user credentials (even if it's wrapped into some DTO without any sort of sensitive information)? I mean is it so-called "best practice" or we can just return simple status code? Is it mandatory to return anything or we can just use void methods in such cases?

    • @unknownkoder
      @unknownkoder  Год назад +1

      Its not mandatory, however some applications may use some of the users information in the frontend of the application. This is why I send back basic info in the tutorial.

  • @mrowox
    @mrowox Год назад

    From your implementation, how will it be possible to add permission to a users roles? from what I can see, there can only be one authority/permission. I am not too clear on that part.
    Also previous videos I have seen usually have a secret in the application.properties file that the jwt encoder uses. why dont we have that? is it because we are using the RSA encryption thing? if you have links that explain this in springboot context, I will appreciate if you can share it.
    I also did notice one downside in that if the application restarts, users have to login again. Can you explain why this is so?
    And for some reasons, when I try to log the currently logged in user using @AuthenticationPrincipal, I get an error

  • @adamspodniak5822
    @adamspodniak5822 Год назад

    One Question. When the token will be sent back to the user in JSONObject, how do i solve it in the FrontEnd actually? User has to insert the Token in order to log in and access the Website. Email it to the user is bullshit, isnt it? Or am i missing something?

  • @olliDeg
    @olliDeg Год назад

    Great video, really helpful!

  • @TheQuancy
    @TheQuancy Год назад

    I'm trying to do this with MongoDb as the database, and I lose myself when i end up trying to create the roles. Since MongoDb isnt a relational db, its a little confusing when im trying to make "join tables"

  • @thomasvs2911
    @thomasvs2911 Год назад +5

    Hey, I get the following error trying to login following your tutorial:
    java.lang.IllegalArgumentException - There is no PasswordEncoder mapped for the id "null".
    Could you help me?

    • @unknownkoder
      @unknownkoder  Год назад +1

      You missed setting up a bean somewhere inside of the configuration would be the first place to look.

    • @thomasvs2911
      @thomasvs2911 Год назад +9

      @@unknownkoder Ty for the reply. I fixed it by changing the PasswordEncoder bean to:
      @Bean
      public PasswordEncoder passwordEncoder() {
      String idForEncode = "bcrypt";
      Map encoderMap = new HashMap();
      encoderMap.put(idForEncode, new BCryptPasswordEncoder());
      return new DelegatingPasswordEncoder(idForEncode, encoderMap);
      }
      This adds the {bcrypt} prefix to passwords stored in the DB and fixes the problem.

    • @mikezoola1
      @mikezoola1 Год назад

      @@thomasvs2911 What you needed to do was
      @Bean
      public AuthenticationManager authenticationManager(UserDetailsService userDetailsService) {
      DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
      daoAuthenticationProvider.setUserDetailsService(userDetailsService);
      daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
      return new ProviderManager(daoAuthenticationProvider);
      }
      You forgot to set the password encoder here. Change your password encoder back to Bcrypt

    • @aman_deep21
      @aman_deep21 Год назад +1

      I also encountered the same problem, your solution helped me out, thank you)

    • @eugenesmith9940
      @eugenesmith9940 Год назад +2

      you need to add daoProvider.setPasswordEncoder(passwordEncoder()); to your authManager() method

  • @Sparrow-tn9jj
    @Sparrow-tn9jj Год назад

    Hello, good tutorial. Can you please tell me how to deal with CORS? Simply adnotating the controller wont work

    • @unknownkoder
      @unknownkoder  Год назад

      Theres a CORS configuration you must setup inside the Configuration class and inside the config bean

  • @timonka1zer822
    @timonka1zer822 9 месяцев назад

    Thank you for your content!

  • @codex8797
    @codex8797 11 месяцев назад +1

    Thank you so much bro, you are a life saver

  • @Trieuat_Vo
    @Trieuat_Vo Год назад

    I have a little confuse. Are u using Authorization Code or Resource Owner Password Credentials. Can u help me to clear my mind

  • @Justin_Jay
    @Justin_Jay Год назад

    Wow. Thank you for this. Brilliant

  • @podcasts.clips.delivery
    @podcasts.clips.delivery Год назад

    Brother, you are a lifesaver!

  • @salehemwanga5408
    @salehemwanga5408 Месяц назад

    Great Video!

  • @RotorVideos01
    @RotorVideos01 10 месяцев назад

    Thank you for the video!

  • @gaddp
    @gaddp Год назад

    sick hoodie man

  • @sakthinivas1840
    @sakthinivas1840 Год назад

    Whats the tool being used to create the architectural diagram in your video?

  • @sougatasingha9587
    @sougatasingha9587 9 месяцев назад

    Nice tutorial but can you tell me how do I follow these steps from spring security documentation?

  • @gatio23
    @gatio23 Год назад

    Very nice video! Can you tell me how to log out with a jwt token? Should I store it in tokenRepo and disable it on logout? Thanks!

    • @unknownkoder
      @unknownkoder  Год назад

      Yes, there should be something along the lines of an invalidate method for your token object.