List of usage examples for java.util Properties remove
@Override public synchronized Object remove(Object key)
From source file:cc.pp.analyzer.paoding.knife.PaodingMaker.java
private static Properties loadProperties(Properties p, String path) throws IOException { URL url;/* www. ja va2s . c om*/ File file; String absolutePath; InputStream in; // ifexists?? boolean skipWhenNotExists = false; if (path.startsWith("ifexists:")) { skipWhenNotExists = true; path = path.substring("ifexists:".length()); } if (path.startsWith("classpath:")) { path = path.substring("classpath:".length()); url = getClassLoader().getResource(path); if (url == null) { if (skipWhenNotExists) { return p; } throw new FileNotFoundException("Not found " + path + " in classpath."); } file = new File(url.getFile()); in = url.openStream(); } else { if (path.startsWith("dic-home:")) { File dicHome = new File(getDicHome(p)); path = path.substring("dic-home:".length()); file = new File(dicHome, path); } else { file = new File(path); } if (skipWhenNotExists && !file.exists()) { return p; } in = new FileInputStream(file); } absolutePath = file.getAbsolutePath(); p.load(in); in.close(); String lastModifieds = p.getProperty("paoding.analysis.properties.lastModifieds"); String files = p.getProperty("paoding.analysis.properties.files"); String absolutePaths = p.getProperty("paoding.analysis.properties.files.absolutepaths"); if (lastModifieds == null) { p.setProperty("paoding.dic.properties.path", path); lastModifieds = String.valueOf(getFileLastModified(file)); files = path; absolutePaths = absolutePath; } else { lastModifieds = lastModifieds + ";" + getFileLastModified(file); files = files + ";" + path; absolutePaths = absolutePaths + ";" + absolutePath; } p.setProperty("paoding.analysis.properties.lastModifieds", lastModifieds); p.setProperty("paoding.analysis.properties.files", files); p.setProperty("paoding.analysis.properties.files.absolutepaths", absolutePaths); String importsValue = p.getProperty("paoding.imports"); if (importsValue != null) { p.remove("paoding.imports"); String[] imports = importsValue.split(";"); for (int i = 0; i < imports.length; i++) { loadProperties(p, imports[i]); } } return p; }
From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override/* w w w . jav a 2s. c o m*/ public boolean updatePin(AuthenticationToken authenticationToken, Integer cryptoTokenId, char[] currentAuthenticationCode, char[] newAuthenticationCode, boolean updateOnly) throws AuthorizationDeniedException, CryptoTokenAuthenticationFailedException, CryptoTokenOfflineException { final String[] requiredAuthorization = new String[] { CryptoTokenRules.MODIFY_CRYPTOTOKEN.resource() + "/" + cryptoTokenId, CryptoTokenRules.ACTIVATE.resource() + "/" + cryptoTokenId, CryptoTokenRules.DEACTIVATE.resource() + "/" + cryptoTokenId }; if (!accessControlSessionSession.isAuthorized(authenticationToken, requiredAuthorization)) { final String msg = INTRES.getLocalizedMessage("authorization.notuathorizedtoresource", Arrays.toString(requiredAuthorization), authenticationToken.toString()); throw new AuthorizationDeniedException(msg); } CryptoToken cryptoToken = getCryptoToken(cryptoTokenId); final Properties cryptoTokenProperties = cryptoToken.getProperties(); // Get current auto-activation pin (if any) final String oldAutoActivationPin = BaseCryptoToken.getAutoActivatePin(cryptoTokenProperties); if (oldAutoActivationPin == null && (updateOnly || newAuthenticationCode == null)) { // This is a NOOP call that will not lead to any change return false; } if (SoftCryptoToken.class.getName().equals(cryptoToken.getClass().getName())) { CryptoProviderTools.installBCProviderIfNotAvailable(); final KeyStore keystore; try { keystore = KeyStore.getInstance("PKCS12", "BC"); keystore.load(new ByteArrayInputStream(cryptoToken.getTokenData()), currentAuthenticationCode); } catch (Exception e) { final String msg = "Failed to use supplied current PIN." + " " + e; log.info(msg); throw new CryptoTokenAuthenticationFailedException(msg); } if (newAuthenticationCode == null) { // When no new pin is supplied, we will not modify the key-store and just remove the current auto-activation pin cryptoTokenProperties.remove(CryptoToken.AUTOACTIVATE_PIN_PROPERTY); cryptoToken.setProperties(cryptoTokenProperties); } else { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); keystore.store(baos, newAuthenticationCode); baos.close(); if (oldAutoActivationPin != null || !updateOnly) { BaseCryptoToken.setAutoActivatePin(cryptoTokenProperties, new String(newAuthenticationCode), true); } else { log.debug( "Auto-activation will not be used. Only changing pin for soft CryptoToken keystore."); } cryptoToken = CryptoTokenFactory.createCryptoToken(SoftCryptoToken.class.getName(), cryptoTokenProperties, baos.toByteArray(), cryptoTokenId, cryptoToken.getTokenName()); } catch (Exception e) { log.info("Unable to store soft keystore with new PIN: " + e); throw new CryptoTokenAuthenticationFailedException( "Unable to store soft keystore with new PIN"); } } } else { if (oldAutoActivationPin != null) { // If we have an old auto-activation pin we will compare the "current" with this value to avoid deactivating the token if (!oldAutoActivationPin.equals(new String(currentAuthenticationCode))) { final String msg = "Supplied PIN did not match auto-activation PIN."; log.info(msg); throw new CryptoTokenAuthenticationFailedException(msg); } else { log.debug( "Successfully verified the PIN for non-soft CryptoToken by comparing supplied PIN to auto-activation PIN."); } } else { // If we don't have an auto-activation pin to compare the supplied PIN to, we need to verify the supplied // PIN can be used in a de-activation/activation cycle. final boolean wasInactive = !isCryptoTokenStatusActive(authenticationToken, cryptoTokenId); cryptoToken.deactivate(); cryptoToken.activate(currentAuthenticationCode); if (wasInactive) { // Note that there is a small glitch here where the token was active, but we have no other options to verify the pin cryptoToken.deactivate(); } } if (newAuthenticationCode == null) { cryptoTokenProperties.remove(CryptoToken.AUTOACTIVATE_PIN_PROPERTY); } else { BaseCryptoToken.setAutoActivatePin(cryptoTokenProperties, new String(newAuthenticationCode), true); } cryptoToken.setProperties(cryptoTokenProperties); } // Save the modified CryptoToken try { cryptoTokenSession.mergeCryptoToken(cryptoToken); } catch (CryptoTokenNameInUseException e) { // This should not happen here since we use the same name and id throw new RuntimeException(e); } securityEventsLoggerSession.log(EventTypes.CRYPTOTOKEN_UPDATEPIN, EventStatus.SUCCESS, ModuleTypes.CRYPTOTOKEN, ServiceTypes.CORE, authenticationToken.toString(), String.valueOf(cryptoTokenId), null, null, "Updated PIN of CryptoToken '" + cryptoToken.getTokenName() + "' with id " + cryptoTokenId); // Return the current auto-activation state return BaseCryptoToken.getAutoActivatePin(cryptoTokenProperties) != null; }
From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java
@Override public void saveCryptoToken(AuthenticationToken authenticationToken, int cryptoTokenId, String tokenName, Properties properties, char[] authenticationCode) throws AuthorizationDeniedException, CryptoTokenOfflineException, CryptoTokenAuthenticationFailedException, CryptoTokenNameInUseException, NoSuchSlotException { if (log.isTraceEnabled()) { log.trace(">saveCryptoToken: " + tokenName + ", " + cryptoTokenId); }/* ww w . j a v a 2s. c om*/ // Note that an admin that is authorized to modify a token could gain access to another HSM slot etc.. if (!accessControlSessionSession.isAuthorized(authenticationToken, CryptoTokenRules.MODIFY_CRYPTOTOKEN.resource())) { final String msg = INTRES.getLocalizedMessage("authorization.notuathorizedtoresource", CryptoTokenRules.MODIFY_CRYPTOTOKEN.resource(), authenticationToken.toString()); throw new AuthorizationDeniedException(msg); } final CryptoToken currentCryptoToken = cryptoTokenSession.getCryptoToken(cryptoTokenId); final String className = currentCryptoToken.getClass().getName(); final byte[] tokendata = currentCryptoToken.getTokenData(); // Handle presence of auto-activation indicators boolean keepAutoActivateIfPresent = Boolean .valueOf(String.valueOf(properties.get(CryptoTokenManagementSession.KEEP_AUTO_ACTIVATION_PIN))); properties.remove(CryptoTokenManagementSession.KEEP_AUTO_ACTIVATION_PIN); final String newPin = BaseCryptoToken.getAutoActivatePin(properties); if (newPin != null) { BaseCryptoToken.setAutoActivatePin(properties, newPin, true); authenticationCode = newPin.toCharArray(); } else if (keepAutoActivateIfPresent) { final String currentPin = BaseCryptoToken.getAutoActivatePin(currentCryptoToken.getProperties()); if (currentPin != null) { BaseCryptoToken.setAutoActivatePin(properties, currentPin, true); authenticationCode = null; // We have an auto-activation pin and it didn't change; } } else if (authenticationCode == null || authenticationCode.length == 0) { // Check if the token was auto-activated before. it is now manually activated, so use the auto-activation code one last time final String currentPin = BaseCryptoToken.getAutoActivatePin(currentCryptoToken.getProperties()); if (currentPin != null) { authenticationCode = currentPin.toCharArray(); } } // TODO: If the current token is active we would like to dig out the code used to activate it and activate the new one as well.. // For SoftCryptoTokens, a new secret means that we should change it and it can only be done if the token is active final CryptoToken newCryptoToken = CryptoTokenFactory.createCryptoToken(className, properties, tokendata, cryptoTokenId, tokenName); // If a new authenticationCode is provided we should verify it before we go ahead and merge if (authenticationCode != null && authenticationCode.length > 0) { newCryptoToken.deactivate(); newCryptoToken.activate(authenticationCode); } final Map<String, Object> details = new LinkedHashMap<String, Object>(); details.put("msg", "Modified CryptoToken with id " + cryptoTokenId); putDelta("name", currentCryptoToken.getTokenName(), newCryptoToken.getTokenName(), details); putDelta("encProviderName", currentCryptoToken.getEncProviderName(), newCryptoToken.getEncProviderName(), details); putDelta("signProviderName", currentCryptoToken.getSignProviderName(), newCryptoToken.getSignProviderName(), details); putDelta(currentCryptoToken.getProperties(), newCryptoToken.getProperties(), details); cryptoTokenSession.mergeCryptoToken(newCryptoToken); securityEventsLoggerSession.log(EventTypes.CRYPTOTOKEN_EDIT, EventStatus.SUCCESS, ModuleTypes.CRYPTOTOKEN, ServiceTypes.CORE, authenticationToken.toString(), String.valueOf(cryptoTokenId), null, null, details); if (log.isTraceEnabled()) { log.trace("<saveCryptoToken: " + tokenName + ", " + cryptoTokenId); } }
From source file:org.alfresco.repo.transfer.RepoTransferReceiverImplTest.java
public void testAsyncCommitWithSummaryReport() throws Exception { log.info("start testAsyncCommitWithSummaryReport"); this.setDefaultRollback(false); Properties properties = (Properties) this.getApplicationContext().getBean("global-properties"); //save the value of this summary report property to restore later String prevValue = properties.getProperty(TransferCommons.TS_SIMPLE_REPORT); try {//w ww. j ava 2 s .c om properties.put(TransferCommons.TS_SIMPLE_REPORT, Boolean.TRUE.toString()); assertTrue(Boolean.parseBoolean(properties.getProperty(TransferCommons.TS_SIMPLE_REPORT))); localTestDestinationReports(true); } finally { if (prevValue == null) { properties.remove(TransferCommons.TS_SIMPLE_REPORT); } else { properties.put(TransferCommons.TS_SIMPLE_REPORT, prevValue); } } }
From source file:org.alfresco.repo.transfer.RepoTransferReceiverImplTest.java
public void testAsyncCommitWithOutSummaryReport() throws Exception { log.info("start testAsyncCommitWithOutSummaryReport"); this.setDefaultRollback(false); this.setDefaultRollback(false); Properties properties = (Properties) this.getApplicationContext().getBean("global-properties"); //save the value of this summary report property to restore later String prevValue = properties.getProperty(TransferCommons.TS_SIMPLE_REPORT); try {//from w w w. j a v a 2s .c o m properties.put(TransferCommons.TS_SIMPLE_REPORT, Boolean.FALSE.toString()); assertFalse(Boolean.parseBoolean(properties.getProperty(TransferCommons.TS_SIMPLE_REPORT))); localTestDestinationReports(false); } finally { if (prevValue == null) { properties.remove(TransferCommons.TS_SIMPLE_REPORT); } else { properties.put(TransferCommons.TS_SIMPLE_REPORT, prevValue); } } }
From source file:net.paoding.analysis.knife.PaodingMaker.java
private static Properties loadProperties(Properties p, String path) throws IOException { URL url;// w w w.ja va 2 s .c o m File file; String absolutePath; InputStream in; // ifexists?? boolean skipWhenNotExists = false; if (path.startsWith("ifexists:")) { skipWhenNotExists = true; path = path.substring("ifexists:".length()); } if (path.startsWith("classpath:")) { path = path.substring("classpath:".length()); url = getClassLoader().getResource(path); if (url == null) { if (skipWhenNotExists) { return p; } throw new FileNotFoundException("Not found " + path + " in classpath."); } /* * Fix issue 42 : ??Bug */ file = new File(getUrlPath(url)); in = url.openStream(); } else { if (path.startsWith("dic-home:")) { File dicHome = new File(getDicHome(p)); path = path.substring("dic-home:".length()); file = new File(dicHome, path); } else { file = new File(path); } if (skipWhenNotExists && !file.exists()) { return p; } in = new FileInputStream(file); } absolutePath = file.getAbsolutePath(); p.load(in); in.close(); String lastModifieds = p.getProperty("paoding.analysis.properties.lastModifieds"); String files = p.getProperty("paoding.analysis.properties.files"); String absolutePaths = p.getProperty("paoding.analysis.properties.files.absolutepaths"); if (lastModifieds == null) { p.setProperty("paoding.dic.properties.path", path); lastModifieds = String.valueOf(getFileLastModified(file)); files = path; absolutePaths = absolutePath; } else { lastModifieds = lastModifieds + ";" + getFileLastModified(file); files = files + ";" + path; absolutePaths = absolutePaths + ";" + absolutePath; } p.setProperty("paoding.analysis.properties.lastModifieds", lastModifieds); p.setProperty("paoding.analysis.properties.files", files); p.setProperty("paoding.analysis.properties.files.absolutepaths", absolutePaths); String importsValue = p.getProperty("paoding.imports"); if (importsValue != null) { p.remove("paoding.imports"); String[] imports = importsValue.split(";"); for (int i = 0; i < imports.length; i++) { loadProperties(p, imports[i]); } } return p; }
From source file:com.ibm.cics.ca1y.Emit.java
/** * Create a compiled pattern from the regex supplied in the properties, or a default. * /*from w w w. ja va2 s . c o m*/ * @param props * - the properties to find the regex in * @return compiled pattern */ private static Pattern getPattern(Properties props) { if (props.containsKey(TOKEN_REGEX)) { try { String regex = props.getProperty(TOKEN_REGEX); // Remove regex from properties to prevent it from being processed further props.remove(TOKEN_REGEX); return Pattern.compile(regex); } catch (Exception e) { logger.warning(messages.getString("InvalidRegex") + " " + TOKEN_REGEX_DEFAULT); } } return Pattern.compile(TOKEN_REGEX_DEFAULT); }
From source file:com.github.rvesse.airline.parser.aliases.UserAliasesSource.java
public List<AliasMetadata> load() throws FileNotFoundException, IOException { Properties properties = new Properties(); // Find the home directory since we will use this File homeDir = null;/*from w w w . j a v a 2 s .c o m*/ if (!StringUtils.isEmpty(System.getProperty("user.home"))) { homeDir = new File(System.getProperty("user.home")); } // Search locations in reverse order overwriting previously found values // each time. Thus the first location in the list has highest precedence Set<String> loaded = new HashSet<>(); for (int i = searchLocations.size() - 1; i >= 0; i--) { // Check an actual location String loc = searchLocations.get(i); if (StringUtils.isBlank(loc)) continue; // Allow use of ~/ or ~\ as reference to user home directory if (loc.startsWith("~" + File.separator)) { if (homeDir == null) continue; loc = homeDir.getAbsolutePath() + loc.substring(homeDir.getAbsolutePath().endsWith(File.separator) ? 2 : 1); } // Don't read property files multiple times if (loaded.contains(loc)) continue; File f = new File(loc); f = new File(f, filename); if (f.exists() && f.isFile() && f.canRead()) { try (FileInputStream input = new FileInputStream(f)) { properties.load(input); } finally { // Remember we've tried to read this file so we don't try // and read it multiple times loaded.add(loc); } } } // Strip any irrelevant properties if (StringUtils.isNotBlank(prefix)) { List<Object> keysToRemove = new ArrayList<Object>(); for (Object key : properties.keySet()) { if (!key.toString().startsWith(prefix)) keysToRemove.add(key); } for (Object key : keysToRemove) { properties.remove(key); } } // Generate the aliases List<AliasMetadata> aliases = new ArrayList<>(); for (Object key : properties.keySet()) { String name = key.toString(); if (!StringUtils.isBlank(prefix)) name = name.substring(prefix.length()); AliasBuilder<C> alias = new AliasBuilder<C>(name); String value = properties.getProperty(key.toString()); if (StringUtils.isEmpty(value)) { aliases.add(alias.build()); continue; } // Process property value into arguments List<String> args = AliasArgumentsParser.parse(value); alias.withArguments(args.toArray(new String[args.size()])); aliases.add(alias.build()); } return aliases; }
From source file:org.apache.jmeter.JMeterReport.java
private void initializeProperties(CLArgsParser parser) { if (parser.getArgumentById(PROPFILE_OPT) != null) { JMeterUtils.getProperties(parser.getArgumentById(PROPFILE_OPT).getArgument()); } else {/*from w w w .ja v a 2 s. c o m*/ JMeterUtils.getProperties( NewDriver.getJMeterDir() + File.separator + "bin" + File.separator + "jmeter.properties"); } // Bug 33845 - allow direct override of Home dir if (parser.getArgumentById(JMETER_HOME_OPT) == null) { JMeterUtils.setJMeterHome(NewDriver.getJMeterDir()); } else { JMeterUtils.setJMeterHome(parser.getArgumentById(JMETER_HOME_OPT).getArgument()); } // Process command line property definitions (can occur multiple times) Properties jmeterProps = JMeterUtils.getJMeterProperties(); List<CLOption> clOptions = parser.getArguments(); int size = clOptions.size(); for (int i = 0; i < size; i++) { CLOption option = clOptions.get(i); String name = option.getArgument(0); String value = option.getArgument(1); switch (option.getDescriptor().getId()) { case PROPFILE2_OPT: // Bug 33920 - allow multiple props File f = new File(name); FileInputStream inStream = null; try { inStream = new FileInputStream(f); jmeterProps.load(inStream); } catch (FileNotFoundException e) { log.warn("Can't find additional property file: " + name, e); } catch (IOException e) { log.warn("Error loading additional property file: " + name, e); } finally { IOUtils.closeQuietly(inStream); } break; case SYSTEM_PROPERTY: if (value.length() > 0) { // Set it log.info("Setting System property: " + name + "=" + value); System.getProperties().setProperty(name, value); } else { // Reset it log.warn("Removing System property: " + name); System.getProperties().remove(name); } break; case JMETER_PROPERTY: if (value.length() > 0) { // Set it log.info("Setting JMeter property: " + name + "=" + value); jmeterProps.setProperty(name, value); } else { // Reset it log.warn("Removing JMeter property: " + name); jmeterProps.remove(name); } break; case LOGLEVEL: if (value.length() > 0) { // Set category log.info("LogLevel: " + name + "=" + value); LoggingManager.setPriority(value, name); } else { // Set root level log.warn("LogLevel: " + name); LoggingManager.setPriority(name); } break; default: // ignored break; } } }
From source file:org.apache.geode.internal.cache.rollingupgrade.RollingUpgrade2DUnitTest.java
public Properties getSystemProperties(int[] locatorPorts) { Properties props = new Properties(); String locatorString = getLocatorString(locatorPorts); props.setProperty("locators", locatorString); props.setProperty("mcast-port", "0"); props.put(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true"); props.put(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "false"); props.remove(DistributionConfig.LOAD_CLUSTER_CONFIG_FROM_DIR_NAME); props.setProperty(DistributionConfig.LOG_LEVEL_NAME, DUnitLauncher.logLevel); return props; }