Skip to content

Commit

Permalink
Revert "Merge pull request payara#5323 from jGauravGupta/FISH-123"
Browse files Browse the repository at this point in the history
This reverts commit e1cec75.
  • Loading branch information
JamesHillyard committed Dec 22, 2021
1 parent d7de819 commit af74670
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ openAPI.configuration.securityEnabled=Enable Secure Access
openAPI.configuration.securityEnabledHelp=If checked, <code>/openapi</code> endpoint can be accessed only via HTTPS and disables the HTTP method with 403 HTTP response. And you will be required to log in before accessing the OpenAPI endpoint.
openAPI.configuration.roles=Roles:
openAPI.configuration.rolesHelp=Separate multiple roles with comma
openAPI.configuration.endpoint=EndPoint
openAPI.configuration.endpointHelp=The context root used to expose the OpenAPI.
openAPI.configuration.virtualServers=Virtual Servers:
openAPI.configuration.virtualServersHelp=Associates an Internet domain name with a physical server.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) [2018-2021] Payara Foundation and/or its affiliates. All rights reserved.
Copyright (c) [2018-2019] Payara Foundation and/or its affiliates. All rights reserved.

The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -113,12 +113,6 @@
helpText="$resource{i18n_microprofile.openAPI.configuration.rolesHelp}">
<sun:textField id="roles" maxLength="250" text="#{pageSession.valueMap['roles']}"/>
</sun:property>
<sun:property id="endPointProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}"
label="$resource{i18n_microprofile.openAPI.configuration.endpoint}"
helpText="$resource{i18n_microprofile.openAPI.configuration.endpointHelp}">
<sun:textField id="endPoint" columns="$int{40}" maxLength="250"
text="#{pageSession.valueMap['endpoint']}"/>
</sun:property>
<sun:property id="virtualServersProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}"
label="$resource{i18n_microprofile.openAPI.configuration.virtualServers}"
helpText="$resource{i18n_microprofile.openAPI.configuration.virtualServersHelp}" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
})
public class GetOpenApiConfigurationCommand implements AdminCommand {

private final String[] OUTPUT_HEADERS = {"Enabled", "EndPoint", "VirtualServers", "CorsHeaders", "Security Enabled", "Roles"};
private final String[] OUTPUT_HEADERS = {"Enabled", "VirtualServers", "CorsHeaders", "Security Enabled", "Roles"};

@Inject
private Target targetUtil;
Expand All @@ -101,7 +101,6 @@ public void execute(AdminCommandContext context) {
ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
Object[] outputValues = {
openApiConfig.getEnabled(),
openApiConfig.getEndpoint(),
openApiConfig.getVirtualServers(),
openApiConfig.getCorsHeaders(),
openApiConfig.getSecurityEnabled(),
Expand All @@ -113,7 +112,6 @@ public void execute(AdminCommandContext context) {

Map<String, Object> extraPropertiesMap = new HashMap<>();
extraPropertiesMap.put("enabled", openApiConfig.getEnabled());
extraPropertiesMap.put("endpoint", openApiConfig.getEndpoint());
extraPropertiesMap.put("virtualServers", openApiConfig.getVirtualServers());
extraPropertiesMap.put("corsHeaders", openApiConfig.getCorsHeaders());
extraPropertiesMap.put("securityenabled", openApiConfig.getSecurityEnabled());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2018-2021] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2018-2019] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -58,14 +58,6 @@ public interface OpenApiServiceConfiguration extends ConfigExtension {
String getEnabled();

void setEnabled(String value) throws PropertyVetoException;

/**
* @return a String value defines the endpoint of openapi service.
*/
@Attribute(defaultValue = "openapi")
String getEndpoint();

void setEndpoint(String value) throws PropertyVetoException;

/**
* Defines if CORS headers are set on the OpenApi response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public class SetOpenApiConfigurationCommand extends SetSecureMicroprofileConfigu
@Param(name = "enabled", optional = true)
private Boolean enabled;

@Param(name = "endpoint", optional = true)
private String endpoint;

@Param(name = "virtualServers", optional = true)
private String virtualServers;

Expand Down Expand Up @@ -129,9 +126,6 @@ public void execute(AdminCommandContext context) {
if (enabled != null) {
configProxy.setEnabled(Boolean.toString(enabled));
}
if (endpoint != null) {
configProxy.setEndpoint(endpoint);
}
if (virtualServers != null) {
configProxy.setVirtualServers(virtualServers);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2018-2021] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2018--2020] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -37,18 +37,22 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.microprofile.openapi.rest.app;
package fish.payara.microprofile.openapi.impl.rest.app;

import static fish.payara.microprofile.openapi.impl.rest.app.OpenApiApplication.OPEN_API_APPLICATION_PATH;
import fish.payara.microprofile.openapi.impl.rest.app.provider.CorsHeadersFilter;
import fish.payara.microprofile.openapi.impl.rest.app.provider.QueryFormatFilter;
import fish.payara.microprofile.openapi.impl.rest.app.provider.writer.JsonWriter;
import fish.payara.microprofile.openapi.impl.rest.app.provider.writer.YamlWriter;
import fish.payara.microprofile.openapi.impl.rest.app.service.OpenApiResource;
import jakarta.ws.rs.ApplicationPath;
import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN;
import org.glassfish.jersey.server.ResourceConfig;

@ApplicationPath(OPEN_API_APPLICATION_PATH)
public class OpenApiApplication extends ResourceConfig {

public static final String OPEN_API_APPLICATION_PATH = "/openapi";
public static final String APPLICATION_YAML = TEXT_PLAIN;

public OpenApiApplication() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
package fish.payara.microprofile.openapi.impl.rest.app.provider;

import static fish.payara.microprofile.openapi.rest.app.OpenApiApplication.APPLICATION_YAML;
import static fish.payara.microprofile.openapi.impl.rest.app.OpenApiApplication.APPLICATION_YAML;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
package fish.payara.microprofile.openapi.impl.rest.app.provider.writer;

import static fish.payara.microprofile.openapi.rest.app.OpenApiApplication.APPLICATION_YAML;
import static fish.payara.microprofile.openapi.impl.rest.app.OpenApiApplication.APPLICATION_YAML;
import fish.payara.microprofile.openapi.impl.rest.app.provider.ObjectMapperFactory;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.ext.Provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import fish.payara.microprofile.openapi.impl.model.OpenAPIImpl;
import fish.payara.microprofile.openapi.impl.processor.BaseProcessor;

import static fish.payara.microprofile.openapi.rest.app.OpenApiApplication.APPLICATION_YAML;
import static fish.payara.microprofile.openapi.impl.rest.app.OpenApiApplication.APPLICATION_YAML;
import java.io.IOException;
import static java.util.logging.Level.WARNING;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
package fish.payara.microprofile.openapi.impl.rest.init;

import fish.payara.microprofile.openapi.impl.admin.OpenApiServiceConfiguration;
import fish.payara.microprofile.openapi.rest.app.OpenApiApplication;
import fish.payara.microprofile.openapi.impl.rest.app.OpenApiApplication;
import static fish.payara.microprofile.openapi.impl.rest.app.OpenApiApplication.OPEN_API_APPLICATION_PATH;
import static java.util.Arrays.asList;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -54,7 +55,6 @@
import static jakarta.servlet.annotation.ServletSecurity.TransportGuarantee.CONFIDENTIAL;
import static org.glassfish.common.util.StringHelper.isEmpty;
import org.glassfish.internal.api.Globals;
import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer;

/**
Expand All @@ -70,16 +70,16 @@ public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletExcepti
if (!"".equals(ctx.getContextPath())) {
return;
}
OpenApiServiceConfiguration configuration = Globals.getDefaultHabitat().getService(OpenApiServiceConfiguration.class);

// Check if there is already an endpoint for OpenAPI
Map<String, ? extends ServletRegistration> registrations = ctx.getServletRegistrations();
for (ServletRegistration reg : registrations.values()) {
if (reg.getMappings().contains(configuration.getEndpoint())) {
if (reg.getMappings().contains(OPEN_API_APPLICATION_PATH)) {
return;
}
}

OpenApiServiceConfiguration configuration = Globals.getDefaultHabitat().getService(OpenApiServiceConfiguration.class);
String virtualServers = configuration.getVirtualServers();
if (!isEmpty(virtualServers)
&& !asList(virtualServers.split(",")).contains(ctx.getVirtualServerName())) {
Expand All @@ -89,9 +89,7 @@ public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletExcepti
// Start the OpenAPI application
new JerseyServletContainerInitializer().onStartup(new HashSet<>(asList(OpenApiApplication.class)), ctx);

ServletContainer servletContainer = new ServletContainer(new OpenApiApplication());
ServletRegistration.Dynamic reg = ctx.addServlet("microprofile-openapi-servlet", servletContainer);
reg.addMapping("/" + configuration.getEndpoint() + "/*");
ServletRegistration.Dynamic reg = (ServletRegistration.Dynamic) ctx.getServletRegistrations().get(OpenApiApplication.class.getName());
if (Boolean.parseBoolean(configuration.getSecurityEnabled())) {
String[] roles = configuration.getRoles().split(",");
reg.setServletSecurity(new ServletSecurityElement(new HttpConstraintElement(CONFIDENTIAL, roles)));
Expand Down

0 comments on commit af74670

Please sign in to comment.