I have a Java application that I deploy on Tomcat (which itself is in a Docker container). The Tomcat requires authentification, asking for user and a passwort. User and password are written into tomcat/tomcat-users.xml and into web.xml with
<security-constraint>
<web-resource-collection>
<web-resource-name>RESTful Application Service</web-resource-name>
<url-pattern>/rest/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>restservice</role-name>
</auth-constraint>
</security-constraint>
This all works as planned.
The application is swaggerized and I would like to use swagger-ui (https://github.com/swagger-api/swagger-ui) to connect with it. This however does not work. I get
$ curl -I "http://localhost:8080/my-rest-service/rest/swagger.json"
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Cache-Control: private
Expires: XXXXXXXX
WWW-Authenticate: Basic realm="RESTful Application Service"
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 951
Date: XXXXXXXX
It does work if I disable the password protection by commenting the security-constraint mentioned above in the web.xml.
What can I do to get swagger to provide a user and a password to my Tomcat / Tomcat application?
From Saúl Martínez Vidals:
In dist/index.html I have to manipulate the part
function addApiKeyAuthorization(){
var key = encodeURIComponent($('#input_apiKey')[0].value);
if(key && key.trim() != "") {
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
log("added key " + key);
}
}
but how exactly?
From Adding Basic Authorization for Swagger-UI I thought it might be
function addApiKeyAuthorization(){
var key = encodeURIComponent($('#input_apiKey')[0].value);
if(key && key.trim() != "") {
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
swaggerUi.api.clientAuthorizations.add("api_key", new SwaggerClient.ApiKeyAuthorization("Authorization", "Basic YWRtaW46dG9tY2F0=", "header"));
log("added key " + key);
}
}
where YWRtaW46dG9tY2F0 is from https://webnet77.net/cgi-bin/helpers/base-64.pl but this did not help.