/************************************************************************* * * * EJBCA Community: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.ejbca.configdump; import java.io.File; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Data class containing settings for configuration dump. * Probably better to use a builder pattern here. * * @version $Id: ConfigDumpSetting.java 29688 2018-08-20 15:27:29Z henriks $ * */ public class ConfigDumpSetting implements Serializable { private static final long serialVersionUID = 1L; public enum ItemType { ACMECONFIG, CA, CRYPTOTOKEN, PUBLISHER, APPROVALPROFILE, CERTPROFILE, EEPROFILE, SERVICE, ROLE, KEYBINDING, ENDENTITY, SYSCONFIG, ADMINPREFS, CMPCONFIG, OCSPCONFIG, PEERCONNECTOR, PEERCONFIG, SCEPCONFIG, ESTCONFIG, VALIDATOR, CTLOG, EXTENDEDKEYUSAGE, CERTEXTENSION }; private File location; private Map> included = new HashMap<>(); private Map> excluded = new HashMap<>(); private List includedAnyType = new ArrayList<>(); private List excludedAnyType = new ArrayList<>(); private boolean ignoreErrors; private boolean ignoreWarnings; public List getIncludedAnyType() { return includedAnyType; } public void setIncludedAnyType(List includedAnyType) { this.includedAnyType = includedAnyType; } public List getExcludedAnyType() { return excludedAnyType; } public void setExcludedAnyType(List excludedAnyType) { this.excludedAnyType = excludedAnyType; } public File getLocation() { return location; } public void setLocation(File location) { this.location = location; } public void setIncluded(Map> included) { this.included = included; } public void setExcluded(Map> excluded) { this.excluded = excluded; } public Map> getIncluded() { return included; } public Map> getExcluded() { return excluded; } public boolean getIgnoreErrors() { return ignoreErrors; } public boolean getIgnoreWarnings() { return ignoreWarnings; } public ConfigDumpSetting(final File location, final Map> included, final Map> excluded, final List includedAnyType, final List excludedAnyType, final boolean ignoreErrors, final boolean ignoreWarnings) { this.location = location; this.included = included; this.excluded = excluded; this.includedAnyType = includedAnyType; this.excludedAnyType = excludedAnyType; this.ignoreErrors = ignoreErrors; this.ignoreWarnings = ignoreWarnings; } public boolean isIncluded(final ItemType type, final String nameStr) { final List includeList = included.get(type); final List excludeList = excluded.get(type); final String name = (nameStr != null ? nameStr.toLowerCase() : ""); if (includeList != null) { for (ConfigdumpPattern p : includeList) { if (p.matches(name)) { return true; } } return false; } if (!includedAnyType.isEmpty()) { for (ConfigdumpPattern p : includedAnyType) { if (p.matches(name)) { return true; } } return false; } if (excludeList != null) { for (ConfigdumpPattern p : excludeList) { if (p.matches(name)) { return false; } } } for (ConfigdumpPattern p : excludedAnyType) { if (p.matches(name)) { return false; } } // Didn't match anything. Default is to include. return true; } }