Java源码示例:com.beust.jcommander.internal.Console
示例1
/**
* Returns an instance of the encryption service, initialized with the token at the provided
* resource location
*
* @param resourceLocation location of the resource token to initialize the encryption service
* with
* @return An initialized instance of the encryption service
* @throws Exception
*/
private static synchronized BaseEncryption getEncryptionService(
final String resourceLocation,
Console console) throws Throwable {
if (encService == null) {
if ((resourceLocation != null) && !"".equals(resourceLocation.trim())) {
LOGGER.trace(
"Setting resource location for encryption service: [" + resourceLocation + "]");
encService = new GeoWaveEncryption(resourceLocation, console);
} else {
encService = new GeoWaveEncryption(console);
}
} else {
if (!resourceLocation.equals(encService.getResourceLocation())) {
encService = new GeoWaveEncryption(resourceLocation, console);
}
}
return encService;
}
示例2
/** Check if encryption token exists. If not, create one initially */
private void checkForToken(Console console) throws Throwable {
if (getResourceLocation() != null) {
// this is simply caching the location, ideally under all
// circumstances resource location exists
tokenFile = new File(getResourceLocation());
} else {
// and this is initializing it for the first time, this just assumes
// the default config file path
// because of that assumption this can cause inconsistency
// under all circumstances this seems like it should never happen
tokenFile =
SecurityUtils.getFormattedTokenKeyFileForConfig(
ConfigOptions.getDefaultPropertyFile(console));
}
if (!tokenFile.exists()) {
generateNewEncryptionToken(tokenFile);
}
}
示例3
/**
* The default property file is in the user's home directory, in the .geowave folder. If the
* version can not be found the first available property file in the folder is used.
*
* @param console console to print output to
*
* @return the default property file
*/
public static File getDefaultPropertyFile(final Console console) {
// HP Fortify "Path Manipulation" false positive
// What Fortify considers "user input" comes only
// from users with OS-level access anyway
final File defaultPath = getDefaultPropertyPath();
final String version = VersionUtils.getVersion(console);
if (version != null) {
return formatConfigFile(version, defaultPath);
} else {
final String[] configFiles = defaultPath.list(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.endsWith("-config.properties");
}
});
if ((configFiles != null) && (configFiles.length > 0)) {
final String backupVersion = configFiles[0].substring(0, configFiles[0].length() - 18);
return formatConfigFile(backupVersion, defaultPath);
} else {
return formatConfigFile("unknownversion", defaultPath);
}
}
}
示例4
public static Properties getBuildProperties(final Console console) {
final Properties props = new Properties();
try (InputStream stream =
VersionUtils.class.getClassLoader().getResourceAsStream(BUILD_PROPERTIES_FILE_NAME);) {
if (stream != null) {
props.load(stream);
}
return props;
} catch (final IOException e) {
LOGGER.warn("Cannot read GeoWave build properties to show version information", e);
if (console != null) {
console.println(
"Cannot read GeoWave build properties to show version information: " + e.getMessage());
}
}
return props;
}
示例5
@Test
public void testEncryptionDecryption() throws Exception {
final String rawInput = "geowave";
Console console = new JCommander().getConsole();
final File tokenFile =
SecurityUtils.getFormattedTokenKeyFileForConfig(
ConfigOptions.getDefaultPropertyFile(console));
if ((tokenFile != null) && tokenFile.exists()) {
final String encryptedValue =
SecurityUtils.encryptAndHexEncodeValue(rawInput, tokenFile.getCanonicalPath(), console);
final String decryptedValue =
SecurityUtils.decryptHexEncodedValue(
encryptedValue,
tokenFile.getCanonicalPath(),
console);
assertEquals(decryptedValue, rawInput);
}
}
示例6
@Override
protected boolean performStatsCommand(
final DataStorePluginOptions storeOptions,
final InternalDataAdapter<?> adapter,
final StatsCommandLineOptions statsOptions,
final Console console) throws IOException {
// Remove the stat
final DataStatisticsStore statStore = storeOptions.createDataStatisticsStore();
final String[] authorizations = getAuthorizations(statsOptions.getAuthorizations());
if (!statStore.removeStatistics(
adapter.getAdapterId(),
fieldName,
new BaseStatisticsType<>(statType),
authorizations)) {
throw new RuntimeException("Unable to remove statistic: " + statType);
}
return true;
}
示例7
public VectorMRExportJobRunner(
final DataStorePluginOptions storeOptions,
final VectorMRExportOptions mrOptions,
final String hdfsHostPort,
final String hdfsPath,
final Console console) {
this.storeOptions = storeOptions;
this.mrOptions = mrOptions;
this.hdfsHostPort = hdfsHostPort;
this.hdfsPath = hdfsPath;
this.console = console;
}
示例8
private GeoServerRestClient(
final GeoServerConfig config,
final WebTarget webTarget,
final Console console) {
this.config = config;
this.webTarget = webTarget;
this.console = console;
}
示例9
public static GeoServerRestClient getInstance(
final GeoServerConfig config,
final Console console) {
if (SINGLETON_INSTANCE == null) {
SINGLETON_INSTANCE = new GeoServerRestClient(config, console);
}
return SINGLETON_INSTANCE;
}
示例10
@Before
public void prepare() {
webTarget = mockedWebTarget();
final Console console = new JCommander().getConsole();
config = new GeoServerConfig(console);
client = GeoServerRestClient.getInstance(config, console);
client.setWebTarget(webTarget);
}
示例11
@Override
public void validatePluginOptions(final Properties properties, final Console console)
throws ParameterException {
// Set the directory to be absolute
dir = Paths.get(dir).toAbsolutePath().toString();
super.validatePluginOptions(properties, console);
}
示例12
@Override
public void validatePluginOptions(final Properties properties, final Console console)
throws ParameterException {
// Set the directory to be absolute
dir = new File(dir).getAbsolutePath();
super.validatePluginOptions(properties, console);
}
示例13
private DataStorePluginOptions loadStore(
final String storeName,
final File configFile,
final Console console) {
final StoreLoader storeLoader = new StoreLoader(storeName);
if (!storeLoader.loadFromConfig(configFile, console)) {
throw new ParameterException("Cannot find left store: " + storeLoader.getStoreName());
}
return storeLoader.getDataStorePlugin();
}
示例14
/**
* Method to decrypt a value
*
* @param value Value to decrypt. Should be wrapped with ENC{}
* @param resourceLocation Optional value to specify the location of the encryption service
* resource location
* @return decrypted value
*/
public static String decryptHexEncodedValue(
final String value,
final String resourceLocation,
Console console) throws Exception {
LOGGER.trace("Decrypting hex-encoded value");
if ((value != null) && !"".equals(value.trim())) {
if (BaseEncryption.isProperlyWrapped(value.trim())) {
try {
return getEncryptionService(resourceLocation, console).decryptHexEncoded(value);
} catch (final Throwable t) {
LOGGER.error(
"Encountered exception during content decryption: " + t.getLocalizedMessage(),
t);
}
} else {
LOGGER.debug(
"WARNING: Value to decrypt was not propertly encoded and wrapped with "
+ WRAPPER
+ ". Not decrypting value.");
return value;
}
} else {
LOGGER.debug("WARNING: No value specified to decrypt.");
}
return "";
}
示例15
/**
* Method to encrypt and hex-encode a string value
*
* @param value value to encrypt and hex-encode
* @param resourceLocation resource token to use for encrypting the value
* @return If encryption is successful, encrypted and hex-encoded string value is returned wrapped
* with ENC{}
*/
public static String encryptAndHexEncodeValue(
final String value,
final String resourceLocation,
Console console) throws Exception {
LOGGER.debug("Encrypting and hex-encoding value");
if ((value != null) && !"".equals(value.trim())) {
if (!BaseEncryption.isProperlyWrapped(value)) {
try {
return getEncryptionService(resourceLocation, console).encryptAndHexEncode(value);
} catch (final Throwable t) {
LOGGER.error(
"Encountered exception during content encryption: " + t.getLocalizedMessage(),
t);
}
} else {
LOGGER.debug(
"WARNING: Value to encrypt already appears to be encrypted and already wrapped with "
+ WRAPPER
+ ". Not encrypting value.");
return value;
}
} else {
LOGGER.debug("WARNING: No value specified to encrypt.");
return value;
}
return value;
}
示例16
/**
* Base constructor for encryption, allowing a resource location for the cryptography token key to
* be specified, rather than using the default-generated path
*
* @param resourceLocation Path to cryptography token key file
*/
public BaseEncryption(final String resourceLocation, Console console) {
try {
setResourceLocation(resourceLocation);
init(console);
} catch (final Throwable t) {
LOGGER.error(t.getLocalizedMessage(), t);
}
}
示例17
/**
* Method to initialize all required fields, check for the existence of the cryptography token
* key, and generate the key for encryption/decryption
*/
private void init(Console console) {
try {
checkForToken(console);
setResourceLocation(tokenFile.getCanonicalPath());
salt = "[email protected]".getBytes("UTF-8");
generateRootKeyFromToken();
} catch (final Throwable t) {
LOGGER.error(t.getLocalizedMessage(), t);
}
}
示例18
/**
* Write the given properties to the file, and log an error if an exception occurs.
*
* @return true if success, false if failure
*/
public static boolean writeProperties(
final File configFile,
final Properties properties,
final Console console) {
return writeProperties(configFile, properties, null, null, console);
}
示例19
/**
* Attempt to load the data store configuration from the config file.
*
* @param console the console to print output to
* @param configFile
* @return {@code true} if the configuration was successfully loaded
*/
public boolean loadFromConfig(final File configFile, final Console console) {
final String namespace = DataStorePluginOptions.getStoreNamespace(storeName);
return loadFromConfig(
ConfigOptions.loadProperties(configFile, "^" + namespace),
namespace,
configFile,
console);
}
示例20
/** Secondary no-arg constructor for direct-access testing */
public GeoServerConfig(final Console console) {
this(ConfigOptions.getDefaultPropertyFile(console), console);
}
示例21
private GeoServerRestClient(final GeoServerConfig config, final Console console) {
this.config = config;
this.console = console;
}
示例22
@Override
public void validatePluginOptions(final Console console) throws ParameterException {
// Set the directory to be absolute
dir = Paths.get(dir).toAbsolutePath().toString();
super.validatePluginOptions(console);
}
示例23
@Override
public void validatePluginOptions(final Console console) throws ParameterException {
// Set the directory to be absolute
dir = new File(dir).getAbsolutePath();
super.validatePluginOptions(console);
}
示例24
@Override
public Console getConsole() {
return new JCommander().getConsole();
}
示例25
public Console getConsole() {
return commander.getConsole();
}
示例26
/** Base constructor for encryption */
public BaseEncryption(Console console) {
init(console);
}
示例27
/** Base constructor for encryption */
public GeoWaveEncryption(Console console) {
super(console);
}
示例28
public static String getVersion(final Console console) {
return getBuildProperties(console).getProperty(VERSION_PROPERTY_KEY);
}
示例29
public static List<String> getVersionInfo(final Console console) {
final List<String> buildAndPropertyList =
Arrays.asList(getBuildProperties(console).toString().split(","));
Collections.sort(buildAndPropertyList.subList(1, buildAndPropertyList.size()));
return buildAndPropertyList;
}
示例30
public static void printVersionInfo(final Console console) {
final List<String> buildAndPropertyList = getVersionInfo(console);
for (final String str : buildAndPropertyList) {
console.println(str);
}
}