r/SpringBoot • u/Substantial-Habit-94 • Mar 02 '23
How to learn Spring Security.
I have to learn Spring Security for my job. I have implemented Rest Apis using spring boot till now. i know Java and Spring Boot. But Spring Security is too confusing for me to understand. I feel like i am missing something. Are there any prerequisites of learning spring boot. Any resources or any recommendations from experienced devs? Guide me please.
3
u/rieckpil Mar 08 '23
This two and a half hours talk/workshop gave me a lot of great insights and practical advice on Spring Security https://www.youtube.com/watch?v=iJ2muJniikY
3
28
Mar 02 '23
It's no surprise that so many people find Spring Security confusing, to be honest. It encapsulates a number of different disciplines under the one banner of "security".
protecting your API resources with OAuth2 or SAML
Providing form login for your web app
providing oauth2 login from third party providers
providing OIDC or SAML federation for your application
protecting your webapp against CSRF and similar exploits
providing authorisation services to others
These really aren't all the same thing, but they all fall under the same project. No wonder people get confused.
The way to approach it is not to just google "Spring security tutorial" but to decide first what it is that you want to do, exactly, and research that. The official docs are actually quite useful once you do that, but trying to digest the entire project is pointless and wasteful.
I think what you're missing is the insight that Spring Security addresses a bunch of disparate concerns which are at best loosely related, all using similar mechanisms: a chain of filters. Once that clicks, and once you realise that all the security DSL config et al are doing is building up a chain of filters which will act upon your requests, it starts making more sense. Once it clicks that you can have more than one of these filter chains, it makes even more sense.
5
u/Sheldor5 Mar 02 '23
no wonder if uneducated people ask questions about topics which they don't even know their basics ...
you lear most of those things/principles in university (at least in my country) but most people who ask on SO or Reddit simply have never studied ... they go from "Java Hello World" straight to "Spring Security" which is the main issue here
9
Mar 02 '23
Yep no argument. It's very common to see people with sod all experience asking how to build something vastly complex that usually takes a large team of experienced engineers to build.
But it could also be that a junior dev has been told "Oh, add Spring Security to this app" by someone senior who should know better than to drop someone in the deep end like that. Happens all the time.
0
u/Sheldor5 Mar 02 '23
most of the time I read those questions like "please do my job for free" while it's clear that they never googled JUST ONCE ... this is the main reason why SO is so hated by juniors, SO is "professionals for professionals" and was never intended to be a Q&A for juniors
4
Mar 02 '23
I always thought it was a stupid name for the website anyway. Good luck finding any info about actual stack overflows any more.
21
6
u/Pedantic_Phoenix Mar 02 '23
To be guided you need to ask specific questions. Watch videos, everyone will recommend you the ones from Amigoscode.
3
u/Ruin-Capable Mar 02 '23
The documentation talking about the overall architecture of Spring Security was very helpful for me.
3
Mar 03 '23
I have found it very helpful to use Chat GPT when I want to learn more about a certain part of Spring Security. It is pretty good at explaining certain concepts and provide me with example code to demonstrate. Of course this is to be done with caution, but it has helped me to understand Spring Security bit for bit
8
4
u/wanjalize Mar 03 '23
Spring or spring security is built on servlets and jsps. So maybe look at servlets and jsp before diving into spring security. The two technologies mentioned talk deeply about filters. Again, if you are going to learn about something don't jump directly into something that has been implemented. What I mean is look for a tutorial whereby the tutor explains aspects of spring security from the ground up (only indians do this). Once you have the basics you can easily move into anything advanced like oauth2, keycloak etc. What I am proposing could take maybe a week to fulfil but since you work I doubt you have that much time so maybe look for short articles that explain about the topic.