Skip to content

Commit d596efc

Browse files
committed
Expose actuator to anonymous for health and readiness checks
1 parent ea4e7b1 commit d596efc

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/main/java/com/faforever/api/config/FafApiProperties.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff 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;

src/main/java/com/faforever/api/config/security/MethodSecurityConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package com.faforever.api.config.security;
22

33
import com.faforever.api.security.method.CustomMethodSecurityExpressionHandler;
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
45
import org.springframework.context.annotation.Bean;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
78
import 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)
1117
public class MethodSecurityConfig {
1218
@Bean

src/main/java/com/faforever/api/config/security/WebSecurityConfig.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.faforever.api.config.security;
22

3+
import com.faforever.api.config.FafApiProperties;
34
import com.faforever.api.security.FafAuthenticationConverter;
5+
import lombok.RequiredArgsConstructor;
46
import org.springframework.context.annotation.Bean;
57
import org.springframework.context.annotation.Configuration;
68
import org.springframework.http.HttpMethod;
@@ -20,10 +22,13 @@
2022

2123
@Configuration
2224
@EnableWebSecurity
25+
@RequiredArgsConstructor
2326
public 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

src/main/java/com/faforever/api/security/ElideUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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() {

src/main/resources/config/application-local.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
faf-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/
9192
logging:
9293
level:
9394
com.faforever.api: debug

0 commit comments

Comments
 (0)