com.microsoft.azure.storage.blob.SharedAccessBlobPermissions Java Examples
The following examples show how to use
com.microsoft.azure.storage.blob.SharedAccessBlobPermissions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 4 votes |
@Override public URI createPlaybackUri(URI storagePath, Date ts) throws Exception { long startTime = System.nanoTime(); try { String accountName = getAccountName(storagePath); CloudBlobClient client = accounts.get(accountName); if (client == null) { VIDEO_STORAGE_AZURE_BAD_ACCOUNT_NAME.inc(); throw new Exception("unknown account name: " + accountName); } CloudBlockBlob blob = new CloudBlockBlob(storagePath, client); SharedAccessBlobHeaders headers = new SharedAccessBlobHeaders(); headers.setContentType("video/mp2t"); headers.setCacheControl("no-cache"); Date start = new Date(ts.getTime() - accessDurationInMs); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy(); policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ)); policy.setSharedAccessStartTime(start); policy.setSharedAccessExpiryTime(ts); String sig = blob.generateSharedAccessSignature(policy, headers, null); String query = storagePath.getQuery(); URI result; if (query != null && !query.isEmpty()) { result = URI.create(storagePath + "&" + sig); } else { result = URI.create(storagePath + "?" + sig); } VIDEO_STORAGE_AZURE_CREATE_PLAYBACK_URI_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); return result; } catch (Exception ex) { VIDEO_STORAGE_AZURE_CREATE_PLAYBACK_URI_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); throw ex; } }
Example #2
Source File: AzureUrlProvider.java From cyberduck with GNU General Public License v3.0 | 4 votes |
private SharedAccessBlobPolicy getPolicy(final int expiry) { final SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy(); policy.setSharedAccessExpiryTime(new Date(this.getExpiry(expiry))); policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ)); return policy; }
Example #3
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
private static String generateSAS(CloudBlobContainer container, boolean readonly) throws Exception { // Create a container if it does not exist. container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Create a UTC Gregorian calendar value. GregorianCalendar calendar = new GregorianCalendar( TimeZone.getTimeZone("UTC")); // Specify the current time as the start time for the shared access // signature. // calendar.setTime(new Date()); sasPolicy.setSharedAccessStartTime(calendar.getTime()); // Use the start time delta one hour as the end time for the shared // access signature. calendar.add(Calendar.HOUR, 10); sasPolicy.setSharedAccessExpiryTime(calendar.getTime()); if (readonly) { // Set READ permissions sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST)); } else { // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST)); } // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF); container.uploadPermissions(containerPermissions); // Create a shared access signature for the container. String sas = container.generateSharedAccessSignature(sasPolicy, null); // HACK: when the just generated SAS is used straight away, we get an // authorization error intermittently. Sleeping for 1.5 seconds fixes that // on my box. Thread.sleep(1500); // Return to caller with the shared access signature. return sas; }
Example #4
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
public static void primePublicContainer(CloudBlobClient blobClient, String accountName, String containerName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient .getContainerReference(containerName); container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions .setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the policy using the values set above. containerPermissions.getSharedAccessPolicies().put("testwasbpolicy", sasPolicy); container.uploadPermissions(containerPermissions); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); }
Example #5
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 4 votes |
private static String generateSAS(CloudBlobContainer container, boolean readonly) throws Exception { // Create a container if it does not exist. container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Create a UTC Gregorian calendar value. GregorianCalendar calendar = new GregorianCalendar( TimeZone.getTimeZone("UTC")); // Specify the current time as the start time for the shared access // signature. // calendar.setTime(new Date()); sasPolicy.setSharedAccessStartTime(calendar.getTime()); // Use the start time delta one hour as the end time for the shared // access signature. calendar.add(Calendar.HOUR, 10); sasPolicy.setSharedAccessExpiryTime(calendar.getTime()); if (readonly) { // Set READ permissions sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST)); } else { // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST)); } // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF); container.uploadPermissions(containerPermissions); // Create a shared access signature for the container. String sas = container.generateSharedAccessSignature(sasPolicy, null); // HACK: when the just generated SAS is used straight away, we get an // authorization error intermittently. Sleeping for 1.5 seconds fixes that // on my box. Thread.sleep(1500); // Return to caller with the shared access signature. return sas; }
Example #6
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 4 votes |
public static void primePublicContainer(CloudBlobClient blobClient, String accountName, String containerName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient .getContainerReference(containerName); container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions .setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the policy using the values set above. containerPermissions.getSharedAccessPolicies().put("testwasbpolicy", sasPolicy); container.uploadPermissions(containerPermissions); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); }
Example #7
Source File: CloudFileTests.java From azure-storage-android with Apache License 2.0 | 4 votes |
private CloudFile doCloudBlobCopy(CloudBlob source, int length) throws Exception { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTime(new Date()); cal.add(Calendar.MINUTE, 5); // Source SAS must have read permissions SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy(); policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ)); policy.setSharedAccessExpiryTime(cal.getTime()); String sasToken = source.generateSharedAccessSignature(policy, null, null); // Get destination reference final CloudFile destination = this.share.getRootDirectoryReference().getFileReference("destination"); // Start copy and wait for completion StorageCredentialsSharedAccessSignature credentials = new StorageCredentialsSharedAccessSignature(sasToken); Constructor<? extends CloudBlob> blobType = source.getClass().getConstructor(URI.class); String copyId = destination.startCopy(blobType.newInstance(credentials.transformUri(source.getUri()))); FileTestHelper.waitForCopy(destination); destination.downloadAttributes(); // Check original file references for equality assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus()); assertEquals(source.getServiceClient().getCredentials().transformUri(source.getUri()).getPath(), destination.getCopyState().getSource().getPath()); assertEquals(length, destination.getCopyState().getTotalBytes().intValue()); assertEquals(length, destination.getCopyState().getBytesCopied().intValue()); assertEquals(copyId, destination.getProperties().getCopyState().getCopyId()); // Attempt to abort the completed copy operation. try { destination.abortCopy(destination.getCopyState().getCopyId()); FileTestHelper.waitForCopy(destination); fail(); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_CONFLICT, ex.getHttpStatusCode()); } assertNotNull(destination.getProperties().getEtag()); assertFalse(source.getProperties().getEtag().equals(destination.getProperties().getEtag())); source.downloadAttributes(); FileProperties prop1 = destination.getProperties(); BlobProperties prop2 = source.getProperties(); assertEquals(prop1.getCacheControl(), prop2.getCacheControl()); assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding()); assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage()); assertEquals(prop1.getContentMD5(), prop2.getContentMD5()); assertEquals(prop1.getContentType(), prop2.getContentType()); assertEquals("value", destination.getMetadata().get("Test")); return destination; }