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());
}
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);
}
}
Aggregations