Search in sources :

Example 1 with IdentityService

use of org.openremote.container.security.IdentityService in project openremote by openremote.

the class ManagerWebService method createApiHandler.

protected HttpHandler createApiHandler(Container container, ResteasyDeployment resteasyDeployment) {
    if (resteasyDeployment == null)
        return null;
    ServletInfo restServlet = Servlets.servlet("RESTEasy Servlet", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/*");
    DeploymentInfo deploymentInfo = new DeploymentInfo().setDeploymentName("RESTEasy Deployment").setContextPath(API_PATH).addServletContextAttribute(ResteasyDeployment.class.getName(), resteasyDeployment).addServlet(restServlet).setClassLoader(Container.class.getClassLoader());
    IdentityService identityService = container.getService(IdentityService.class);
    if (identityService != null) {
        resteasyDeployment.setSecurityEnabled(true);
    } else {
        throw new RuntimeException("No identity service deployed, can't enable API security");
    }
    return addServletDeployment(container, deploymentInfo, resteasyDeployment.isSecurityEnabled());
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) IdentityService(org.openremote.container.security.IdentityService) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Container(org.openremote.model.Container) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 2 with IdentityService

use of org.openremote.container.security.IdentityService in project openremote by openremote.

the class WebService method addServletDeployment.

/**
 * Adds a deployment to the default servlet container and returns the started handler.
 */
public static HttpHandler addServletDeployment(Container container, DeploymentInfo deploymentInfo, boolean secure) {
    IdentityService identityService = container.getService(IdentityService.class);
    boolean devMode = container.isDevMode();
    try {
        if (secure) {
            if (identityService == null)
                throw new IllegalStateException("No identity service found, make sure " + IdentityService.class.getName() + " is added before this service");
            identityService.secureDeployment(deploymentInfo);
        } else {
            LOG.info("Deploying insecure web context: " + deploymentInfo.getContextPath());
        }
        // This will catch anything not handled by Resteasy/Servlets, such as IOExceptions "at the wrong time"
        deploymentInfo.setExceptionHandler(new WebServiceExceptions.ServletUndertowExceptionHandler(devMode));
        // Add CORS filter that works for any servlet deployment
        FilterInfo corsFilterInfo = getCorsFilterInfo(container);
        if (corsFilterInfo != null) {
            deploymentInfo.addFilter(corsFilterInfo);
            deploymentInfo.addFilterUrlMapping(corsFilterInfo.getName(), "*", DispatcherType.REQUEST);
            deploymentInfo.addFilterUrlMapping(corsFilterInfo.getName(), "*", DispatcherType.FORWARD);
        }
        DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo);
        manager.deploy();
        return manager.start();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : IdentityService(org.openremote.container.security.IdentityService) DeploymentManager(io.undertow.servlet.api.DeploymentManager) FilterInfo(io.undertow.servlet.api.FilterInfo)

Aggregations

IdentityService (org.openremote.container.security.IdentityService)2 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 FilterInfo (io.undertow.servlet.api.FilterInfo)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1 HttpServlet30Dispatcher (org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher)1 ResteasyDeployment (org.jboss.resteasy.spi.ResteasyDeployment)1 Container (org.openremote.model.Container)1