Microservices Security Using JWT | Spring Cloud Gateway | JavaTechie

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024
  • This tutorial will guide you How to secure your microservices with with JWT Authentication using Spring Cloud Gateway.
    We are going to discuss an architecture in which one microservice will act as a api gateway service which does central authentication, redirect an incoming request to other microservices. The main advantage of this architecture is you can easily add multiple microservices to the system and all authentication, authorization will be taken care from a central unit
    #Javatechie #Microservice #Security #JWT
    Spring boot microservice Live course Just started (Recordings available)
    Hurry-up & Register today itself!
    COURSE LINK : javatechie5246...
    PROMO CODE : Java40
    GitHub:
    github.com/Jav...
    Blogs:
    / javatechie
    Facebook:
    / javatechie
    guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
    Disclaimer/Policy:
    --------------------------------
    Note : All uploaded content in this channel is mine and its not copied from any community ,
    you are free to use source code from above mentioned GitHub account
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 492

  • @Nexgenstory
    @Nexgenstory 2 หลายเดือนก่อน +2

    Could you explain me : Client -> Security Service (GenerateToken) -> API Gateway -> MicroService1 (validate JWT) this flow is fine . What happen we request come directly to Client-> Microservice1 . How to check JWT for each endpoint.

    • @aishaprasad5555
      @aishaprasad5555 2 หลายเดือนก่อน +3

      How to block each microservice endpoint to access??

  • @treefrog9392
    @treefrog9392 ปีที่แล้ว +36

    I feel like your explanations are even better than people who have english as their first language lol. You really do have a gift for this!

  • @Akash-tq1ui
    @Akash-tq1ui ปีที่แล้ว +4

    Hi Basant ,
    Very useful tutorial however I have one doubt, In production when the token is generated by passing a valid username and password it should automatically pass the token to the gateway right but here I saw that you are manually passing the token to the gateway through Postman for accessing microservices, My question is how we can automatically pass the token to the gateway for accessing microservices when the token is generated

    • @Javatechie
      @Javatechie  ปีที่แล้ว +2

      Your question is genuine but this automatically stuff needs to handle from UI not from the backend

    • @Akash-tq1ui
      @Akash-tq1ui ปีที่แล้ว

      @@Javatechie ok thank you!

  • @impertator644
    @impertator644 ปีที่แล้ว +31

    I love you. Finally the architecture I'm looking for. A lot of tutorial are covering authentication for only one microservice and you are probably the only one that approaches the problem keeping in mind the whole microservice architecture.

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Thank you so much Lukasz for appreciating my work 🥰🥰

    • @hkkabir2024
      @hkkabir2024 11 หลายเดือนก่อน +1

      you worth millions of like

  • @sadiulhakim7814
    @sadiulhakim7814 9 หลายเดือนก่อน +5

    Hi sir! I am grateful for this tutorial. In this tutorial you have two client services, one gate way, one security service and you added security in Api Gate. I like the way you did it. But i need to move forward and add some Authorization. Suppose in swiggy service there are some end points what only admin can access and some end points normal user can access. How to apply this type of Authorization. Would you please make second part of this tutorial please? I am following this tutorial and trying to learn. I tried to implement the security directly in the API GATE-WAY service. But that was not easy because gate-way supports webflux not the web.

    • @ASHISHKUMAR-jh9kw
      @ASHISHKUMAR-jh9kw 5 หลายเดือนก่อน +1

      make use of method level authorization and roles

    • @Javatechie
      @Javatechie  5 หลายเดือนก่อน +2

      Yes I am still not finding any solution for this approach. Will check and update you

    • @sadiulhakim7814
      @sadiulhakim7814 5 หลายเดือนก่อน

      @@Javatechie Thanks

    • @sadiulhakim7814
      @sadiulhakim7814 5 หลายเดือนก่อน

      @@Javatechie I saw others using OAuth2 to solve this problem. KeyCloak is one of them.

    • @anon_geek
      @anon_geek หลายเดือนก่อน

      @@Javatechie Hey, I found your video helpful, however I wanted to inquire, did you find any solution for this approach?

  • @ВитяМаксимов-л9ш
    @ВитяМаксимов-л9ш 9 วันที่ผ่านมา +2

    Bro, thank you!!! God bless you!!!

  • @vaishali1843
    @vaishali1843 ปีที่แล้ว +1

    1:11:00 The rest call from gateway to auth service is not working. It is throwing an error saying cannot call from java.lang.illegalstateexception: block()/blockfirst()/blocklast() are blocking, which is not supported in thread reactor-http-nio-1. Please let me know if someone can help in this

  • @AmitBenShimon
    @AmitBenShimon ปีที่แล้ว +2

    why did you copy the code of "/validate" to gateway? It's useless now in the identity-service if you run this piece of code from the gateway

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Rather than doing another rest call to identity service i have used it in gateway itself

    • @AmitBenShimon
      @AmitBenShimon ปีที่แล้ว +1

      @@Javatechie i get that, but if this was the goal all along, then why did we implement this in the id-service to begin with? I want to avoid duplicate code.

  • @AlmustaphaTukurUmar
    @AlmustaphaTukurUmar 9 หลายเดือนก่อน +2

    This Video is really helpful, Pls. Can you cover Role base authentication and Authorization on the individual microservices?

  • @vaderashyam7207
    @vaderashyam7207 ปีที่แล้ว +3

    Wow Very Nicely Explained In Easy To Understand Manner.
    1 Request can you please show how to implement role based authentication with Spring API Gateway ?

    • @Javatechie
      @Javatechie  ปีที่แล้ว +2

      Yes buddy it's in queue i will upload soon

  • @monikaraut5266
    @monikaraut5266 ปีที่แล้ว +2

    I am new to microservices & your videos helped me a lott🙌🙌 also can you please tell me, what should I use for role based authorisation in microservices.
    I am working on project which is a web portal for sanctioning government applications, It has user & admin as roles.
    Please guide🙌

    • @SmitBudgetalizer
      @SmitBudgetalizer ปีที่แล้ว

      I am working on jwt token microservices.
      How to logout user or expire token imediate?

  • @dattatraybharde2902
    @dattatraybharde2902 9 หลายเดือนก่อน +3

    Great Video sir, completely Awesome...Add the role based security through api gateway.

  • @pierreescudie1634
    @pierreescudie1634 หลายเดือนก่อน +2

    Finally found an understandable tutorial about securing a Spring Cloud Gateway microservices architecture! A thousand times thank you sir!

  • @viveksingh-rt4py
    @viveksingh-rt4py 7 หลายเดือนก่อน +1

    Awesome videos. Hats off to you in explaining it in a very simple and easy manner. One question.
    May I know if we have a requirement to secure our swiggy and restaurant service endpoint and grant access based on role, then how we can achieve this requirement .

  • @hkkabir2024
    @hkkabir2024 11 หลายเดือนก่อน +2

    Hello sir. there is api still open for each microservice. like calling the order in it's own microservice with port like localhost: 8082 then api is open . if anyone can call that api wihout gateway and security then what is the usage of jwt ???

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน +1

      Simple question can you please answer me how the user will know about the endpoints of your microservice ?

    • @hkkabir2024
      @hkkabir2024 11 หลายเดือนก่อน +2

      @@Javatechie using url or somehow user know the endpoint or hacker know the endpoint. so the endpoints are not secured for each MS. you have to reconsider your code and try to figure out how to secure all the endpoints separately also

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน +1

      @@hkkabir2024 no buddy it will be known by user only if you exposed it . If we are doing that then it's the wrong approach then what is the need for a gateway?

  • @sonliman2192
    @sonliman2192 หลายเดือนก่อน +2

    This video is very useful for me . Thank you for your time and explanation

  • @pranoydas9654
    @pranoydas9654 ปีที่แล้ว +1

    In Gateway service, can you please show us role based authentication. You just showed authentication part but not authorisation. Please show us. It’s very important

  • @bhavanisankar71
    @bhavanisankar71 ปีที่แล้ว +1

    Brother " Set interface how remove duplicates internally " please explain because yesterday interview i am unable to answer simply rejected for this reason

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      It internally uses map buddy i already explained in my interview QA videos please check

    • @bhavanisankar71
      @bhavanisankar71 ปีที่แล้ว

      @@Javatechie ok thanks 😔

  • @malam3958
    @malam3958 11 หลายเดือนก่อน +1

    Thanks for sharing this video.
    I have one question. Do we need of validator.isSecure for endpoints /token, /register, /validateToken? I think no because we are not applying filter for IdentityService then obviously API Gateway will not use the filter. Please correct me I am wrong.

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน

      Yes it's required otherwise wise how can we bipass the request. Currently I am not calling identity service api but as per best practices it's good to do rest API call to validate the token hence above URL required to bypass

  • @MustafaCam-uv5fr
    @MustafaCam-uv5fr 2 หลายเดือนก่อน +1

    great job Sr. does it come with new spring boot verison

  • @ViswanathSandilyaJandhyala
    @ViswanathSandilyaJandhyala 8 หลายเดือนก่อน +1

    Hi @javatechie
    I have a question. What is i dont want to validate the token in cloud-gateway. every request which is coming to gateway and cloud-gateway has to call identity-service to validate the token and send back to cloud-gateway and based on the response it will call the endpoint or throw an exception. Is it possible ??

    • @Javatechie
      @Javatechie  8 หลายเดือนก่อน

      Yes it's absolutely possible that is what I explained in PPT but while explaining code I have added validateToken logic in gateway but you can do that easily just refer flow it will be dead easy

  • @RustemReizov
    @RustemReizov 9 หลายเดือนก่อน +1

    My English is poor. Maybe you talked about this. I understood correctly that in a real project we do not need to create a method for validating tokens in the identity service, because validation needs to be implemented only in Spring Gateway?

    • @Javatechie
      @Javatechie  9 หลายเดือนก่อน

      We can keep it in the gateway that's what I did in this video but it's a bad practice because the key thumb rules of microservice is to segregate functionality to different modules so if I keep security and routing in the same application then it violates the principle isn't it?

  • @pratheeban3650
    @pratheeban3650 ปีที่แล้ว +1

    Basant can you tell me how to JWT token pass through one service to another service as we only sent the payload (order details) to call restaurant API. Here how JWT propagation happening

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Jwt will only pass to api gateway for authentication It won't pass to other microservices Please debug the filter class you will understand

  • @andywang4189
    @andywang4189 หลายเดือนก่อน +1

    Quite informative, thanks!

  • @pavankumarmantha
    @pavankumarmantha ปีที่แล้ว +5

    instead of completely using spring cloud stack we can make this more OSS (open source stack) like every micro service is containerised (dockerised) then use KONG as API gateway. this way we can make the configuration more simple and reduce tight coupling.

    • @mirarima8877
      @mirarima8877 ปีที่แล้ว +1

      Could you please explain more about how that works?

    • @amankumar-f4n5r
      @amankumar-f4n5r ปีที่แล้ว

      can you please come with your hands on similar like this using KONG.

  • @tanson86
    @tanson86 ปีที่แล้ว +1

    For h2 db modify the securityFilterChain in AuthConfig as below
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
    return httpSecurity
    .headers().frameOptions().disable()
    .and()
    .csrf().ignoringRequestMatchers(PathRequest.toH2Console()).disable()
    .authorizeHttpRequests()
    .requestMatchers("/auth/save","/auth/token","/auth/validate").permitAll()
    .requestMatchers(PathRequest.toH2Console()).permitAll()
    .and().build();
    }

  • @three_bachelors
    @three_bachelors ปีที่แล้ว +2

    Hello Sir ,
    In spring data mongodb one annotation is there @Encrypted , How can i use for Encryption with AWs KMS please make a video for this topic
    One more , How to modify RequestBody, response body in Interceptor and pass to controller.

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Okay i will do this

  • @rajraushan3190
    @rajraushan3190 11 หลายเดือนก่อน +1

    really helpful, but I have a doubt, what if someone directly access the microservice url by bypassing the api gateway. how to handle that?

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน

      How does someone know your URL, if you are sharing then it strictly breaks the microservice contract

  • @im_asfar
    @im_asfar ปีที่แล้ว +1

    sir please provide the link from where i can start from developing swiggy and restuarent microservice along with service registry in eureka server....Thanks

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Please checkout the video description I have shared the code

  • @nachiro_dev
    @nachiro_dev 3 หลายเดือนก่อน +1

    Thaaaaaaaaaaaaanks man! nice video

  • @vivekbansal-bc9eg
    @vivekbansal-bc9eg หลายเดือนก่อน +1

    Won't the rest template call to identity service will be blocking and will lead to an issue?

    • @Javatechie
      @Javatechie  หลายเดือนก่อน

      Yes it should be synchronous

  • @metinbicaksiz
    @metinbicaksiz 5 หลายเดือนก่อน +1

    the source coude keeps crashing with intenal server error. Do you have any suggestions about it? Thanks in advance

    • @Javatechie
      @Javatechie  5 หลายเดือนก่อน +1

      Can you please share the exact stack trace in javatechie4u@gmail.com

  • @fsoldierdeth
    @fsoldierdeth 11 หลายเดือนก่อน +1

    i have a question, what if i have 3 microservices (agency -> service -> activities ) and i want to get all activities from the services that an agency offers, do i need to ask for the token 3 times?

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน +1

      It should be done in one go , simply we are applying security on the entry point not in individual microservice

  • @AvinashJ21
    @AvinashJ21 4 หลายเดือนก่อน +1

    Thank you so much !!
    But how can we restrict direct access to individual microservices

    • @Javatechie
      @Javatechie  4 หลายเดือนก่อน +1

      Only one way to avoid exposing them

  • @MedAliJelidi
    @MedAliJelidi ปีที่แล้ว +1

    Thank you! but i have a question! is this enough in term of security in my application and how can i add more security layers

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      This is the way to implement in microservice but if you want more secure then better use 3rd party identity providers like okta or keyclok. I already uploaded a video of keyclok using microservice

  • @udayreddy9619
    @udayreddy9619 ปีที่แล้ว +1

    Thanks for sharing ❤
    But how can we authenticate based on role.
    Here we can access the whole microservice but how can we access some end points of one microservice and other endpoint for another role.

  • @erichhc9698
    @erichhc9698 ปีที่แล้ว +2

    I've been waiting this long, thanks java techie greetings from peru😎

  • @MAMUNGM
    @MAMUNGM ปีที่แล้ว +1

    At last, how to send user info from api gateway to swigy app after filterchain in api gateway validates token

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      You can set it to the header of the api call . I will do a video since i found multiple viewers having the same doubts

  • @saurabhtandel3332
    @saurabhtandel3332 ปีที่แล้ว +1

    How to exclude some API from applying Jwt in the headers.

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Configure those api which you want to bypass in security config class with antMatchers

  • @milanfaizal
    @milanfaizal 21 วันที่ผ่านมา +1

    Awesome video.

  • @florangelacastrocastaneda946
    @florangelacastrocastaneda946 ปีที่แล้ว +1

    How could I add roles authorization? Thanks from Colombia

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Roles even i am looking for that solution.will update you

  • @rahimkhan-fh9dd
    @rahimkhan-fh9dd ปีที่แล้ว +3

    Hey Basant, Once again you delivered nice content which we were looking since long time. I locally setup up and tried it working fine. I have a concern here
    If user directly request to 'Swiggy App' or 'Restaurent Service' then he able to get all details without providing JWT token.
    How secure these 2 apps if user directly send request?

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Hi Rahim think practically why you will expose swiggy and restaurant microservice endpoints directly to the end user. If that is the case API gateway itself is no use right .
      So we should only expose api gateway endpoints that is how we can force everyone to use gateway with token

    • @sumanthkatapally1697
      @sumanthkatapally1697 ปีที่แล้ว +1

      @@Javatechie Hi that was a great explanation, but I have a question. Is there any way we can secure swiggy and restaurant microservice and use it in gateway as well?

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Again we landed in the same context . If this is your requirement then you should avoid using gateway

    • @rahimkhan-fh9dd
      @rahimkhan-fh9dd ปีที่แล้ว +1

      @@Javatechie We can make secure swiggy and restuarent apps too.
      Currently I am on similar kind of project where we secure each microservices app.
      I will update here later.

    • @sumanthkatapally1697
      @sumanthkatapally1697 ปีที่แล้ว

      @@rahimkhan-fh9dd Can you provide more details. It would be helpful. Thanks.

  • @vamsikrishna8643
    @vamsikrishna8643 10 หลายเดือนก่อน +1

    Nice work man, please implement the swegger this application which is used for api documentation, thanks in advance

  • @vedhlikith6252
    @vedhlikith6252 ปีที่แล้ว +5

    Best course available in youtube. Thankfully it is free. Keep up the good work

  • @hardikrao5734
    @hardikrao5734 10 หลายเดือนก่อน +1

    How to stop direct access to swigging and restaurant, and only access via gateway?

    • @Javatechie
      @Javatechie  10 หลายเดือนก่อน +1

      You need to configure cross origin

  • @shivansh7100
    @shivansh7100 8 หลายเดือนก่อน +1

    Hi Basant, Its really good explanation, I have one doubt, how should we handle @PreAuthorize in our microservices in case we are following this pattern.
    Please do answer me , its really urgent for me.

    • @Javatechie
      @Javatechie  8 หลายเดือนก่อน

      Hello Shivansh , I am also not sure about your question if we will go with pre Authorize annotations then in every microservice we need to implement security but that's what is not advisable.i am looking into solution will update you once I find

    • @shivansh7100
      @shivansh7100 8 หลายเดือนก่อน +1

      @@Javatechie thanks

  • @pvsree
    @pvsree 11 หลายเดือนก่อน +1

    Explained very well. My doubt is if there are 100s of microservices all the call will go through API gate way and the auth Service, how to handle API gateway or auth service failure ?

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน

      You need to handle it through DR . In microservice world 🌎 no guarantee of 0 downtime

    • @pvsree
      @pvsree 11 หลายเดือนก่อน

      @@Javatechie thanks

  • @ujjawalk2148
    @ujjawalk2148 7 หลายเดือนก่อน +1

    Great explanation, but you only cover authentication part dosnt cover authorization , can explain that

  • @anhtai5332
    @anhtai5332 ปีที่แล้ว +1

    Thank you so much. Can you do a video share how to config authorization with JWT in microservices ?

  • @phanimc11211
    @phanimc11211 ปีที่แล้ว +2

    Thank you very much for the video., if restaurant service has to call swiggy service using rest template, now we have to include jwt token in httpheaders otherwise we will get 401 authorization as we have implemented jwt authentication is my understanding correct please let me know

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      No phani , we haven't implemented security in microservice level we have added on gateway level so inter communication doesn't require any authentication mechanism

    • @phanimc11211
      @phanimc11211 ปีที่แล้ว +1

      @@Javatechie 🙏🙏👍thanks

  • @yourfilm21
    @yourfilm21 ปีที่แล้ว +1

    bro why you make video too long, why you not make video per part or per episode?

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      YPdw this content needs to be delivered in a single video otherwise it's difficult for both of us to sync with context .
      I agree the video duration might be more because we have not compromised on content each and every concept i delivered with clarity .

  • @sudheerkumar-tp1mg
    @sudheerkumar-tp1mg ปีที่แล้ว +1

    Hi Sir, actually regarding sso in every TH-cam tutorial up to okta telling, but how to modify the database of existing application because already users everything is present, please suggest any video on this.

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      I will cover this

    • @sudheerkumar-tp1mg
      @sudheerkumar-tp1mg ปีที่แล้ว +2

      @@Javatechie thank you so much sir for your quick reply

  • @ayoubalkhalaf3778
    @ayoubalkhalaf3778 11 หลายเดือนก่อน +1

    How to get current authenticated user from all other microservices?

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน

      The only way I need to pass principal info as part of the request header while calling api from other microservices

  • @sidimohamedelhamed4419
    @sidimohamedelhamed4419 ปีที่แล้ว +1

    Thank you! how is it going if i have the UserData in an other service, is there any video with this case ?

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      In our case also user data available in other services right

  • @RustemReizov
    @RustemReizov 9 หลายเดือนก่อน +1

    Why did you create bean UserDetailsService if CustomUserDetailsService anotated with @Component?
    Wouldn't it be better create argument UserDetailsService into authenticationProvider method?

    • @Javatechie
      @Javatechie  9 หลายเดือนก่อน

      Buddy i create a bean of interface where the implementation is CustomUDService

    • @RustemReizov
      @RustemReizov 9 หลายเดือนก่อน +1

      @@Javatechie Isn't it unnecessary to create a bean? @Component itself creates the bean, you can simply pass it to the method?

    • @Javatechie
      @Javatechie  9 หลายเดือนก่อน

      Got your points and Agree buddy

  • @giansiccardi6151
    @giansiccardi6151 3 หลายเดือนก่อน +1

    bro you helped me a lot, thank you very much and greetings from Argentina

  • @ManishNegi-il1kf
    @ManishNegi-il1kf 2 หลายเดือนก่อน +2

    Its a very best content which i ever seen in across youtube .. thanks basant keep it up..

  • @seriseyes
    @seriseyes ปีที่แล้ว +1

    Hi, How do i access current user from other microservices? such as restaurant-service?

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      From api gateway extract logged in user ID or name then pass it as part of headers while redirecting it to other API

  • @damumahendar
    @damumahendar 10 หลายเดือนก่อน +1

    Excellent work , but the website u use for getting the secret is not working any more . so people are suffering to get the secret and cant able to use the full potential of the work you have done here . pls give an alternative way to get secret from else where . i was suffering for a week for validating JWT and routing . this came as a life saver . Thanks much for a fablous work . i would like to do a donation . if u have any payment portal pls let me know .

    • @Javatechie
      @Javatechie  10 หลายเดือนก่อน

      Ohh is it , the last time I tried it works since these are open-source we can't predict from any website will check alternative and update in thread

    • @damumahendar
      @damumahendar 10 หลายเดือนก่อน +1

      Hi @@Javatechie , Appreciate you're reading the comments . if you make shorts for generating the secret please share the link here and the spring security video description .

  • @premraj.m
    @premraj.m 7 หลายเดือนก่อน +1

    52:00 Auth service integrate with Gateway
    56:00 Validate token

  • @smrutisouravmoharana2658
    @smrutisouravmoharana2658 11 หลายเดือนก่อน +1

    Sir u have used only user name and password with token to validate the api of other service like swiggy and other service but how to do when I add role based authentication to active the different api of different service (role based authentication using in api gateway) plz make a video

    • @Javatechie
      @Javatechie  11 หลายเดือนก่อน

      I haven't found a direct solution for role based authentication and Authorization but what i understand is that we need to create a separate service for admin and users and can define that in the api gateway.

    • @smrutisouravmoharana2658
      @smrutisouravmoharana2658 11 หลายเดือนก่อน +1

      ​​@@Javatechiesir can you make a video plz... So that i will be helpful. Multiuser login is very important concept in microservices design pattern

  • @Crazyfactzz123
    @Crazyfactzz123 7 หลายเดือนก่อน +1

    Thank you for this wonderful video❤️❤️

  • @cristianlozadapadilla4896
    @cristianlozadapadilla4896 ปีที่แล้ว +3

    THIS IS THE VIDEO I WAS LOOKING FOR, THANKS SO MUCH FROM COLOMBIA

  • @sunderkrishnaupreti561
    @sunderkrishnaupreti561 ปีที่แล้ว +3

    Nobody explains like you do..Thank you very much for the video.

  • @PrashantJannu
    @PrashantJannu 3 หลายเดือนก่อน +1

    Thanks aTon Sir ❤, No one can match your Explanation level 👍

  • @saidmzee4107
    @saidmzee4107 ปีที่แล้ว +1

    Hello Sir, is it possible each microservice to have its own user and password. A token generated to only access the specific service to which the user belongs?

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Yes you need to play with an api key specific to the microservice

    • @saidmzee4107
      @saidmzee4107 ปีที่แล้ว

      @@Javatechie thank you very much, let me check and apply

  • @sandeepjayaram83
    @sandeepjayaram83 3 หลายเดือนก่อน +1

    Very good explanation, have one doubt in jwt tutorial you mentioned to validate token you passed token and user details object , but here in api gateway you are passing just token , what if I modify token , and how api gateway is validating modified token since we are not passing user details object

    • @Javatechie
      @Javatechie  3 หลายเดือนก่อน

      In jwt from token we extract user details . We Don't pass user details explicitly

    • @sandeepjayaram83
      @sandeepjayaram83 3 หลายเดือนก่อน

      @@Javatechie was mentioning about below method , can u plz explain here we are just passing token we r not extracting username
      public void validateToken(final String token) {
      Jwts.parserBuilder().setSigningKey(getSignKey()).build().parseClaimsJws(token);
      }

    • @Javatechie
      @Javatechie  3 หลายเดือนก่อน

      Please Debug parseClaim method you Will understand from token what all we are extracting

  • @SayemHasnat-e4h
    @SayemHasnat-e4h ปีที่แล้ว +1

    it's awsome,,
    I was trying to solve this kind of problem and this tutorial helps me a lot.
    Thank You so much for the video tutorial.

  • @obinnannubia4191
    @obinnannubia4191 ปีที่แล้ว +1

    Why did you not use the api gateway port number to get the token?

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Yes I have used the api gateway port only because gateways interact to identity service

  • @Canarticho
    @Canarticho ปีที่แล้ว +1

    Hello basant, should I define the sessionCreationPolicy to SessionCreationPolicy.STATELESS inside the securityFilterChain to precise I don't want to use jsessionid ?

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      It's good to have

  • @TalhaHussain-zy9gw
    @TalhaHussain-zy9gw 3 หลายเดือนก่อน +3

    It is authenticated only when it routes through the gateway. But the end point for the micro services are still open how to secure that?

    • @vinaygoswami5374
      @vinaygoswami5374 2 หลายเดือนก่อน

      I think we need to implement spring security at service level for each service

    • @ahammedhussain9335
      @ahammedhussain9335 หลายเดือนก่อน

      Is there any solution for this issue?

    • @vinaygoswami5374
      @vinaygoswami5374 หลายเดือนก่อน +1

      @@ahammedhussain9335 I think the services need not to be public, so we cannot access them directly, we can only access them through gateway as the end user, and at gateway we filter request to check for the token and authentication for routing the request to the appropriate service.

    • @darshanrajashekhar5914
      @darshanrajashekhar5914 หลายเดือนก่อน

      No no just implement cross origin bro

    • @vinaygoswami5374
      @vinaygoswami5374 หลายเดือนก่อน

      @@darshanrajashekhar5914 please elaborate

  • @zero-dev
    @zero-dev ปีที่แล้ว +1

    How i will get current user and its roles in other microservice

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      In each service you can call UserdetailsService to get user info

  • @KroTek20
    @KroTek20 7 หลายเดือนก่อน +1

    I keep on getting 401 Unauthorized when I try to access other endpoints available from my API-Gateway. I can get the token with /auth/token, I can validate it, but for other endpoints I always get 401. I checked the code over and over again, it doesn't look like I missed something.

    • @Javatechie
      @Javatechie  7 หลายเดือนก่อน

      Please check the configuration and compare it with my code . I guess there is an issue with antMatchers or what I have definitely secured url

    • @KroTek20
      @KroTek20 7 หลายเดือนก่อน +1

      @@Javatechie problem solved

    • @Javatechie
      @Javatechie  7 หลายเดือนก่อน

      What was the issue

    • @KroTek20
      @KroTek20 7 หลายเดือนก่อน

      @@Javatechie If I try to dockerize my app with docker-compose I run into the same problem, I keep getting 401. Do I have to somehow provide a new secret to the docker image than the one used in the app?

  • @yuvrajph4754
    @yuvrajph4754 ปีที่แล้ว +1

    Awesome video Bhai.. much needed.. thanks a lot for the content shared. 🎉

  • @C410-u7t
    @C410-u7t ปีที่แล้ว +1

    Let me ask you a question. If, for example, I try to access the restaurant service directly (giving the restaurant service port), that is, without going through Gateway, I will skip the validate token part, right? So the restaurant service isn't protected at all, is it?

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Then what is the need of the API gateway buddy? If you will directly expose your microservice endpoints to users

    • @C410-u7t
      @C410-u7t ปีที่แล้ว

      ​@@Javatechie The point is, if a hacker knows the port of my services (for somehow), he can easily access them.

    • @omkarprakashbhosale8338
      @omkarprakashbhosale8338 ปีที่แล้ว

      Do you get any solution regarding this

    • @omkarprakashbhosale8338
      @omkarprakashbhosale8338 ปีที่แล้ว

      ​@@Javatechie then how disallow it...?....bcz if somebody knows our port...he can access it

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Knowing only port how someone can access buddy? We shouldn't expose our microservice endpoints even though it's exposed then we need to implement cross origin so that if the request comes from only api gateway then only allow that.

  • @fnGamingz
    @fnGamingz ปีที่แล้ว +1

    Thank you so much Basant for this tutorial, but getting one issue which integrating api gateway to angular,
    Failed)net::ERR_NAME_NOT_RESOLVED preflight Preflight
    Please tell me what to do to resolve this,
    Thanks in advance!!

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Please drop me an email to javatechie4u@gmail.com with complete error stack trace

  • @suresh1250
    @suresh1250 5 หลายเดือนก่อน +1

    Thank you very much for providing such a detailed explanation. Your video is undoubtedly superior to paid courses that tend to overcomplicate things and stretch on for more than 8 hours.
    I have a question: If I were to call Swiggy or a restaurant service directly, bypassing the gateway or discovery service, how would I handle authentication?

    • @vivekbansal-bc9eg
      @vivekbansal-bc9eg หลายเดือนก่อน +1

      you can't but you can make that api endpoint in api gateway itself

  • @Full-Stack-Project
    @Full-Stack-Project ปีที่แล้ว +1

    Nice video we learn couple of thing related to microservices and spring security ❤❤❤

  • @ahheask9527
    @ahheask9527 5 หลายเดือนก่อน +1

    How to implement with role and permission on security?

  • @ritabratabanerjee8899
    @ritabratabanerjee8899 5 หลายเดือนก่อน

    Firstly Thank you for all your tutorials. I tried this api gateway implementation and getting "An expected CSRF token cannot be found" when calling authenticate or register apis through gateway. It works if I directly call authentication service. Could you please help with this.

  • @rohitmanohar2733
    @rohitmanohar2733 ปีที่แล้ว +1

    Hi Sir,
    I have implemented filter as per ur logic but I need to call identity-service in order to validate the token, but when I call the identity service using resttemplate I get the following error :
    java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3
    So can u please help how can we resolve this.

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Yes simple please use web client instead of rest template

    • @rohitmanohar2733
      @rohitmanohar2733 ปีที่แล้ว +1

      Sir since we are in already in reactive phase, and we need to somehow need to block the code to validate the token, so once I used webclient with blocking , I get the same exception, and I can't use reactive response here

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      It shouldn't give an error let me check and update you

    • @rohitmanohar2733
      @rohitmanohar2733 ปีที่แล้ว +1

      Thank you so much sir for ur quick response, I will be waiting for ur answer

  • @arnold123user
    @arnold123user ปีที่แล้ว +1

    since springboot 3.0 you dont have to do @EnableDiscoveryClient annotation. It is enough that dependency is defined in pom.xml

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      I haven't tried , will check and update you

  • @truthpath184
    @truthpath184 11 หลายเดือนก่อน +1

    Hi Basant sir, Jwt in microservices explanation is so good. Thank you so much...

  • @anushabondalapati1267
    @anushabondalapati1267 10 หลายเดือนก่อน +1

    Is it possible to show flow diagram , how it goes?

    • @Javatechie
      @Javatechie  10 หลายเดือนก่อน

      Beginning I already explained flow of this security mechanism

  • @berkaybb5733
    @berkaybb5733 2 หลายเดือนก่อน

    Nice explanation! Only thing I'm concerning is that why did you filter and authenticate user in gateway directly rather than routing to IDENTITY service and authenticate?

  • @ShantanuSharma26
    @ShantanuSharma26 หลายเดือนก่อน

    Great Video! Need some more info : How do we avoid scattering secret? it can be stolen from code repo. How will the services be talking to each other? How will they get the token? Also how to enable HTTPS with proper handling of secrets.

  • @AnilKumar-cc8px
    @AnilKumar-cc8px ปีที่แล้ว +3

    Grateful for such a wonderful insight on Microservices security. It will definitely help me to improve skills in my projects. Thankyou so much for the efforts. I'm learning a lot from your channel. Awaiting for more interesting videos.

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Thanks buddy keep learning 😃

  • @basith103
    @basith103 5 หลายเดือนก่อน

    after implementing spring security to microservices it will only validate token when URL passed through the API Gateway, what if we try to hit the URL of the particular service, how to stop that?

  • @p1262
    @p1262 8 หลายเดือนก่อน

    Loved the explanations!! But, how can i do a role based authentication, like admin and user for example? I've faced with this question and got stucked. I wonder if you can help me.

  • @Aniruddhdwivedi
    @Aniruddhdwivedi ปีที่แล้ว +1

    Hi Basant, similar to this video can you make one video to secure microservices for authentication, authorization, and re-authorization of OAuth tokens using the OAuth2.0 protocol and IDAnywhere/Okta as authentication servers?

    • @Javatechie
      @Javatechie  ปีที่แล้ว +2

      Okay i will do this

  • @aziztolearn
    @aziztolearn 4 หลายเดือนก่อน

    Why calling validate endpoint from auth-service(identity-service) was bad idea? I don't understand.

  • @psudhakarreddy6548
    @psudhakarreddy6548 ปีที่แล้ว +2

    Thank you bro 🎉

  • @AP-pr1mw
    @AP-pr1mw หลายเดือนก่อน

    What if I hit the swiggy service end-points instead of API gateway end-points ? it should be accessible right how we can call swiggy service is secure ?

  • @saikrishna4661
    @saikrishna4661 4 หลายเดือนก่อน

    Hello Can I directly come to this video withOut watching your previous videos of springSecurity?

  • @huetzinc
    @huetzinc 5 หลายเดือนก่อน

    13:44 Comienza a crear el proyecto identity-service (lo hace desde el Spring initializer de su IDE IntelliJ)

  • @sandhyathanna9461
    @sandhyathanna9461 4 หลายเดือนก่อน

    I have a use case. Can someone suggest a solution pls? I am trying to invoke a third party api, with the token embedded in the request headers. This api returns me a huge json response. While this api is returning some response, what if the token expires midway? How can we fetch a new token and resume from where it failed?

  • @TestJob-lc6by
    @TestJob-lc6by 6 หลายเดือนก่อน

    When I'm trying to access with gateway url postman is throwing 404 error , when I'm trying with the service url it's working fine kindly help with this issue

  • @krishnan6201
    @krishnan6201 ปีที่แล้ว +1

    how spring cloud check that request came from web or mobile app and executes corresponding version of RequestMapping method. can you please clarify my query?

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      There is no such mechanism whether it's mobile or web app endpoint will always be the same buddy .

    • @krishnan6201
      @krishnan6201 ปีที่แล้ว

      @@Javatechie i am facing interview questions about it. i can't able to answer that. what could expert answer from you. plz help me on this.

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      For desktop or mobile view frontend team needs to design responsive pages. Nothing to do from the backend

    • @krishnan6201
      @krishnan6201 ปีที่แล้ว +1

      thanks @@Javatechie

  • @Virat77799
    @Virat77799 6 หลายเดือนก่อน

    Hi all.
    Here I dint understand how role based Authorization will work. I see Authorization is happening at idm service and authorisation happens in filter of api gateway but how wil spring know to do role based Authorization.

  • @filz4461
    @filz4461 ปีที่แล้ว +4

    You have one of the best educational channels out there. I would love to give you a constructive opinion: It would be great if you could change your microphone into something clearer, like what the java brain and Navin have. Trust me, it makes a huge difference.

    • @Javatechie
      @Javatechie  ปีที่แล้ว +2

      Thanks Filz , i noted it and going forward i will come with better audio quality. Need to look into rode configuration

    • @archanasingh3060
      @archanasingh3060 ปีที่แล้ว +1

      ​@@Javatechie 🎉d o 😢😢😢😮😊😂😅😅😅😅😮😮😮😮😮😅😮fq😢😢😢😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮😮

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Archana not getting you

    • @filz4461
      @filz4461 ปีที่แล้ว

      @@Javatechie I think, that's a bot.

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Even not getting you buddy. What do you mean by bot