Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ public T run() {
});

}
catch (RestClientException ex) {
throw ex;
}
catch (Exception ex) {
throw new RestClientException("Error running rest call", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
Expand All @@ -33,8 +35,10 @@
import org.springframework.http.MediaType;
import org.springframework.security.kerberos.test.KerberosSecurityTestcase;
import org.springframework.security.kerberos.test.MiniKdc;
import org.springframework.web.client.HttpClientErrorException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class KerberosRestTemplateTests extends KerberosSecurityTestcase {

Expand Down Expand Up @@ -72,6 +76,8 @@ void setUp() throws Exception {
String serverPrincipal = "HTTP/localhost";
File serverKeytab = new File(workDir, "server.keytab");
kdc.createPrincipal(serverKeytab, serverPrincipal);

setUpClient();
}

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

@Test
void sendsNegotiateHeader() {
setUpClient();
String s = this.restTemplate.getForObject(this.baseUrl + "/get", String.class);
assertThat(s).isEqualTo(helloWorld);
}

@Test
void throwsOriginalException() {
assertThatThrownBy(() -> restTemplate.getForObject(this.baseUrl + "/notfound", String.class))
.isInstanceOf(HttpClientErrorException.NotFound.class);
}

private void setUpClient() {
this.restTemplate = new KerberosRestTemplate(this.clientKeytab.getAbsolutePath(), this.clientPrincipal);
Map<String, Object> loginOptions = new HashMap<>();
loginOptions.put("refreshKrb5Config", "true");
this.restTemplate = new KerberosRestTemplate(this.clientKeytab.getAbsolutePath(), this.clientPrincipal, loginOptions);
}

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