@@ -190,16 +190,28 @@ private SecureSessionAgentConfig getSecureSessionAgentConfigFromMDS() {
190190
191191 String plaintextS2AAddress = "" ;
192192 String mtlsS2AAddress = "" ;
193+ Object s2aAddressConfig = 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+ }
193200 try {
194201 plaintextS2AAddress =
195- validateString (responseData , S2A_PLAINTEXT_ADDRESS_JSON_KEY , PARSE_ERROR_S2A );
202+ OAuth2Utils .validateString (
203+ (Map <String , Object >) s2aAddressConfig ,
204+ S2A_PLAINTEXT_ADDRESS_JSON_KEY ,
205+ PARSE_ERROR_S2A );
196206 } catch (IOException ignore ) {
197207 /*
198208 * Do not throw error because of parsing error, just leave the address as empty in {@link SecureSessionAgentConfig}.
199209 */
200210 }
201211 try {
202- mtlsS2AAddress = validateString (responseData , S2A_MTLS_ADDRESS_JSON_KEY , PARSE_ERROR_S2A );
212+ mtlsS2AAddress =
213+ OAuth2Utils .validateString (
214+ (Map <String , Object >) s2aAddressConfig , S2A_MTLS_ADDRESS_JSON_KEY , PARSE_ERROR_S2A );
203215 } catch (IOException ignore ) {
204216 /*
205217 * Do not throw error because of parsing error, just leave the address as empty in {@link SecureSessionAgentConfig}.
@@ -211,23 +223,4 @@ private SecureSessionAgentConfig getSecureSessionAgentConfigFromMDS() {
211223 .setMtlsAddress (mtlsS2AAddress )
212224 .build ();
213225 }
214-
215- private static String validateString (Map <String , Object > map , String key , String errorPrefix )
216- throws IOException {
217- Object value = map .get (S2A_JSON_KEY );
218- if (value == null ) {
219- throw new IOException (
220- String .format (OAuth2Utils .VALUE_NOT_FOUND_MESSAGE , errorPrefix , S2A_JSON_KEY ));
221- }
222- if (!(value instanceof Map )) {
223- throw new IOException (
224- String .format (OAuth2Utils .VALUE_WRONG_TYPE_MESSAGE , errorPrefix , "Map" , S2A_JSON_KEY ));
225- }
226- Object address = ((Map <String , Object >) value ).get (key );
227- if (!(address instanceof String )) {
228- throw new IOException (
229- String .format (OAuth2Utils .VALUE_WRONG_TYPE_MESSAGE , errorPrefix , "string" , key ));
230- }
231- return (String ) address ;
232- }
233226}
0 commit comments