Skip to content

Commit 0ffc970

Browse files
committed
Merge branch 'release/10.9.5' into release/v10.9.5
# Conflicts: # backend/src/main/java/com/park/utmstack/config/Constants.java
2 parents 5219ae8 + bb3d4ea commit 0ffc970

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

backend/src/main/java/com/park/utmstack/config/Constants.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import com.park.utmstack.domain.index_pattern.enums.SystemIndexPattern;
44

5-
import java.util.Collections;
65
import java.util.HashMap;
7-
import java.util.List;
86
import java.util.Map;
97

108
public final class Constants {
@@ -130,7 +128,6 @@ public final class Constants {
130128
// Defines the index pattern for querying Elasticsearch statistics indexes.
131129
// ----------------------------------------------------------------------------------
132130
public static final String STATISTICS_INDEX_PATTERN = "v11-statistics-*";
133-
public static final String API_ACCESS_LOGS = ".utmstack-api-logs";
134131

135132
// Logging
136133
public static final String TRACE_ID_KEY = "traceId";
@@ -142,10 +139,7 @@ public final class Constants {
142139
public static final String DURATION_KEY = "duration";
143140
public static final String CAUSE_KEY = "cause";
144141
public static final String LAYER_KEY = "layer";
145-
146-
public static final String API_KEY_HEADER = "Utm-Api-Key";
147-
public static final List<String> API_ENDPOINT_IGNORE = Collections.emptyList();
148-
142+
public static final String TFA_EXEMPTION_HEADER = "X-Bypass-TFA";
149143

150144
private Constants() {
151145
}

backend/src/main/java/com/park/utmstack/security/jwt/TokenProvider.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.park.utmstack.security.jwt;
22

33

4+
import com.park.utmstack.config.Constants;
45
import com.park.utmstack.security.AuthoritiesConstants;
56
import com.park.utmstack.util.CipherUtil;
67
import io.jsonwebtoken.*;
@@ -16,10 +17,12 @@
1617
import org.springframework.stereotype.Component;
1718
import tech.jhipster.config.JHipsterProperties;
1819

20+
import javax.servlet.http.HttpServletRequest;
1921
import java.security.Key;
2022
import java.util.Arrays;
2123
import java.util.Collection;
2224
import java.util.Date;
25+
import java.util.Optional;
2326
import java.util.stream.Collectors;
2427

2528
@Component
@@ -116,4 +119,16 @@ public boolean validateToken(String authToken) {
116119
}
117120
return false;
118121
}
122+
123+
public boolean canBypassTwoFactorAuth(HttpServletRequest request) {
124+
boolean tfaExemptionRequested = Boolean.parseBoolean(request.getHeader(Constants.TFA_EXEMPTION_HEADER));
125+
126+
boolean forceTfaAuth = Boolean.parseBoolean(
127+
Optional.ofNullable(System.getenv(Constants.PROP_TFA_ENABLE)).orElse("true")
128+
);
129+
130+
return tfaExemptionRequested || !forceTfaAuth;
131+
}
132+
133+
119134
}

backend/src/main/java/com/park/utmstack/web/rest/UserJWTController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public ResponseEntity<JWTToken> authorize(@Valid @RequestBody LoginVM loginVM, H
7777
throw new TooMuchLoginAttemptsException(String.format("Authentication blocked: IP %s exceeded login attempt threshold", ip));
7878
}
7979

80-
boolean authenticated = !Boolean.parseBoolean(Constants.CFG.get(Constants.PROP_TFA_ENABLE));
80+
boolean isTfaExempted = this.tokenProvider.canBypassTwoFactorAuth(request);
81+
boolean authenticated = !Boolean.parseBoolean(Constants.CFG.get(Constants.PROP_TFA_ENABLE)) || isTfaExempted;
8182

8283
UsernamePasswordAuthenticationToken authenticationToken =
8384
new UsernamePasswordAuthenticationToken(loginVM.getUsername(), loginVM.getPassword());

0 commit comments

Comments
 (0)