Skip to content

Commit 63c5d7b

Browse files
committed
throw original exception to keep compatibility with common RestTemplate
Signed-off-by: Yohei Kishimoto <[email protected]>
1 parent 29b9dc6 commit 63c5d7b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

kerberos/kerberos-client/src/main/java/org/springframework/security/kerberos/client/KerberosRestTemplate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ public T run() {
244244
});
245245

246246
}
247+
catch (RestClientException ex) {
248+
throw ex;
249+
}
247250
catch (Exception ex) {
248251
throw new RestClientException("Error running rest call", ex);
249252
}

kerberos/kerberos-client/src/test/java/org/springframework/security/kerberos/client/KerberosRestTemplateTests.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.io.File;
2020
import java.nio.charset.StandardCharsets;
2121
import java.util.Collections;
22+
import java.util.HashMap;
23+
import java.util.Map;
2224

2325
import okhttp3.mockwebserver.Dispatcher;
2426
import okhttp3.mockwebserver.MockResponse;
@@ -33,8 +35,10 @@
3335
import org.springframework.http.MediaType;
3436
import org.springframework.security.kerberos.test.KerberosSecurityTestcase;
3537
import org.springframework.security.kerberos.test.MiniKdc;
38+
import org.springframework.web.client.HttpClientErrorException;
3639

3740
import static org.assertj.core.api.Assertions.assertThat;
41+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3842

3943
class KerberosRestTemplateTests extends KerberosSecurityTestcase {
4044

@@ -72,6 +76,8 @@ void setUp() throws Exception {
7276
String serverPrincipal = "HTTP/localhost";
7377
File serverKeytab = new File(workDir, "server.keytab");
7478
kdc.createPrincipal(serverKeytab, serverPrincipal);
79+
80+
setUpClient();
7581
}
7682

7783
@AfterEach
@@ -81,13 +87,20 @@ void tearDown() throws Exception {
8187

8288
@Test
8389
void sendsNegotiateHeader() {
84-
setUpClient();
8590
String s = this.restTemplate.getForObject(this.baseUrl + "/get", String.class);
8691
assertThat(s).isEqualTo(helloWorld);
8792
}
8893

94+
@Test
95+
void throwsOriginalException() {
96+
assertThatThrownBy(() -> restTemplate.getForObject(this.baseUrl + "/notfound", String.class))
97+
.isInstanceOf(HttpClientErrorException.NotFound.class);
98+
}
99+
89100
private void setUpClient() {
90-
this.restTemplate = new KerberosRestTemplate(this.clientKeytab.getAbsolutePath(), this.clientPrincipal);
101+
Map<String, Object> loginOptions = new HashMap<>();
102+
loginOptions.put("refreshKrb5Config", "true");
103+
this.restTemplate = new KerberosRestTemplate(this.clientKeytab.getAbsolutePath(), this.clientPrincipal, loginOptions);
91104
}
92105

93106
private MockResponse getRequest(RecordedRequest request, byte[] body, String contentType) {

0 commit comments

Comments
 (0)