/** * Returns a shared access signature for the share. Note this does not contain the leading "?". * * @param policy * An {@link SharedAccessFilePolicy} object that represents the access policy for the * shared access signature. * @param groupPolicyIdentifier * A <code>String</code> which represents the share-level access policy. * * @return A <code>String</code> which represents a shared access signature for the share. * * @throws StorageException * If a storage service error occurred. * @throws InvalidKeyException * If the key is invalid. */ public String generateSharedAccessSignature(final SharedAccessFilePolicy policy, final String groupPolicyIdentifier) throws InvalidKeyException, StorageException { return this.generateSharedAccessSignature(policy, groupPolicyIdentifier, null /* IP range */, null /* protocols */); }
/** * Returns a shared access signature for the share. Note this does not contain the leading "?". * * @param policy * An {@link SharedAccessFilePolicy} object that represents the access policy for the * shared access signature. * @param groupPolicyIdentifier * A <code>String</code> which represents the share-level access policy. * * @return A <code>String</code> which represents a shared access signature for the share. * * @throws StorageException * If a storage service error occurred. * @throws InvalidKeyException * If the key is invalid. */ public String generateSharedAccessSignature(final SharedAccessFilePolicy policy, final String groupPolicyIdentifier) throws InvalidKeyException, StorageException { return this.generateSharedAccessSignature(policy, groupPolicyIdentifier, null /* IP range */, null /* protocols */); }
@Test @Category({ SlowTests.class }) public void testShareSASCombinations() throws StorageException, URISyntaxException, IOException, InvalidKeyException, InterruptedException { EnumSet<SharedAccessFilePermissions> permissionSet = null; Map<Integer, CloudFileShare> shares = new HashMap<Integer, CloudFileShare>(); try { for (int bits = 0x1; bits < 0x40; bits++) { shares.put(bits, FileTestHelper.getRandomShareReference()); shares.get(bits).createIfNotExists(); permissionSet = getPermissions(bits); FileSharePermissions perms = new FileSharePermissions(); perms.getSharedAccessPolicies().put("readwrite" + bits, createSharedAccessPolicy(permissionSet, 300)); shares.get(bits).uploadPermissions(perms); } Thread.sleep(30000); for (int bits = 0x1; bits < 0x20; bits++) { permissionSet = getPermissions(bits); String sasToken = shares.get(bits).generateSharedAccessSignature(null, "readwrite" + bits); CloudFile testFile = FileTestHelper.uploadNewFile(shares.get(bits), 64, null); testAccess(sasToken, permissionSet, shares.get(bits), testFile); } } finally { for (int bits = 0x1; bits < shares.size(); bits++) { shares.get(bits).deleteIfExists(); } } }
Thread.sleep(30000); String sasToken = this.share.generateSharedAccessSignature(policy, null); String sasToken2 = this.share.generateSharedAccessSignature(policy2, null); CloudFileShare sasShare = new CloudFileShare(PathUtility.addToQuery(this.share.getUri(), sasToken2));
Thread.sleep(30000); String shareReadListSas = this.share.generateSharedAccessSignature(policy2, null); CloudFileShare readListShare = new CloudFileShare(PathUtility.addToQuery(this.share.getUri(), shareReadListSas)); readListShare.getStorageUri(), this.share.generateSharedAccessSignature(null, "readlist"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), shareFromUri.getServiceClient().getCredentials().getClass().toString()); this.share.generateSharedAccessSignature(null, "readlist")); CloudFileClient client = new CloudFileClient(this.share.getServiceClient().getStorageUri(), creds);
@Test public void testDirectorySas() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dirFile"); CloudFile file = dir.getFileReference("dirFile"); dir.create(); file.create(512); SharedAccessFilePolicy policy = createSharedAccessPolicy( EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.LIST, SharedAccessFilePermissions.DELETE), 300); // Test directory SAS with a file SAS token from an identically named file String sas = file.generateSharedAccessSignature(policy, null); CloudFileDirectory sasDir = new CloudFileDirectory(new URI(dir.getUri().toString() + "?" + sas)); try { sasDir.downloadAttributes(); fail("This should result in an authentication error."); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_FORBIDDEN, ex.getHttpStatusCode()); } // Test directory SAS with a share SAS token sas = this.share.generateSharedAccessSignature(policy, null); sasDir = new CloudFileDirectory(new URI(dir.getUri().toString() + "?" + sas)); sasDir.downloadAttributes(); // Test deleting a directory using a SAS token. The directory must be empty for this request to succeed. file.delete(); sasDir.delete(); }
this.share.generateSharedAccessSignature(policy, null, null, SharedAccessProtocols.HTTPS_ONLY); String shareSasHttp = this.share.generateSharedAccessSignature(policy, null, null, SharedAccessProtocols.HTTPS_HTTP); final URI httpUri = new URI("http", this.share.getUri().getAuthority(), this.share.getUri().getPath(), this.share.getUri().getQuery(), null);
String shareSasNone = this.share.generateSharedAccessSignature(policy, null, range2, null); CloudFileShare noneShare = new CloudFileShare(PathUtility.addToQuery(this.share.getUri(), shareSasNone)); String shareSasOne = this.share.generateSharedAccessSignature(policy, null, sourceIP, null); CloudFileShare oneShare = new CloudFileShare(PathUtility.addToQuery(this.share.getUri(), shareSasOne)); String shareSasAll = this.share.generateSharedAccessSignature(policy, null, range1, null); CloudFileShare allShare = new CloudFileShare(PathUtility.addToQuery(this.share.getUri(), shareSasAll));