use of nl.nn.adapterframework.util.AppConstants 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 + "]");
}
use of nl.nn.adapterframework.util.AppConstants in project iaf by ibissource.
the class DetermineApplicationServerBean method checkSecurityConstraintEnabled.
private void checkSecurityConstraintEnabled() {
AppConstants appConstants = AppConstants.getInstance();
String stage = appConstants.getString("dtap.stage", "LOC");
if (appConstants.getBoolean("security.constraint.warning", !"LOC".equalsIgnoreCase(stage))) {
try {
String web = "/WEB-INF" + File.separator + "web.xml";
URL webXml = servletContext.getResource(web);
if (webXml != null) {
if (XmlUtils.buildDomDocument(webXml).getElementsByTagName("security-constraint").getLength() < 1)
ApplicationWarnings.add(log, "unsecure IBIS application, enable the security constraints section in the web.xml in order to secure the application!");
}
} catch (Exception e) {
ApplicationWarnings.add(log, "unable to determine whether security constraints have been enabled, is there a web.xml present?", e);
}
}
}
use of nl.nn.adapterframework.util.AppConstants in project iaf by ibissource.
the class FxfWrapperPipe method configure.
@Override
public void configure() throws ConfigurationException {
setRemoveOutputNamespaces(true);
if (getDirection() == Direction.WRAP) {
ParameterList parameterList = getParameterList();
if (parameterList.findParameter(DESTINATION) == null) {
parameterList.add(new Parameter(DESTINATION, DESTINATION_PREFIX + "." + retrieveStartTransferVersion() + "." + DESTINATION_SUFFIX));
}
}
super.configure();
AppConstants rootAppConstants = AppConstants.getInstance();
if (getDirection() == Direction.WRAP) {
instanceName = rootAppConstants.getResolvedProperty("instance.name");
if (StringUtils.isEmpty(instanceName)) {
throw new ConfigurationException("instance.name not available");
}
instanceNameLowerCase = rootAppConstants.getResolvedProperty("instance.name.lc");
if (StringUtils.isEmpty(instanceNameLowerCase)) {
throw new ConfigurationException("instance.name.lc not available");
}
environment = rootAppConstants.getResolvedProperty("dtap.stage");
if (StringUtils.isEmpty(environment) || environment.length() < 1) {
throw new ConfigurationException("dtap.stage not available");
}
environment = environment.substring(0, 1);
if (StringUtils.isEmpty(getFlowId())) {
throw new ConfigurationException("attribute flowId must be specified");
} else if (getFlowId().length() < 3) {
throw new ConfigurationException("attribute flowId too short");
}
} else {
if (!StringUtils.isEmpty(getFlowId())) {
throw new ConfigurationException("attribute flowId must not be specified");
}
fxfDir = AppConstants.getInstance(getConfigurationClassLoader()).getResolvedProperty("fxf.dir");
if (fxfDir == null) {
throw new ConfigurationException("property fxf.dir has not been initialised");
}
if (isCreateFolder() && !new File(fxfDir).exists() && !new File(fxfDir).mkdirs()) {
throw new ConfigurationException("cannot create fxf.dir in the path [" + fxfDir + "]");
}
if (!new File(fxfDir).isDirectory()) {
throw new ConfigurationException("fxf.dir [" + fxfDir + "] doesn't exist or is not a directory");
}
transferFlowIdTp = XmlUtils.getXPathTransformerPool(null, TRANSFORMER_FLOW_ID_XPATH, OutputType.TEXT, false, getParameterList());
String xpathFilename = isUseServerFilename() ? SERVER_FILENAME_XPATH : CLIENT_FILENAME_XPATH;
clientFilenameTp = XmlUtils.getXPathTransformerPool(null, xpathFilename, OutputType.TEXT, false, getParameterList());
}
if (StringUtils.isNotEmpty(getFlowOutFolder()) && !getFlowOutFolder().endsWith("/")) {
setFlowOutFolder(getFlowOutFolder() + "/");
}
if (!getFxfVersion().equals("3.1") && !getFxfVersion().equals("3.2")) {
throw new ConfigurationException("illegal value for fxfVersion [" + getFxfVersion() + "], must be '3.1' or '3.2'");
}
}
use of nl.nn.adapterframework.util.AppConstants in project iaf by ibissource.
the class ShowLiquibaseScript method downloadScript.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/jdbc/liquibase/download")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadScript() throws ApiException {
List<Configuration> configurations = new ArrayList<Configuration>();
for (Configuration config : getIbisManager().getConfigurations()) {
DatabaseMigratorBase databaseMigrator = config.getBean("jdbcMigrator", DatabaseMigratorBase.class);
if (databaseMigrator.hasMigrationScript()) {
configurations.add(config);
}
}
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException, WebApplicationException {
try (ZipOutputStream zos = new ZipOutputStream(out)) {
for (Configuration configuration : configurations) {
AppConstants appConstants = AppConstants.getInstance(configuration.getClassLoader());
String changeLogFile = appConstants.getString("liquibase.changeLogFile", "DatabaseChangelog.xml");
try (InputStream file = configuration.getClassLoader().getResourceAsStream(changeLogFile)) {
if (file != null) {
ZipEntry entry = new ZipEntry(changeLogFile);
zos.putNextEntry(entry);
zos.write(StreamUtil.streamToByteArray(file, false));
zos.closeEntry();
}
}
}
} catch (IOException e) {
throw new ApiException("Failed to create zip file with scripts.", e);
}
}
};
return Response.ok(stream).type(MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=\"DatabaseChangelog.zip\"").build();
}
use of nl.nn.adapterframework.util.AppConstants in project iaf by ibissource.
the class JdbcTransactionalStorage method setOperationControls.
@Override
protected void setOperationControls() {
super.setOperationControls();
AppConstants ac = AppConstants.getInstance();
checkTable = ac.getBoolean(PROPERTY_CHECK_TABLE, false);
checkIndices = ac.getBoolean(PROPERTY_CHECK_INDICES, true);
}
Aggregations