|
4 | 4 | import java.io.InputStream; |
5 | 5 | import java.io.InputStreamReader; |
6 | 6 | import java.io.Reader; |
| 7 | +import java.util.Iterator; |
7 | 8 | import java.util.Objects; |
8 | 9 | import java.util.Properties; |
9 | 10 |
|
10 | 11 | import com.here.account.util.Clock; |
11 | 12 | import com.here.account.util.SettableSystemClock; |
12 | | -import org.ini4j.Ini; |
| 13 | +import org.apache.commons.configuration2.INIConfiguration; |
| 14 | +import org.apache.commons.configuration2.ex.ConfigurationException; |
| 15 | +import org.apache.commons.configuration2.HierarchicalConfiguration; |
| 16 | +import org.apache.commons.configuration2.tree.ImmutableNode; |
13 | 17 |
|
14 | 18 | import com.here.account.auth.OAuth1ClientCredentialsProvider; |
15 | 19 | import com.here.account.http.HttpConstants.HttpMethods; |
@@ -64,30 +68,38 @@ protected static ClientAuthorizationRequestProvider getClientCredentialsProvider |
64 | 68 | try { |
65 | 69 | Properties properties = getPropertiesFromIni(inputStream, sectionName); |
66 | 70 | return FromSystemProperties.getClientCredentialsProviderWithDefaultTokenEndpointUrl(clock, properties); |
67 | | - } catch (IOException e) { |
| 71 | + } catch (IOException | ConfigurationException e) { |
68 | 72 | throw new RequestProviderException("trouble FromFile " + e, e); |
69 | 73 | } |
70 | 74 | } |
71 | 75 |
|
72 | 76 | static final String DEFAULT_INI_SECTION_NAME = "default"; |
73 | | - |
74 | | - static Properties getPropertiesFromIni(InputStream inputStream, String sectionName) throws IOException { |
75 | | - Ini ini = new Ini(); |
| 77 | + |
| 78 | + static Properties getPropertiesFromIni(InputStream inputStream, String sectionName) throws IOException, ConfigurationException { |
76 | 79 | try (Reader reader = new InputStreamReader(inputStream, OAuthConstants.UTF_8_CHARSET)) { |
77 | | - ini.load(reader); |
78 | | - Ini.Section section = ini.get(sectionName); |
| 80 | + INIConfiguration ini = new INIConfiguration(); |
| 81 | + ini.read(reader); |
| 82 | + HierarchicalConfiguration<ImmutableNode> section = ini.getSection(sectionName); |
79 | 83 | Properties properties = new Properties(); |
80 | | - properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY, |
81 | | - section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY)); |
82 | | - properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY, |
83 | | - section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY)); |
84 | | - properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY, |
85 | | - section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY)); |
86 | | - // scope is optional |
87 | | - String scope = section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY); |
88 | | - if (null != scope) |
89 | | - properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY, scope); |
90 | | - |
| 84 | + Iterator<String> it = section.getKeys(); |
| 85 | + while (it.hasNext()) { |
| 86 | + String key = it.next(); |
| 87 | + String value = section.getString(key); |
| 88 | + switch (key.replaceAll("\\.+", ".")) { |
| 89 | + case OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY: |
| 90 | + properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY, value); |
| 91 | + break; |
| 92 | + case OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY: |
| 93 | + properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY, value); |
| 94 | + break; |
| 95 | + case OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY: |
| 96 | + properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY, value); |
| 97 | + break; |
| 98 | + case OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY: |
| 99 | + properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY, value); |
| 100 | + break; |
| 101 | + } |
| 102 | + } |
91 | 103 | return properties; |
92 | 104 | } |
93 | 105 | } |
|
0 commit comments