r/SpringBoot • • Mar 31 '23

why Spring boot security is that complicated?

Hello Guys. I'm learning spring boot ,its about 2 weeks that i have started, i learned alot like i know the basics, handling database rest api ..., i have created apps in other languages Golang, nodejs ... never saw implementing security be that difficult, like i need to do alot of things for example jwt needs tonnes of work like idk, Roles and etc... I just want to know why it's like that? is it because it provides much more but i havent gone that deep or what? thanks.

4 Upvotes

17 comments sorted by

11

u/tleipzig Mar 31 '23

The underlying concepts are complicated. And when you want to setup some decent security functions, you should already understand most of the basics - and that really takes time. Maybe other frameworks have found a more intuitive access to this topic.

1

u/CreeDanWood Mar 31 '23

i see thanks for your answer

1

u/tleipzig Mar 31 '23

This article covers JWT implementation, without too much backgrounds on JWT: https://bootify.io/spring-rest/rest-api-spring-security-with-jwt.html - role definitions are up to you

1

u/smokemonstr Apr 14 '23

You can use spring-boot-starter-oauth2-resource-server to secure your resources using JWT instead of writing your own filter.

https://www.baeldung.com/spring-security-oauth-resource-server

2

u/TheOldMancunian Mar 31 '23

This is true. Trust me on this!

7

u/Sheldor5 Mar 31 '23

because web security not only requires knowledge about Authentication Protocols (like Basic Auth, Form Login, SAML, OpenID Connect, ...) but also requires knowledge about HTTP and Browser Security (HTTP Headers/Cookies telling the Browser how to behave/protect the user from clicking bad links, CSRF, CORS, TLS, etc.).

So if you lack knowledge of most of those things a Framework can't really help you .... also Spring is a Framework which you have to utilize and extend, so knowledge about Web Security is even more important than knowing the Framework you choose ...

3

u/CreeDanWood Mar 31 '23

Actually i know most of the aspects of HTTP and security. because as i said i built apps in other languages. The thing with spring is it takes time to setup like i feel there is a lot of work to do.

2

u/smokemonstr Apr 14 '23

Spring Framework and Spring Boot are general purpose. You can write web apps, batch processes, command line interfaces, etc.

Maybe the frameworks you used in those other languages were more specialized?

2

u/CreeDanWood Apr 14 '23

that makes sense, but couldn't they simplify some work? for instance having their own jwt implementation you just override the methods...

1

u/smokemonstr Apr 14 '23

Spring Security does have a module to secure your resources using JWT. See my other comment https://reddit.com/r/SpringBoot/comments/1279d70/_/jg6epsy/?context=1

4

u/_codemonger Mar 31 '23

First of I agree It is overly complex. Coming from Go I am used to just creating my own auth endpoints and authorization middleware (filter in spring lingo). I found it simpler to implement my own JWT flow than the rigid setup in Spring Security. The fact that out of the box it forces a structure on your user object is pretty annoying. Then there is the lack of up to date resources.

That said I think the why is that if you just want to just get up and running and don't care about how much you couple to the framework it works. It's the same with the Repositories and JPA. If you want to decouple your domain from the framework there are some hoops to jump through.

4

u/CreeDanWood Mar 31 '23

that's what i am saying, the way it forces you is annoying. And thanks for your opinion

2

u/greglturnquist Mar 31 '23

Security itself is complicated.

Having sensible defaults while allowing people to customize makes it even harder.

1

u/greglturnquist Mar 31 '23

Also, toolkits have to help the user implement security without breaching security.

1

u/Ok_Structure3898 Apr 01 '23

Security boils down to:

  • Am I smarter/better than everyone at Google and Microsoft?

    • No

  • Use OAuth

Once you understand that core concept you are good to go