Search in sources :

Example 36 with AppConstants

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 + "]");
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) ServletSecurity(javax.servlet.annotation.ServletSecurity) HttpConstraintElement(javax.servlet.HttpConstraintElement) ServletSecurityElement(javax.servlet.ServletSecurityElement) AppConstants(nl.nn.adapterframework.util.AppConstants)

Example 37 with AppConstants

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);
        }
    }
}
Also used : URL(java.net.URL) AppConstants(nl.nn.adapterframework.util.AppConstants)

Example 38 with AppConstants

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'");
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) File(java.io.File) AppConstants(nl.nn.adapterframework.util.AppConstants)

Example 39 with AppConstants

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();
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) StreamingOutput(javax.ws.rs.core.StreamingOutput) IOException(java.io.IOException) DatabaseMigratorBase(nl.nn.adapterframework.jdbc.migration.DatabaseMigratorBase) ZipOutputStream(java.util.zip.ZipOutputStream) AppConstants(nl.nn.adapterframework.util.AppConstants) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with AppConstants

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);
}
Also used : AppConstants(nl.nn.adapterframework.util.AppConstants)

Aggregations

AppConstants (nl.nn.adapterframework.util.AppConstants)42 IbisContext (nl.nn.adapterframework.configuration.IbisContext)7 File (java.io.File)6 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 FileWriter (java.io.FileWriter)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1