本文整理汇总了Java中org.jets3t.service.acl.AccessControlList类的典型用法代码示例。如果您正苦于以下问题:Java AccessControlList类的具体用法?Java AccessControlList怎么用?Java AccessControlList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessControlList类属于org.jets3t.service.acl包,在下文中一共展示了AccessControlList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
public void create(final Path bucket, final String location) throws BackgroundException {
// Create bucket
if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) {
throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3"));
}
AccessControlList acl;
if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) {
acl = GSAccessControlList.REST_CANNED_PUBLIC_READ;
}
else {
acl = GSAccessControlList.REST_CANNED_PRIVATE;
}
try {
session.getClient().createBucket(new S3PathContainerService().getContainer(bucket).getName(), location, acl);
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Cannot create folder {0}", e, bucket);
}
}
示例2: setConfiguration
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
@Override
public void setConfiguration(final Path container, final LoggingConfiguration configuration) throws BackgroundException {
try {
// Logging target bucket
final GSBucketLoggingStatus status = new GSBucketLoggingStatus(
StringUtils.isNotBlank(configuration.getLoggingTarget()) ? configuration.getLoggingTarget() : container.getName(), null);
if(configuration.isEnabled()) {
status.setLogfilePrefix(PreferencesFactory.get().getProperty("google.logging.prefix"));
}
// Grant write for Google to logging target bucket
final AccessControlList acl = session.getClient().getBucketAcl(container.getName());
final GroupByEmailAddressGrantee grantee = new GroupByEmailAddressGrantee(
"[email protected]");
if(!acl.getPermissionsForGrantee(grantee).contains(Permission.PERMISSION_WRITE)) {
acl.grantPermission(grantee, Permission.PERMISSION_WRITE);
session.getClient().putBucketAcl(container.getName(), acl);
}
session.getClient().setBucketLoggingStatusImpl(container.getName(), status);
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e);
}
}
示例3: updateBucketAccessControlList
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
/**
* Updates the ACL settings for the currently selected bucket.
*/
private void updateBucketAccessControlList() {
try {
AccessControlList bucketACL = s3ServiceMulti.getS3Service().getBucketAcl(currentSelectedBucket);
AccessControlList updatedBucketACL = AccessControlDialog.showDialog(
ownerFrame, new S3Bucket[] {currentSelectedBucket}, bucketACL, this);
if (updatedBucketACL != null) {
currentSelectedBucket.setAcl(updatedBucketACL);
s3ServiceMulti.getS3Service().putBucketAcl(currentSelectedBucket);
}
} catch (Exception e) {
String message = "Unable to update bucket's Access Control List";
log.error(message, e);
ErrorDialog.showDialog(ownerFrame, this, message, e);
}
}
示例4: deploy
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
public void deploy(File jarFile) {
String deployBucket = getOrCry("deployBucket");
String deployFilename = getOrCry("deployFilename");
try {
getStorage().getOrCreateBucket(deployBucket);
AccessControlList bucketAcl = getStorage().getBucketAcl(
deployBucket);
bucketAcl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
S3Object statFileObject = new S3Object(jarFile);
statFileObject.setKey(deployFilename);
statFileObject.setAcl(bucketAcl);
getStorage().putObject(deployBucket, statFileObject);
log.info("File " + jarFile + " now accessible at " + getJarUrl());
} catch (Exception e) {
log.warn("Failed to deploy or set permissions in bucket "
+ deployBucket + ", key " + deployFilename, e);
}
}
示例5: saveImage
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
private void saveImage(String filename, MultipartFile image)
throws ImageUploadException {
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3AccessKey, s3SecretKey);
S3Service s3 = new RestS3Service(awsCredentials);
S3Bucket imageBucket = s3.getBucket("spitterImages");
S3Object imageObject = new S3Object(filename);
imageObject.setDataInputStream(
new ByteArrayInputStream(image.getBytes()));
imageObject.setContentLength(image.getBytes().length);
imageObject.setContentType("image/jpeg");
AccessControlList acl = new AccessControlList();
acl.setOwner(imageBucket.getOwner());
acl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
imageObject.setAcl(acl);
s3.putObject(imageBucket, imageObject);
} catch (Exception e) {
throw new ImageUploadException("Unable to save image", e);
}
}
示例6: getObjectAclImpl
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
protected AccessControlList getObjectAclImpl(String bucketName, String objectKey)
throws ServiceException
{
if (log.isDebugEnabled()) {
log.debug("Retrieving Access Control List for bucketName="
+ bucketName + ", objectKey=" + objectKey);
}
Map<String, String> requestParameters = new HashMap<String, String>();
requestParameters.put("acl","");
HttpResponse httpResponse = performRestGet(bucketName, objectKey, requestParameters, null);
return getXmlResponseSaxParser()
.parseAccessControlListResponse(
new HttpMethodReleaseInputStream(httpResponse)).getAccessControlList();
}
示例7: putAclImpl
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
protected void putAclImpl(String bucketName, String objectKey, AccessControlList acl,
String versionId) throws ServiceException
{
if (log.isDebugEnabled()) {
log.debug("Setting Access Control List for bucketName=" + bucketName + ", objectKey=" + objectKey);
}
Map<String, String> requestParameters = new HashMap<String, String>();
requestParameters.put("acl","");
if (versionId != null) {
requestParameters.put("versionId", versionId);
}
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("Content-Type", "text/plain");
try {
String aclAsXml = acl.toXml();
metadata.put("Content-Length", String.valueOf(aclAsXml.length()));
performRestPut(bucketName, objectKey, metadata, requestParameters,
new StringEntity(aclAsXml, "text/plain", Constants.DEFAULT_ENCODING),
true);
} catch (UnsupportedEncodingException e) {
throw new ServiceException("Unable to encode ACL XML document", e);
}
}
示例8: prepareRESTHeaderAcl
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
/**
* Prepares the metadata with the given ACL
* an ACL is provided and can be represented with a HTTP header.
*
* @param metadata
* @param acl
* @return true if no acl or standard, false otherwise
* false if an ACL was provided but it could not be applied as a canned ACL.
*/
protected boolean prepareRESTHeaderAcl(Map<String, Object> metadata, AccessControlList acl)
{
if (metadata == null) {
throw new IllegalArgumentException("Null metadata not allowed.");
}
if (acl != null) {
String restHeaderAclValue = acl.getValueForRESTHeaderACL();
if (restHeaderAclValue != null) {
metadata.put(this.getRestHeaderPrefix() + "acl", restHeaderAclValue);
} else {
return false;
}
}
return true;
}
示例9: putObjectAclWithSignedUrl
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
/**
* Sets an object's ACL details using a pre-signed PUT URL generated for that object.
* This method is an implementation of the interface {@link org.jets3t.service.utils.signedurl.SignedUrlHandler}.
*
* @param signedAclUrl
* a signed URL generated with {@link org.jets3t.service.S3Service#createSignedUrl(String, String, String, String, java.util.Map, org.jets3t.service.security.ProviderCredentials, long, boolean)}.
* @param acl
* the ACL settings to apply to the object represented by the signed URL.
*
* @throws org.jets3t.service.ServiceException
*/
public void putObjectAclWithSignedUrl(String signedAclUrl, AccessControlList acl) throws ServiceException {
HttpPut putMethod = new HttpPut(signedAclUrl);
if (acl != null) {
String restHeaderAclValue = acl.getValueForRESTHeaderACL();
if (restHeaderAclValue != null) {
putMethod.addHeader(this.getRestHeaderPrefix() + "acl", restHeaderAclValue);
} else {
try {
String aclAsXml = acl.toXml();
putMethod.setEntity(new StringEntity(
aclAsXml, "text/xml", Constants.DEFAULT_ENCODING));
} catch (UnsupportedEncodingException e) {
throw new ServiceException("Unable to encode ACL XML document", e);
}
}
}
HttpResponse httpResponse = performRequest(putMethod, new int[] {200});
// Consume response data and release connection.
releaseConnection(httpResponse);
}
示例10: actionPerformed
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
/**
* Event handler for this dialog.
*/
public void actionPerformed(ActionEvent e) {
if ("OK".equals(e.getActionCommand())) {
copyActionApproved = true;
for (int i = 0; i < destinationObjects.length; i++) {
destinationObjects[i].setKey(
renameObjectKey(destinationObjects[i].getKey(), i));
if ("Publically Accessible".equals(destinationAclComboBox.getSelectedItem())) {
destinationObjects[i].setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
} else if ("Unchanged".equals(destinationAclComboBox.getSelectedItem())) {
copyOriginalAccessControlLists = true;
}
// Apply storage class
destinationObjects[i].setStorageClass(
(String) destinationStorageClassComboBox.getSelectedItem());
}
this.setVisible(false);
} else if ("Cancel".equals(e.getActionCommand())) {
copyActionApproved = false;
this.setVisible(false);
}
}
示例11: getAclDescription
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
public static String getAclDescription(AccessControlList acl) {
if (acl == null) {
return ACL_UNKNOWN_DESCRIPTION;
}
for (GrantAndPermission gap: acl.getGrantAndPermissions()) {
if (GroupGrantee.ALL_USERS.equals(gap.getGrantee())
&& Permission.PERMISSION_READ.equals(gap.getPermission()))
{
return ACL_PUBLIC_DESCRIPTION;
}
}
if (AccessControlList.REST_CANNED_PUBLIC_READ.equals(acl)) {
return ACL_PUBLIC_DESCRIPTION;
}
return ACL_PRIVATE_DESCRIPTION;
}
示例12: prepareUploadObject
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
public StorageObject prepareUploadObject() throws Exception {
StorageObject newObject = ObjectUtils
.createObjectForUpload(targetKey, file, encryptionUtil, isGzipEnabled, null);
if ("PUBLIC_READ".equalsIgnoreCase(aclString)) {
newObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
} else if ("PUBLIC_READ_WRITE".equalsIgnoreCase(aclString)) {
newObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ_WRITE);
} else if ("PRIVATE".equalsIgnoreCase(aclString)) {
// Private is the default, no need to add an ACL
} else {
throw new Exception("Invalid value for ACL string: " + aclString);
}
// Apply custom metadata items to upload object.
newObject.addAllMetadata(customMetadata);
return newObject;
}
示例13: uploadToBucket
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
public String uploadToBucket(String bucketname,
DataInputStream dataInputStream, String fx) throws ServiceException {
StorageObject[] sob = { new StorageObject() };
sob[0].setDataInputStream(dataInputStream);
sob[0].setName(fx);
S3Bucket privateBket = s3service.getBucket(bucketname);
AccessControlList bucketAcl = s3service.getBucketAcl(privateBket);
sob[0].setAcl(bucketAcl);
if (this.storageService.putObjects(bucketname, sob)) {
StorageObject objectDetailsOnly = s3service.getObjectDetails(
bucketname, fx);
Logger.log("S3FS.uploadToBucket success: "
+ objectDetailsOnly.getName());
return objectDetailsOnly.getName();
}
Logger.error("S3FS.uploadToBucket: " + bucketname + " failed.");
return null;
}
示例14: grantAcl
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
public boolean grantAcl(S3Object object) throws ServiceException, InterruptedException {
if(Strings.isNullOrEmpty(s3Acl)){
return true;
}
for (int i = 0; i < s3AclRetries; ++i) {
try {
AccessControlList acl = s3Service.getObjectAcl(object.getBucketName(), object.getKey());
for (String id : s3Acl.split(",")) {
acl.grantPermission(new CanonicalGrantee(id), Permission.PERMISSION_READ);
}
s3Service.putObjectAcl(object.getBucketName(), object.getKey(), acl);
return true;
} catch (Exception e) {
log.error("Exception while granting ACL: " + e.getMessage(), e);
Thread.sleep(1000 * (i + 1));
}
}
return false;
}
示例15: test
import org.jets3t.service.acl.AccessControlList; //导入依赖的package包/类
@Test
public void test() throws Exception {
RestS3Service s3Service = mock(RestS3Service.class);
AccessControlList acl = new AccessControlList();
doReturn(acl).when(s3Service).getObjectAcl("bucket", "key");
doNothing().when(s3Service).putObjectAcl("bucket", "key", acl);
GrantAcl grantAcl = new GrantAcl(s3Service, "1,2,3", 1);
S3Object obj = new S3Object("key");
obj.setBucketName("bucket");
obj.setAcl(GSAccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL);
assertTrue(grantAcl.grantAcl(obj));
Set<GrantAndPermission> grants = new HashSet<GrantAndPermission>(Arrays.asList(acl.getGrantAndPermissions()));
assertEquals(grants.size(), 3);
Set<GrantAndPermission> grantSet = new HashSet<GrantAndPermission>();
for (int i = 1; i <= 3; ++i) {
grantSet.add(new GrantAndPermission(new CanonicalGrantee(Integer.toString(i)), Permission.PERMISSION_READ));
}
}