use of javax.servlet.HttpConstraintElement 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);
}
}
use of javax.servlet.HttpConstraintElement in project Payara by payara.
the class HealthCheckServletContainerInitializer method onStartup.
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
// Check if this context is the root one ("/")
if (ctx.getContextPath().isEmpty()) {
// Check if there is already a servlet for healthcheck
Map<String, ? extends ServletRegistration> registrations = ctx.getServletRegistrations();
MicroprofileHealthCheckConfiguration configuration = Globals.getDefaultHabitat().getService(MicroprofileHealthCheckConfiguration.class);
if (!Boolean.parseBoolean(configuration.getEnabled())) {
// MP Healthcheck disabled
return;
}
for (ServletRegistration reg : registrations.values()) {
if (reg.getClass().equals(HealthCheckServlet.class) || reg.getMappings().contains("/" + configuration.getEndpoint())) {
return;
}
}
String virtualServers = configuration.getVirtualServers();
if (!isEmpty(virtualServers) && !asList(virtualServers.split(",")).contains(ctx.getVirtualServerName())) {
return;
}
// Register servlet
ServletRegistration.Dynamic reg = ctx.addServlet("microprofile-healthcheck-servlet", HealthCheckServlet.class);
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);
if (Boolean.getBoolean(CREATE_INSECURE_ENDPOINT_TEST)) {
ServletRegistration.Dynamic insecureReg = ctx.addServlet("microprofile-healthcheck-servlet-insecure", HealthCheckServlet.class);
insecureReg.addMapping("/" + configuration.getEndpoint() + "-insecure/*");
}
}
}
}
use of javax.servlet.HttpConstraintElement in project iaf by ibissource.
the class ServletManager method registerServlet.
public void registerServlet(String servletName, Servlet servlet, String urlMapping, String[] roles, int loadOnStartup, Map<String, String> initParameters) {
log.info("instantiating IbisInitializer servlet name [" + servletName + "] servletClass [" + servlet + "] loadOnStartup [" + loadOnStartup + "]");
getServletContext().log("instantiating IbisInitializer servlet [" + servletName + "]");
AppConstants appConstants = AppConstants.getInstance();
String propertyPrefix = "servlet." + servletName + ".";
if (!appConstants.getBoolean(propertyPrefix + "enabled", true))
return;
ServletRegistration.Dynamic serv = getServletContext().addServlet(servletName, servlet);
ServletSecurity.TransportGuarantee transportGuarantee = getTransportGuarantee(propertyPrefix + "transportGuarantee");
String stage = appConstants.getString("dtap.stage", null);
String[] rolesCopy = new String[0];
if (roles != null && stage != null && !stage.equalsIgnoreCase("LOC"))
rolesCopy = roles;
String roleNames = appConstants.getString(propertyPrefix + "securityroles", null);
if (StringUtils.isNotEmpty(roleNames)) {
log.warn("property [" + propertyPrefix + "securityroles] has been replaced with [" + propertyPrefix + "securityRoles" + "]");
}
roleNames = appConstants.getString(propertyPrefix + "securityRoles", roleNames);
if (StringUtils.isNotEmpty(roleNames))
rolesCopy = roleNames.split(",");
declareRoles(rolesCopy);
HttpConstraintElement httpConstraintElement = new HttpConstraintElement(transportGuarantee, rolesCopy);
ServletSecurityElement constraint = new ServletSecurityElement(httpConstraintElement);
String urlMappingCopy = appConstants.getString(propertyPrefix + "urlMapping", urlMapping);
if (!urlMappingCopy.startsWith("/") && !urlMappingCopy.startsWith("*")) {
urlMappingCopy = "/" + urlMappingCopy;
}
serv.addMapping(urlMappingCopy);
int loadOnStartupCopy = appConstants.getInt(propertyPrefix + "loadOnStartup", loadOnStartup);
serv.setLoadOnStartup(loadOnStartupCopy);
serv.setServletSecurity(constraint);
if (initParameters != null && !initParameters.isEmpty()) {
// Manually loop through the map as serv.setInitParameters will fail all parameters even if only 1 fails...
for (String key : initParameters.keySet()) {
String value = initParameters.get(key);
if (!serv.setInitParameter(key, value)) {
log("unable to set init-parameter [" + key + "] with value [" + value + "] for servlet [" + servletName + "]", Level.ERROR);
}
}
}
if (log.isDebugEnabled())
log.debug("registered servlet [" + servletName + "] class [" + servlet + "] url [" + urlMapping + "] loadOnStartup [" + loadOnStartup + "]");
}
Aggregations