|
45 | 45 | import java.io.InputStream;
|
46 | 46 | import java.util.Arrays;
|
47 | 47 | import java.util.HashSet;
|
| 48 | +import java.util.Map; |
48 | 49 | import java.util.ServiceLoader;
|
49 | 50 | import java.util.Set;
|
50 | 51 | import javax.annotation.concurrent.ThreadSafe;
|
|
59 | 60 | */
|
60 | 61 | @ThreadSafe
|
61 | 62 | public class SecureSessionAgent {
|
| 63 | + static final String S2A_JSON_KEY = "s2a"; |
62 | 64 | static final String S2A_PLAINTEXT_ADDRESS_JSON_KEY = "plaintext_address";
|
63 | 65 | static final String S2A_MTLS_ADDRESS_JSON_KEY = "mtls_address";
|
64 | 66 | static final String S2A_CONFIG_ENDPOINT_POSTFIX =
|
@@ -188,17 +190,25 @@ private SecureSessionAgentConfig getSecureSessionAgentConfigFromMDS() {
|
188 | 190 |
|
189 | 191 | String plaintextS2AAddress = "";
|
190 | 192 | String mtlsS2AAddress = "";
|
| 193 | + Map<String, Object> s2aAddressConfig = (Map<String, Object>) responseData.get(S2A_JSON_KEY); |
| 194 | + if (s2aAddressConfig == null) { |
| 195 | + /* |
| 196 | + * Return empty addresses in {@link SecureSessionAgentConfig} if endpoint doesn't return anything. |
| 197 | + */ |
| 198 | + return SecureSessionAgentConfig.createBuilder().build(); |
| 199 | + } |
191 | 200 | try {
|
192 | 201 | plaintextS2AAddress =
|
193 |
| - OAuth2Utils.validateString(responseData, S2A_PLAINTEXT_ADDRESS_JSON_KEY, PARSE_ERROR_S2A); |
| 202 | + OAuth2Utils.validateString( |
| 203 | + s2aAddressConfig, S2A_PLAINTEXT_ADDRESS_JSON_KEY, PARSE_ERROR_S2A); |
194 | 204 | } catch (IOException ignore) {
|
195 | 205 | /*
|
196 | 206 | * Do not throw error because of parsing error, just leave the address as empty in {@link SecureSessionAgentConfig}.
|
197 | 207 | */
|
198 | 208 | }
|
199 | 209 | try {
|
200 | 210 | mtlsS2AAddress =
|
201 |
| - OAuth2Utils.validateString(responseData, S2A_MTLS_ADDRESS_JSON_KEY, PARSE_ERROR_S2A); |
| 211 | + OAuth2Utils.validateString(s2aAddressConfig, S2A_MTLS_ADDRESS_JSON_KEY, PARSE_ERROR_S2A); |
202 | 212 | } catch (IOException ignore) {
|
203 | 213 | /*
|
204 | 214 | * Do not throw error because of parsing error, just leave the address as empty in {@link SecureSessionAgentConfig}.
|
|
0 commit comments