- Add the Codota plugin to your IDE and get smart completions
private void myMethod () {LocalDateTime l =
new LocalDateTime()
LocalDateTime.now()
DateTimeFormatter formatter;String text;formatter.parseLocalDateTime(text)
- Smart code suggestions by Codota
}
@JsonCreator public AzureTableConfiguration(@JsonProperty("accountName") String accountName, @JsonProperty("accountKey") String accountKey, @JsonProperty("timeout")Duration timeout, @JsonProperty("retryInterval") Duration retryInterval, @JsonProperty("retryAttempts") int retryAttempts) { this.retryInterval = checkNotNull(retryInterval, "retryInterval cannot be null"); this.retryAttempts = retryAttempts; this.timeout = checkNotNull(timeout, "timeout cannot be null"); this.storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey( checkNotNull(accountName, "accountName cannot be null"), checkNotNull(accountKey, "accountKey cannot be null")); }
/** * Sets the name of the access key to be used when signing the request. * * @param key * A <code>String</code> that represents the name of the access key to be used when signing the request. */ public synchronized void updateKey(final String key) { this.updateKey(Base64.decode(key)); }
/** * Returns a <code>String</code> that represents this instance, optionally including sensitive data. * * @param exportSecrets * <code>true</code> to include sensitive data in the return string; otherwise, <code>false</code>. * * @return A <code>String</code> that represents this object, optionally including sensitive data. */ @Override public String toString(final boolean exportSecrets) { return String.format("%s=%s;%s=%s", CloudStorageAccount.ACCOUNT_NAME_NAME, this.getAccountName(), CloudStorageAccount.ACCOUNT_KEY_NAME, exportSecrets ? this.exportBase64EncodedKey() : "[key hidden]"); }
@Test public void testStorageCredentialsSharedKeyUpdateKey() throws URISyntaxException, StorageException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); assertEquals(ACCOUNT_KEY, cred.exportBase64EncodedKey()); // Validate update with byte array byte[] dummyKey = { 0, 1, 2 }; cred.updateKey(dummyKey); String base64EncodedDummyKey = Base64.encode(dummyKey); assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey()); // Validate update with string dummyKey[0] = 3; base64EncodedDummyKey = Base64.encode(dummyKey); cred.updateKey(base64EncodedDummyKey); assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey()); }
@Test public void testStorageCredentialsSharedKey() throws URISyntaxException, StorageException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); assertEquals(ACCOUNT_NAME, cred.getAccountName()); URI testUri = new URI("http://test/abc?querya=1"); assertEquals(testUri, cred.transformUri(testUri)); assertEquals(ACCOUNT_KEY, cred.exportBase64EncodedKey()); byte[] dummyKey = { 0, 1, 2 }; String base64EncodedDummyKey = Base64.encode(dummyKey); cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, base64EncodedDummyKey); assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey()); dummyKey[0] = 3; base64EncodedDummyKey = Base64.encode(dummyKey); cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, base64EncodedDummyKey); assertEquals(base64EncodedDummyKey, cred.exportBase64EncodedKey()); }
@Test public void testStorageCredentialsNullKeyValue() { String nullKeyValueAsString = null; try { new StorageCredentialsAccountAndKey(ACCOUNT_NAME, nullKeyValueAsString); fail("Did not hit expected exception"); } catch (IllegalArgumentException ex) { assertEquals(SR.STRING_NOT_VALID, ex.getMessage()); } StorageCredentialsAccountAndKey credentials2 = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); assertEquals(ACCOUNT_NAME, credentials2.getAccountName()); assertEquals(ACCOUNT_KEY, Base64.encode(credentials2.exportKey())); byte[] nullKeyValueAsByteArray = null; try { new StorageCredentialsAccountAndKey(ACCOUNT_NAME, nullKeyValueAsByteArray); fail("Did not hit expected exception"); } catch (IllegalArgumentException ex) { assertEquals(SR.INVALID_KEY, ex.getMessage()); } }
@Test public void testCloudStorageAccountExportKey() throws InvalidKeyException, URISyntaxException { String accountKeyString = "abc2564="; String accountString = "BlobEndpoint=http://blobs/;AccountName=test;AccountKey=" + accountKeyString; CloudStorageAccount account = CloudStorageAccount.parse(accountString); StorageCredentialsAccountAndKey accountAndKey = (StorageCredentialsAccountAndKey) account.getCredentials(); String key = accountAndKey.exportBase64EncodedKey(); assertEquals(accountKeyString, key); byte[] keyBytes = accountAndKey.exportKey(); byte[] expectedKeyBytes = Base64.decode(accountKeyString); TestHelper.assertByteArrayEquals(expectedKeyBytes, keyBytes); } }
/** * Computes a signature for the specified string using the HMAC-SHA256 algorithm. * * @param value * The UTF-8-encoded string to sign. * * @return A <code>String</code> that contains the HMAC-SHA256-encoded signature. * * @throws InvalidKeyException * If the key is not a valid Base64-encoded string. */ public static synchronized String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException { if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) { byte[] utf8Bytes = null; try { utf8Bytes = value.getBytes(Constants.UTF8_CHARSET); } catch (final UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } return Base64.encode(((StorageCredentialsAccountAndKey) creds).getHmac256().doFinal(utf8Bytes)); } else { return null; } }
/** * Computes a signature for the specified string using the HMAC-SHA256 algorithm. * * @param value * The UTF-8-encoded string to sign. * * @return A <code>String</code> that contains the HMAC-SHA256-encoded signature. * * @throws InvalidKeyException * If the key is not a valid Base64-encoded string. */ public static synchronized String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException { if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) { byte[] utf8Bytes = null; try { utf8Bytes = value.getBytes(Constants.UTF8_CHARSET); } catch (final UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } return Base64.encode(((StorageCredentialsAccountAndKey) creds).getHmac256().doFinal(utf8Bytes)); } else { return null; } }
/** * Connect to Azure storage using account key credentials. */ private void connectUsingConnectionStringCredentials( final String accountName, final String containerName, final String accountKey) throws InvalidKeyException, StorageException, IOException, URISyntaxException { // If the account name is "acc.blob.core.windows.net", then the // rawAccountName is just "acc" String rawAccountName = accountName.split("\\.")[0]; StorageCredentials credentials = new StorageCredentialsAccountAndKey( rawAccountName, accountKey); connectUsingCredentials(accountName, credentials, containerName); }
/** * Returns a <code>String</code> that represents this instance, optionally including sensitive data. * * @param exportSecrets * <code>true</code> to include sensitive data in the return string; otherwise, <code>false</code>. * * @return A <code>String</code> that represents this object, optionally including sensitive data. */ @Override public String toString(final boolean exportSecrets) { return String.format("%s=%s;%s=%s", CloudStorageAccount.ACCOUNT_NAME_NAME, this.getAccountName(), CloudStorageAccount.ACCOUNT_KEY_NAME, exportSecrets ? this.exportBase64EncodedKey() : "[key hidden]"); }
/** * Sets the name of the access key to be used when signing the request. * * @param key * A <code>String</code> that represents the name of the access key to be used when signing the request. */ public synchronized void updateKey(final String key) { this.updateKey(Base64.decode(key)); }
/** * Helper method that creates CloudStorageAccount Instance using the * storage account key. * @param accountName Name of the storage account * @param accountKey Storage Account key * @return CloudStorageAccount instance for the storage account. * @throws SASKeyGenerationException */ private CloudStorageAccount getStorageAccountInstance(String accountName, String accountKey) throws SASKeyGenerationException { if (!storageAccountMap.containsKey(accountName)) { CloudStorageAccount account = null; try { account = new CloudStorageAccount(new StorageCredentialsAccountAndKey( accountName, accountKey)); } catch (URISyntaxException uriSyntaxEx) { throw new SASKeyGenerationException("Encountered URISyntaxException " + "for account " + accountName, uriSyntaxEx); } storageAccountMap.put(accountName, account); } return storageAccountMap.get(accountName); }
@Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final StorageCredentials credentials = client.getCredentials(); if(host.getCredentials().isPasswordAuthentication()) { // Update credentials ((StorageCredentialsAccountAndKey) credentials).updateKey(host.getCredentials().getPassword()); } else if(host.getCredentials().isTokenAuthentication()) { if(!StringUtils.equals(host.getCredentials().getToken(), ((StorageCredentialsSharedAccessSignature) credentials).getToken())) { this.interrupt(); this.open(proxy, new DisabledHostKeyCallback(), prompt); } } // Fetch reference for directory to check login credentials try { this.getFeature(ListService.class).list(new AzureHomeFinderService(this).find(), new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { throw new ListCanceledException(list); } }); } catch(ListCanceledException e) { // Success } }
public static CloudBlobDirectory createCloudBlobDirectory(String path) { Map<String, String> config = parseAzureConfigurationFromUri(path); String accountName = config.get(KEY_ACCOUNT_NAME); String key = System.getenv("AZURE_SECRET_KEY"); StorageCredentials credentials = null; try { credentials = new StorageCredentialsAccountAndKey(accountName, key); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Could not connect to the Azure Storage. Please verify if AZURE_SECRET_KEY environment variable " + "is correctly set!"); } String uri = config.get(KEY_STORAGE_URI); String dir = config.get(KEY_DIR); try { return AzureUtilities.cloudBlobDirectoryFrom(credentials, uri, dir); } catch (URISyntaxException | StorageException e) { throw new IllegalArgumentException( "Could not connect to the Azure Storage. Please verify the path provided!"); } }
public static CloudBlobDirectory createCloudBlobDirectory(String path) { Map<String, String> config = parseAzureConfigurationFromUri(path); String accountName = config.get(KEY_ACCOUNT_NAME); String key = System.getenv("AZURE_SECRET_KEY"); StorageCredentials credentials = null; try { credentials = new StorageCredentialsAccountAndKey(accountName, key); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Could not connect to the Azure Storage. Please verify if AZURE_SECRET_KEY environment variable " + "is correctly set!"); } String uri = config.get(KEY_STORAGE_URI); String dir = config.get(KEY_DIR); try { return AzureUtilities.cloudBlobDirectoryFrom(credentials, uri, dir); } catch (URISyntaxException | StorageException e) { throw new IllegalArgumentException( "Could not connect to the Azure Storage. Please verify the path provided!"); } }
private AzurePersistence createAzurePersistence() throws StorageException, URISyntaxException, InvalidKeyException { CloudBlobDirectory cloudBlobDirectory = null; if (accountName != null && uri != null) { String key = System.getenv("AZURE_SECRET_KEY"); StorageCredentials credentials = new StorageCredentialsAccountAndKey(accountName, key); cloudBlobDirectory = AzureUtilities.cloudBlobDirectoryFrom(credentials, uri, dir); } else if (connectionString != null && containerName != null) { cloudBlobDirectory = AzureUtilities.cloudBlobDirectoryFrom(connectionString, containerName, dir); } if (cloudBlobDirectory == null) { throw new IllegalArgumentException("Could not connect to Azure storage. Too few connection parameters specified!"); } return new AzurePersistence(cloudBlobDirectory); }
private AzurePersistence createAzurePersistence() throws StorageException, URISyntaxException, InvalidKeyException { CloudBlobDirectory cloudBlobDirectory = null; if (accountName != null && uri != null) { String key = System.getenv("AZURE_SECRET_KEY"); StorageCredentials credentials = new StorageCredentialsAccountAndKey(accountName, key); cloudBlobDirectory = AzureUtilities.cloudBlobDirectoryFrom(credentials, uri, dir); } else if (connectionString != null && containerName != null) { cloudBlobDirectory = AzureUtilities.cloudBlobDirectoryFrom(connectionString, containerName, dir); } if (cloudBlobDirectory == null) { throw new IllegalArgumentException("Could not connect to Azure storage. Too few connection parameters specified!"); } return new AzurePersistence(cloudBlobDirectory); }
return new StorageCredentialsAccountAndKey(accountName, accountKey);
String accountKey = Utils.returnInputkey(inputCreds, accountName); System.out.println(“This mapper is assigned the following account:”+accountName); StorageCredentials creds = new StorageCredentialsAccountAndKey(accountName,accountKey); CloudStorageAccount account = new CloudStorageAccount(creds); CloudBlobClient client = account.createCloudBlobClient();