Search in sources :

Example 1 with JerseyServletContainerInitializer

use of org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer in project Payara by payara.

the class EjbInvokerContainerInitializer method onStartup.

@Override
public void onStartup(Set<Class<?>> set, ServletContext ctx) throws ServletException {
    EjbInvokerConfiguration config = Globals.getDefaultBaseServiceLocator().getService(EjbInvokerConfiguration.class);
    String endpoint = ctx.getContextPath();
    if (endpoint.startsWith("/")) {
        endpoint = endpoint.substring(1);
    }
    if (!config.getEndpoint().equals(endpoint)) {
        return;
    }
    if (Boolean.parseBoolean(config.getSecurityEnabled())) {
        String[] roles = config.getRoles().split(",");
        ServletRegistration.Dynamic reg = (ServletRegistration.Dynamic) ctx.getServletRegistration(EjbOverHttpApplication.class.getName());
        if (reg == null) {
            new JerseyServletContainerInitializer().onStartup(new HashSet<>(asList(EjbOverHttpApplication.class)), ctx);
            reg = (ServletRegistration.Dynamic) ctx.getServletRegistration(EjbOverHttpApplication.class.getName());
        }
        reg.setServletSecurity(new ServletSecurityElement(new HttpConstraintElement(CONFIDENTIAL, roles)));
        if (FORM_AUTH.equals(config.getAuthType())) {
            ServletRegistration defaultRegistration = ctx.getServletRegistration("default");
            defaultRegistration.addMapping("/login.xhtml");
            defaultRegistration.addMapping("/error.xhtml");
        }
        ctx.declareRoles(roles);
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) EjbInvokerConfiguration(fish.payara.ejb.http.admin.EjbInvokerConfiguration) HttpConstraintElement(javax.servlet.HttpConstraintElement) EjbOverHttpApplication(fish.payara.ejb.http.endpoint.EjbOverHttpApplication) ServletSecurityElement(javax.servlet.ServletSecurityElement) JerseyServletContainerInitializer(org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer)

Aggregations

EjbInvokerConfiguration (fish.payara.ejb.http.admin.EjbInvokerConfiguration)1 EjbOverHttpApplication (fish.payara.ejb.http.endpoint.EjbOverHttpApplication)1 HttpConstraintElement (javax.servlet.HttpConstraintElement)1 ServletRegistration (javax.servlet.ServletRegistration)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1 JerseyServletContainerInitializer (org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer)1