5151import org .apache .hc .client5 .http .impl .classic .HttpClientBuilder ;
5252import org .apache .hc .core5 .http .config .Lookup ;
5353import org .apache .hc .core5 .http .config .RegistryBuilder ;
54+ import org .jspecify .annotations .Nullable ;
5455
5556import org .springframework .http .HttpMethod ;
5657import org .springframework .http .client .HttpComponentsClientHttpRequestFactory ;
@@ -82,13 +83,13 @@ public class KerberosRestTemplate extends RestTemplate {
8283
8384 private static final Credentials credentials = new NullCredentials ();
8485
85- private final String keyTabLocation ;
86+ private final @ Nullable String keyTabLocation ;
8687
87- private final String userPrincipal ;
88+ private final @ Nullable String userPrincipal ;
8889
89- private final String password ;
90+ private final @ Nullable String password ;
9091
91- private final Map <String , Object > loginOptions ;
92+ private final @ Nullable Map <String , Object > loginOptions ;
9293
9394 /**
9495 * Instantiates a new kerberos rest template.
@@ -110,7 +111,7 @@ public KerberosRestTemplate(HttpClient httpClient) {
110111 * @param keyTabLocation the key tab location
111112 * @param userPrincipal the user principal
112113 */
113- public KerberosRestTemplate (String keyTabLocation , String userPrincipal ) {
114+ public KerberosRestTemplate (@ Nullable String keyTabLocation , @ Nullable String userPrincipal ) {
114115 this (keyTabLocation , userPrincipal , buildHttpClient ());
115116 }
116117
@@ -120,15 +121,16 @@ public KerberosRestTemplate(String keyTabLocation, String userPrincipal) {
120121 * @param userPrincipal the user principal
121122 * @param httpClient the http client
122123 */
123- public KerberosRestTemplate (String keyTabLocation , String userPrincipal , HttpClient httpClient ) {
124+ public KerberosRestTemplate (@ Nullable String keyTabLocation , @ Nullable String userPrincipal ,
125+ HttpClient httpClient ) {
124126 this (keyTabLocation , userPrincipal , null , null , httpClient );
125127 }
126128
127129 /**
128130 * Instantiates a new kerberos rest template.
129131 * @param loginOptions the login options
130132 */
131- public KerberosRestTemplate (Map <String , Object > loginOptions ) {
133+ public KerberosRestTemplate (@ Nullable Map <String , Object > loginOptions ) {
132134 this (null , null , null , loginOptions , buildHttpClient ());
133135 }
134136
@@ -137,7 +139,7 @@ public KerberosRestTemplate(Map<String, Object> loginOptions) {
137139 * @param loginOptions the login options
138140 * @param httpClient the http client
139141 */
140- public KerberosRestTemplate (Map <String , Object > loginOptions , HttpClient httpClient ) {
142+ public KerberosRestTemplate (@ Nullable Map <String , Object > loginOptions , HttpClient httpClient ) {
141143 this (null , null , null , loginOptions , httpClient );
142144 }
143145
@@ -147,7 +149,8 @@ public KerberosRestTemplate(Map<String, Object> loginOptions, HttpClient httpCli
147149 * @param userPrincipal the user principal
148150 * @param loginOptions the login options
149151 */
150- public KerberosRestTemplate (String keyTabLocation , String userPrincipal , Map <String , Object > loginOptions ) {
152+ public KerberosRestTemplate (@ Nullable String keyTabLocation , @ Nullable String userPrincipal ,
153+ @ Nullable Map <String , Object > loginOptions ) {
151154 this (keyTabLocation , userPrincipal , null , loginOptions , buildHttpClient ());
152155 }
153156
@@ -158,8 +161,8 @@ public KerberosRestTemplate(String keyTabLocation, String userPrincipal, Map<Str
158161 * @param password the password
159162 * @param loginOptions the login options
160163 */
161- public KerberosRestTemplate (String keyTabLocation , String userPrincipal , String password ,
162- Map <String , Object > loginOptions ) {
164+ public KerberosRestTemplate (@ Nullable String keyTabLocation , @ Nullable String userPrincipal ,
165+ @ Nullable String password , @ Nullable Map <String , Object > loginOptions ) {
163166 this (keyTabLocation , userPrincipal , password , loginOptions , buildHttpClient ());
164167 }
165168
@@ -171,8 +174,8 @@ public KerberosRestTemplate(String keyTabLocation, String userPrincipal, String
171174 * @param loginOptions the login options
172175 * @param httpClient the http client
173176 */
174- private KerberosRestTemplate (String keyTabLocation , String userPrincipal , String password ,
175- Map <String , Object > loginOptions , HttpClient httpClient ) {
177+ private KerberosRestTemplate (@ Nullable String keyTabLocation , @ Nullable String userPrincipal ,
178+ @ Nullable String password , @ Nullable Map <String , Object > loginOptions , HttpClient httpClient ) {
176179 super (new HttpComponentsClientHttpRequestFactory (httpClient ));
177180 this .keyTabLocation = keyTabLocation ;
178181 this .userPrincipal = userPrincipal ;
@@ -226,9 +229,9 @@ private LoginContext buildLoginContext() throws LoginException {
226229 }
227230
228231 @ Override
229- protected final <T > T doExecute (final URI url , final String uriTemplate , final HttpMethod method ,
230- final RequestCallback requestCallback , final ResponseExtractor < T > responseExtractor )
231- throws RestClientException {
232+ protected final <T > T doExecute (final URI url , final @ Nullable String uriTemplate ,
233+ final @ Nullable HttpMethod method , final @ Nullable RequestCallback requestCallback ,
234+ final @ Nullable ResponseExtractor < T > responseExtractor ) throws RestClientException {
232235
233236 try {
234237 LoginContext lc = buildLoginContext ();
@@ -249,23 +252,28 @@ public T run() {
249252 }
250253 }
251254
252- private <T > T doExecuteSubject (URI url , String uriTemplate , HttpMethod method , RequestCallback requestCallback ,
253- ResponseExtractor <T > responseExtractor ) throws RestClientException {
254- return super .doExecute (url , uriTemplate , method , requestCallback , responseExtractor );
255+ private <T > T doExecuteSubject (URI url , @ Nullable String uriTemplate , @ Nullable HttpMethod method ,
256+ @ Nullable RequestCallback requestCallback , @ Nullable ResponseExtractor <T > responseExtractor )
257+ throws RestClientException {
258+ T result = super .doExecute (url , uriTemplate , method , requestCallback , responseExtractor );
259+ if (result == null ) {
260+ throw new RestClientException ("doExecute returned null" );
261+ }
262+ return result ;
255263 }
256264
257265 private static final class ClientLoginConfig extends Configuration {
258266
259- private final String keyTabLocation ;
267+ private final @ Nullable String keyTabLocation ;
260268
261- private final String userPrincipal ;
269+ private final @ Nullable String userPrincipal ;
262270
263- private final String password ;
271+ private final @ Nullable String password ;
264272
265- private final Map <String , Object > loginOptions ;
273+ private final @ Nullable Map <String , Object > loginOptions ;
266274
267- private ClientLoginConfig (String keyTabLocation , String userPrincipal , String password ,
268- Map <String , Object > loginOptions ) {
275+ private ClientLoginConfig (@ Nullable String keyTabLocation , @ Nullable String userPrincipal ,
276+ @ Nullable String password , @ Nullable Map <String , Object > loginOptions ) {
269277 super ();
270278 this .keyTabLocation = keyTabLocation ;
271279 this .userPrincipal = userPrincipal ;
@@ -309,24 +317,24 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
309317 private static class NullCredentials implements Credentials {
310318
311319 @ Override
312- public Principal getUserPrincipal () {
320+ public @ Nullable Principal getUserPrincipal () {
313321 return null ;
314322 }
315323
316324 @ Override
317- public char [] getPassword () {
325+ public char @ Nullable [] getPassword () {
318326 return null ;
319327 }
320328
321329 }
322330
323331 private static final class CallbackHandlerImpl implements CallbackHandler {
324332
325- private final String userPrincipal ;
333+ private final @ Nullable String userPrincipal ;
326334
327- private final String password ;
335+ private final @ Nullable String password ;
328336
329- private CallbackHandlerImpl (String userPrincipal , String password ) {
337+ private CallbackHandlerImpl (@ Nullable String userPrincipal , @ Nullable String password ) {
330338 super ();
331339 this .userPrincipal = userPrincipal ;
332340 this .password = password ;
@@ -342,7 +350,9 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback
342350 }
343351 else if (callback instanceof PasswordCallback ) {
344352 PasswordCallback pc = (PasswordCallback ) callback ;
345- pc .setPassword (this .password .toCharArray ());
353+ if (this .password != null ) {
354+ pc .setPassword (this .password .toCharArray ());
355+ }
346356 }
347357 else {
348358 throw new UnsupportedCallbackException (callback , "Unknown Callback" );
0 commit comments