Merge pull request #3004 from hapifhir/jr-20210914-oidc-support-in-swagger
add support for OIDC authentication to Swagger API
This commit is contained in:
commit
0eb6958701
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
type: add
|
||||||
|
issue: 3005
|
||||||
|
jira: SMILE-723
|
||||||
|
title: "Open up the visibility of some methods in the generation of the Open API definition files to allow extenders to add support for OIDC authorization."
|
|
@ -262,6 +262,13 @@ public class OpenApiInterceptor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resourcePath.endsWith(".html")) {
|
||||||
|
theResponse.setContentType(Constants.CT_HTML);
|
||||||
|
theResponse.setStatus(200);
|
||||||
|
IOUtils.copy(resource, theResponse.getOutputStream());
|
||||||
|
theResponse.getOutputStream().close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -336,12 +343,18 @@ public class OpenApiInterceptor {
|
||||||
String page = extractPageName(theRequestDetails, PAGE_SYSTEM);
|
String page = extractPageName(theRequestDetails, PAGE_SYSTEM);
|
||||||
context.setVariable("PAGE", page);
|
context.setVariable("PAGE", page);
|
||||||
|
|
||||||
|
populateOIDCVariables(theRequestDetails, context);
|
||||||
|
|
||||||
String outcome = myTemplateEngine.process("index.html", context);
|
String outcome = myTemplateEngine.process("index.html", context);
|
||||||
|
|
||||||
theResponse.getWriter().write(outcome);
|
theResponse.getWriter().write(outcome);
|
||||||
theResponse.getWriter().close();
|
theResponse.getWriter().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void populateOIDCVariables(ServletRequestDetails theRequestDetails, WebContext theContext) {
|
||||||
|
theContext.setVariable("OAUTH2_REDIRECT_URL_PROPERTY", "");
|
||||||
|
}
|
||||||
|
|
||||||
private String extractPageName(ServletRequestDetails theRequestDetails, String theDefault) {
|
private String extractPageName(ServletRequestDetails theRequestDetails, String theDefault) {
|
||||||
String[] pageValues = theRequestDetails.getParameters().get("page");
|
String[] pageValues = theRequestDetails.getParameters().get("page");
|
||||||
String page = null;
|
String page = null;
|
||||||
|
@ -354,7 +367,7 @@ public class OpenApiInterceptor {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OpenAPI generateOpenApi(ServletRequestDetails theRequestDetails) {
|
protected OpenAPI generateOpenApi(ServletRequestDetails theRequestDetails) {
|
||||||
String page = extractPageName(theRequestDetails, null);
|
String page = extractPageName(theRequestDetails, null);
|
||||||
|
|
||||||
CapabilityStatement cs = getCapabilityStatement(theRequestDetails);
|
CapabilityStatement cs = getCapabilityStatement(theRequestDetails);
|
||||||
|
|
|
@ -18,7 +18,7 @@ body
|
||||||
background: #fafafa;
|
background: #fafafa;
|
||||||
}
|
}
|
||||||
|
|
||||||
.scheme-container, .information-container
|
.information-container
|
||||||
{
|
{
|
||||||
display: none
|
display: none
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
@ -55,7 +56,8 @@
|
||||||
plugins: [
|
plugins: [
|
||||||
// SwaggerUIBundle.plugins.DownloadUrl
|
// SwaggerUIBundle.plugins.DownloadUrl
|
||||||
],
|
],
|
||||||
// layout: "StandaloneLayout"
|
// layout: "StandaloneLayout",
|
||||||
|
oauth2RedirectUrl: "[[${OAUTH2_REDIRECT_URL_PROPERTY}]]"
|
||||||
});
|
});
|
||||||
// End Swagger UI call region
|
// End Swagger UI call region
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,17 @@ public class OpenApiInterceptorTest {
|
||||||
assertEquals(null, url);
|
assertEquals(null, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStandardRedirectScriptIsAccessible() throws IOException {
|
||||||
|
myServer.getRestfulServer().registerInterceptor(new AddResourceCountsInterceptor());
|
||||||
|
myServer.getRestfulServer().registerInterceptor(new OpenApiInterceptor());
|
||||||
|
|
||||||
|
HttpGet get = new HttpGet("http://localhost:" + myServer.getPort() + "/fhir/swagger-ui/oauth2-redirect.html");
|
||||||
|
try (CloseableHttpResponse response = myClient.execute(get)) {
|
||||||
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String fetchSwaggerUi(String url) throws IOException {
|
private String fetchSwaggerUi(String url) throws IOException {
|
||||||
String resp;
|
String resp;
|
||||||
HttpGet get = new HttpGet(url);
|
HttpGet get = new HttpGet(url);
|
||||||
|
|
Loading…
Reference in New Issue