-
Hi all, there is something I don't understand reading either bff tutorial, now moved here and the explanation contained in spring-addons-starter-oidc readme. The readme states the a Security(Web)FilterChain is created If spring-boot-starter-oauth2-resource-server is on the classpath and unless com.c4-soft.springaddons.oidc.resourceserver.enabled=false and that's ok. The tutorial bff project, which is obviously an oauth2 client depends only from spring-boot-starter-oauth2-client, it does not depends from spring-boot-starter-oauth2-resource-server, nevertheless in its application.yml there is this:
which seems saying that a second SecurityFilterChain is created too. As I'm trying to implement a bff solution based where I have 4 spa applications which communicate with single bff which in turns send requests to different resource servers, but my bff hosts some REST api too, for example the login-options described in the pattern but other endpoints too which need to be secured with session token, I would like to understand if I need to depends from spring-boot-starter-oauth2-resource-server or not. Thanks for the clarification, bye |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi, I think you spotted an issue in the Baeldung repo. Yes, the BFF should depend on And also, yes,
The "client" filter-chain having higher precedence, be careful not to hide your REST endpoints behind it with too wide client Another caveat for your implementation: be aware that only an OAuth2 client can query a protected resource server endpoint (only OAuth2 clients can attach a Bearer token to the request). So, if you want your frontends to query the REST endpoints you host on the BFF itself, you might have to define a distinct route with the
So requests to Hope I was clear enough :/ This is just the regular BFF stuff but can be a bit confusing in this case... P.S.Your system will scale better if you put the less possible features in the BFF which is the only backend service needing sessions (actually, not really the only one as the authorization server uses sessions too, but this is another story). Resource servers can be stateless, which make it super easy to scale, but the later and the less you have to scale the BFF, the better (when scaling the BFF, you'll have to use Spring Session or a smart proxy routing all requests from a given device to the same instance). So long story short, if I were typing on your keyboard, I'd move these REST enpoints in standalone resource server service(s) ;) |
Beta Was this translation helpful? Give feedback.
-
I would rather phrase: " So if what you mean by "bff endpoint" are the REST endpoints you expect to be authorized with access tokens, your assomption is true. But a BFF definitely has other endpoints at least for out2Login, logout and routed requests which are all authorized with sessions in the "client" filter-chain. For sure,
Yes, because this routes need the
It "must" at minimum for the route to the downstream endpoints for which you want to "permit-all". For other downstream endpoints, it does not "have to" but it "can". In the tutorial (and all my apps), resources access control is handled solely by resource servers. The frontends maintain user login state (to adapt UI depending on the user being identified or not) and would use route guards (or would handle the If it was only to me, unauthorized requests would always be answered Also, when opting for a systematic
Yes, you have. Thank you. The cause is that A fix could be to mark the dependency on Would you open a PR for that (and get your name associated to the improvement) or should I push a quick fix? |
Beta Was this translation helpful? Give feedback.
I would rather phrase: "
client.security-matcher
should match only the endpoints needing session and not REST endpoints withBearer
authorization".So if what you mean by "bff endpoint" are the REST endpoints you expect to be authorized with access tokens, your assomption is true. But a BFF definitely has other endpoints at least for out2Login, logout and routed requests which are all authorized with sessions in the "client" filter-chain. For sure,
client.security-matcher
must match this other endpoints...