3636/**
3737 * Factory class that provides new instances for the main authenticators :
3838 * <ul>
39- * <li>{@link BotAuthenticator} : to authenticate the main Bot service account</li>
40- * <li>{@link OboAuthenticator} : to perform on-behalf-of authentication</li>
39+ * <li>{@link BotAuthenticator} : to authenticate the main Bot service
40+ * account</li>
41+ * <li>{@link OboAuthenticator} : to perform on-behalf-of authentication</li>
4142 * </ul>
4243 */
4344@ Slf4j
@@ -64,8 +65,7 @@ public AuthenticatorFactory(@Nonnull BdkConfig bdkConfig, @Nonnull ApiClientFact
6465 *
6566 * @return a new {@link BotAuthenticator} instance.
6667 */
67- public @ Nonnull
68- BotAuthenticator getBotAuthenticator () throws AuthInitializationException {
68+ public @ Nonnull BotAuthenticator getBotAuthenticator () throws AuthInitializationException {
6969 if (this .config .getBot ().isBothCertificateAndRsaConfigured ()) {
7070 throw new AuthInitializationException (
7171 "Both of certificate and rsa authentication are configured. Only one of them should be provided." );
@@ -82,8 +82,7 @@ BotAuthenticator getBotAuthenticator() throws AuthInitializationException {
8282 this .apiClientFactory .getLoginClient (),
8383 this .apiClientFactory .getSessionAuthClient (),
8484 this .apiClientFactory .getKeyAuthClient (),
85- new AgentVersionService (new SignalsApi (this .apiClientFactory .getAgentClient ()))
86- );
85+ new AgentVersionService (new SignalsApi (this .apiClientFactory .getAgentClient ())));
8786 }
8887 if (this .config .getBot ().isRsaAuthenticationConfigured ()) {
8988 if (!this .config .getBot ().isRsaConfigurationValid ()) {
@@ -97,8 +96,7 @@ BotAuthenticator getBotAuthenticator() throws AuthInitializationException {
9796 this .loadPrivateKeyFromAuthenticationConfig (this .config .getBot ()),
9897 this .apiClientFactory .getLoginClient (),
9998 this .apiClientFactory .getRelayClient (),
100- new AgentVersionService (new SignalsApi (this .apiClientFactory .getAgentClient ()))
101- );
99+ new AgentVersionService (new SignalsApi (this .apiClientFactory .getAgentClient ())));
102100 }
103101 throw new AuthInitializationException ("Neither RSA private key nor certificate is configured." );
104102 }
@@ -108,8 +106,7 @@ BotAuthenticator getBotAuthenticator() throws AuthInitializationException {
108106 *
109107 * @return a new {@link OboAuthenticator} instance.
110108 */
111- public @ Nonnull
112- OboAuthenticator getOboAuthenticator () throws AuthInitializationException {
109+ public @ Nonnull OboAuthenticator getOboAuthenticator () throws AuthInitializationException {
113110 if (this .config .getApp ().isBothCertificateAndRsaConfigured ()) {
114111 throw new AuthInitializationException (
115112 "Both of certificate and rsa authentication are configured. Only one of them should be provided." );
@@ -122,8 +119,7 @@ OboAuthenticator getOboAuthenticator() throws AuthInitializationException {
122119 return new OboAuthenticatorCertImpl (
123120 this .config .getRetry (),
124121 this .config .getApp ().getAppId (),
125- this .apiClientFactory .getExtAppSessionAuthClient ()
126- );
122+ this .apiClientFactory .getExtAppSessionAuthClient ());
127123 }
128124 if (this .config .getApp ().isRsaAuthenticationConfigured ()) {
129125 if (!this .config .getApp ().isRsaConfigurationValid ()) {
@@ -134,8 +130,7 @@ OboAuthenticator getOboAuthenticator() throws AuthInitializationException {
134130 this .config .getRetry (),
135131 this .config .getApp ().getAppId (),
136132 this .loadPrivateKeyFromAuthenticationConfig (this .config .getApp ()),
137- this .apiClientFactory .getLoginClient ()
138- );
133+ this .apiClientFactory .getLoginClient ());
139134 }
140135 throw new AuthInitializationException ("Neither RSA private key nor certificate is configured." );
141136 }
@@ -145,8 +140,7 @@ OboAuthenticator getOboAuthenticator() throws AuthInitializationException {
145140 *
146141 * @return a new {@link ExtensionAppAuthenticator} instance.
147142 */
148- public @ Nonnull
149- ExtensionAppAuthenticator getExtensionAppAuthenticator () throws AuthInitializationException {
143+ public @ Nonnull ExtensionAppAuthenticator getExtensionAppAuthenticator () throws AuthInitializationException {
150144 if (this .config .getApp ().isBothCertificateAndRsaConfigured ()) {
151145 throw new AuthInitializationException (
152146 "Both of certificate and rsa authentication are configured. Only one of them should be provided." );
@@ -173,8 +167,7 @@ ExtensionAppAuthenticator getExtensionAppAuthenticator() throws AuthInitializati
173167 this .loadPrivateKeyFromAuthenticationConfig (this .config .getApp ()),
174168 this .apiClientFactory .getLoginClient (),
175169 this .apiClientFactory .getPodClient (),
176- extensionAppTokensRepository
177- );
170+ extensionAppTokensRepository );
178171 }
179172 throw new AuthInitializationException ("Neither RSA private key nor certificate is configured." );
180173 }
@@ -225,10 +218,13 @@ private static String loadPrivateKey(String privateKeyPath) throws IOException,
225218 throw new AuthInitializationException (
226219 "Unable to find RSA private key as classpath resource from: " + privateKeyPath );
227220 }
221+ try (InputStream resourceStream = is ) {
222+ return IOUtils .toString (resourceStream , StandardCharsets .UTF_8 );
223+ }
228224 } else {
229- is = new FileInputStream (privateKeyPath );
225+ try (InputStream fileStream = new FileInputStream (privateKeyPath )) {
226+ return IOUtils .toString (fileStream , StandardCharsets .UTF_8 );
227+ }
230228 }
231-
232- return IOUtils .toString (is , StandardCharsets .UTF_8 );
233229 }
234230}
0 commit comments