Search in sources :

Example 1 with OpenApiServiceConfiguration

use of fish.payara.microprofile.openapi.impl.admin.OpenApiServiceConfiguration in project Payara by payara.

the class OpenApiService method initConfig.

@PostConstruct
public void initConfig() {
    OpenApiServiceConfiguration config = Globals.get(OpenApiServiceConfiguration.class);
    this.enabled = Boolean.valueOf(config.getEnabled());
    this.securityEnabled = Boolean.valueOf(config.getSecurityEnabled());
    this.withCorsHeaders = Boolean.valueOf(config.getCorsHeaders());
}
Also used : OpenApiServiceConfiguration(fish.payara.microprofile.openapi.impl.admin.OpenApiServiceConfiguration) PostConstruct(javax.annotation.PostConstruct)

Example 2 with OpenApiServiceConfiguration

use of fish.payara.microprofile.openapi.impl.admin.OpenApiServiceConfiguration in project Payara by payara.

the class OpenApiServletContainerInitializer method onStartup.

@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
    // Only deploy to app root
    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())) {
            return;
        }
    }
    String virtualServers = configuration.getVirtualServers();
    if (!isEmpty(virtualServers) && !asList(virtualServers.split(",")).contains(ctx.getVirtualServerName())) {
        return;
    }
    // Start the OpenAPI application
    ServletContainer servletContainer = new ServletContainer(new OpenApiApplication());
    ServletRegistration.Dynamic reg = ctx.addServlet("microprofile-openapi-servlet", servletContainer);
    reg.setLoadOnStartup(1);
    reg.addMapping("/" + configuration.getEndpoint() + "/*");
    if (Boolean.parseBoolean(configuration.getSecurityEnabled())) {
        String[] roles = configuration.getRoles().split(",");
        reg.setServletSecurity(new ServletSecurityElement(new HttpConstraintElement(CONFIDENTIAL, roles)));
        ctx.declareRoles(roles);
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) OpenApiApplication(fish.payara.microprofile.openapi.rest.app.OpenApiApplication) HttpConstraintElement(javax.servlet.HttpConstraintElement) OpenApiServiceConfiguration(fish.payara.microprofile.openapi.impl.admin.OpenApiServiceConfiguration) ServletSecurityElement(javax.servlet.ServletSecurityElement)

Aggregations

OpenApiServiceConfiguration (fish.payara.microprofile.openapi.impl.admin.OpenApiServiceConfiguration)2 OpenApiApplication (fish.payara.microprofile.openapi.rest.app.OpenApiApplication)1 PostConstruct (javax.annotation.PostConstruct)1 HttpConstraintElement (javax.servlet.HttpConstraintElement)1 ServletRegistration (javax.servlet.ServletRegistration)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)1