OAuthCertBoundJwtAccessTokenAuthority implements Authority, AuthorityKeyStore, KeyStore { private void processAuthorizedClientIds(String authorizedClientIdsPath, Map<String, Set<String>> authorizedClientIds, Map<String, String> authorizedServices) { if (authorizedClientIdsPath == null || authorizedClientIdsPath.isEmpty()) { return; } try (BufferedReader br = new BufferedReader(new FileReader(authorizedClientIdsPath))) { for (String line = br.readLine(); line != null; line = br.readLine()) { if (line.isEmpty()) { continue; } final String mapEntry = line.trim(); boolean isInvalid = false; String[] comps = mapEntry.split(OAuthAuthorityConsts.CLIENT_ID_FIELD_DELIMITER); if (comps.length != 3) { LOG.error("Skipping invalid client id entry {}", mapEntry); isInvalid = true; } for (String comp: comps) { if (comp.isEmpty()) { LOG.error("Skipping invalid client id entry {}", mapEntry); isInvalid = true; break; } } if (isInvalid) { continue; } Set<String> clientIds = OAuthAuthorityUtils.csvToSet(comps[0], OAuthAuthorityConsts.CLIENT_ID_DELIMITER); if (clientIds == null || clientIds.contains("")) { LOG.error("Skipping invalid client id entry {}", mapEntry); continue; } authorizedClientIds.put(comps[1], clientIds); authorizedServices.put(comps[1], comps[2]); } } catch (Exception e) { LOG.error("Unable to process client id list: {}", e.getMessage()); } }  @Override void setKeyStore(KeyStore keyStore); @Override String getPublicKey(String domain, String service, String keyId); @Override CredSource getCredSource(); @Override String getAuthenticateChallenge(); @Override String getDomain(); @Override String getHeader(); @Override Principal authenticate(String credentials, String remoteAddr, String httpMethod, StringBuilder errMsg); @Override void initialize(); @Override Principal authenticate(HttpServletRequest request, StringBuilder errMsg);  }
@Test public void testProcessAuthorizedClientIds() throws Exception { OAuthCertBoundJwtAccessTokenAuthority authority = new OAuthCertBoundJwtAccessTokenAuthority(); Method processAuthorizedClientIds = authority.getClass().getDeclaredMethod("processAuthorizedClientIds", String.class, Map.class, Map.class); processAuthorizedClientIds.setAccessible(true); Map<String, Set<String>> authorizedClientIds = new HashMap<>(); Map<String, String> authorizedServices = new HashMap<>(); authorizedClientIds.clear(); authorizedServices.clear(); processAuthorizedClientIds.invoke(authority, null, authorizedClientIds, authorizedServices); assertEquals(authorizedClientIds.size(), 0); assertEquals(authorizedServices.size(), 0); authorizedClientIds.clear(); authorizedServices.clear(); processAuthorizedClientIds.invoke(authority, "", authorizedClientIds, authorizedServices); assertEquals(authorizedClientIds.size(), 0); assertEquals(authorizedServices.size(), 0); String non_existing_filepath = this.classLoader.getResource("authorized_client_ids.empty.txt").toURI().resolve("./authorized_client_ids.non_existing.txt").getPath(); authorizedClientIds.clear(); authorizedServices.clear(); processAuthorizedClientIds.invoke(authority, non_existing_filepath, authorizedClientIds, authorizedServices); assertEquals(authorizedClientIds.size(), 0); assertEquals(authorizedServices.size(), 0); authorizedClientIds.clear(); authorizedServices.clear(); processAuthorizedClientIds.invoke(authority, this.classLoader.getResource("authorized_client_ids.empty.txt").getPath(), authorizedClientIds, authorizedServices); assertEquals(authorizedClientIds.size(), 0); assertEquals(authorizedServices.size(), 0); authorizedClientIds.clear(); authorizedServices.clear(); Map<String, Set<String>> expectedAuthorizedClientIds = new HashMap<>(); Map<String, String> expectedAuthorizedServices = new HashMap<>(); expectedAuthorizedClientIds.put("ui_principal_11", new HashSet<>(Arrays.asList(new String[]{"client_id_11","client_id_12"}))); expectedAuthorizedServices.put("ui_principal_11", "authorized_service_11"); expectedAuthorizedClientIds.put("ui_principal_21", new HashSet<>(Arrays.asList(new String[]{"client_id_21"}))); expectedAuthorizedServices.put("ui_principal_21", "authorized_service_21"); expectedAuthorizedClientIds.put("ui_principal_31", new HashSet<>(Arrays.asList(new String[]{"client_id_31"}))); expectedAuthorizedServices.put("ui_principal_31", "authorized_service_31"); expectedAuthorizedClientIds.put("ui_principal_41", new HashSet<>(Arrays.asList(new String[]{"client_id_41","trailing_comma"}))); expectedAuthorizedServices.put("ui_principal_41", "authorized_service_41"); processAuthorizedClientIds.invoke(authority, this.classLoader.getResource("authorized_client_ids.txt").getPath(), authorizedClientIds, authorizedServices); assertEquals(authorizedClientIds, expectedAuthorizedClientIds); assertEquals(authorizedServices, expectedAuthorizedServices); }