File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public class FafApiProperties {
1616 * The API version.
1717 */
1818 private String version ;
19+ private boolean allowAnonymous ;
1920 private Jwt jwt = new Jwt ();
2021 private OAuth2 oAuth2 = new OAuth2 ();
2122 private Async async = new Async ();
@@ -258,11 +259,6 @@ public static class Smtp {
258259 private String password ;
259260 }
260261
261- @ Data
262- public static class Anope {
263- private String databaseName ;
264- }
265-
266262 @ Data
267263 public static class Rating {
268264 private int defaultMean ;
Original file line number Diff line number Diff line change 11package com .faforever .api .config .security ;
22
33import com .faforever .api .security .method .CustomMethodSecurityExpressionHandler ;
4+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
45import org .springframework .context .annotation .Bean ;
56import org .springframework .context .annotation .Configuration ;
67import org .springframework .security .access .expression .method .MethodSecurityExpressionHandler ;
78import org .springframework .security .config .annotation .method .configuration .EnableMethodSecurity ;
89
910@ Configuration
11+ @ ConditionalOnProperty (
12+ value = "faf-api.allow-anonymous" ,
13+ havingValue = "false" ,
14+ matchIfMissing = true
15+ )
1016@ EnableMethodSecurity (securedEnabled = true )
1117public class MethodSecurityConfig {
1218 @ Bean
Original file line number Diff line number Diff line change 11package com .faforever .api .config .security ;
22
3+ import com .faforever .api .config .FafApiProperties ;
34import com .faforever .api .security .FafAuthenticationConverter ;
5+ import lombok .RequiredArgsConstructor ;
46import org .springframework .context .annotation .Bean ;
57import org .springframework .context .annotation .Configuration ;
68import org .springframework .http .HttpMethod ;
2022
2123@ Configuration
2224@ EnableWebSecurity
25+ @ RequiredArgsConstructor
2326public class WebSecurityConfig {
2427
28+ private final FafApiProperties fafApiProperties ;
29+
2530 @ Bean
26- public SecurityFilterChain securityFilterChain (HttpSecurity http ) throws Exception {
31+ public SecurityFilterChain securityFilterChain (HttpSecurity http ) {
2732 final var bearerTokenResolver = new DefaultBearerTokenResolver ();
2833 bearerTokenResolver .setAllowUriQueryParameter (true );
2934
@@ -42,7 +47,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
4247 "/swagger-ui/**" ,
4348 "/swagger-resources/**" ,
4449 "/v3/api-docs/**" ,
45- "/"
50+ "/" ,
51+ "/actuator/**"
4652 ).permitAll ();
4753 // Webapp folder
4854 authorizeConfig .requestMatchers (
@@ -61,6 +67,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
6167 "/users/requestPasswordResetViaSteam" ,
6268 "/users/linkToSteam/**"
6369 ).permitAll ();
70+
71+ if (fafApiProperties .isAllowAnonymous ()) {
72+ authorizeConfig .requestMatchers ("/data/**" ).permitAll ();
73+ }
6474 authorizeConfig .anyRequest ().authenticated ();
6575 });
6676 // @formatter:on
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ public String getName() {
2424
2525 @ Override
2626 public boolean isInRole (String role ) {
27- return fafAuthentication .hasRole (role );
27+ return fafAuthentication != null && fafAuthentication .hasRole (role );
2828 }
2929
3030 public Optional <Integer > getFafUserId () {
Original file line number Diff line number Diff line change 11faf-api :
2+ allow-anonymous : true
23 jwt :
34 secretKeyPath : ${JWT_PRIVATE_KEY_PATH:test-pki-private.key}
45 publicKeyPath : ${JWT_PUBLIC_KEY_PATH:test-pki-public.key}
@@ -86,8 +87,8 @@ spring:
8687 oauth2 :
8788 resourceserver :
8889 jwt :
89- jwk-set-uri : https ://hydra.faforever.com /.well-known/jwks.json
90- issuer-uri : https ://hydra.faforever.com /
90+ jwk-set-uri : http ://hydra.faforever.localhost /.well-known/jwks.json
91+ issuer-uri : http ://ory- hydra:4444 /
9192logging :
9293 level :
9394 com.faforever.api : debug
You can’t perform that action at this time.
0 commit comments