

 AWS SDK for Java 1.x는 2025년 12월 31일에 end-of-support되었습니다. 새로운 기능, 가용성 개선 및 보안 업데이트를 계속 받으려면 [AWS SDK for Java 2.x](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html)로 마이그레이션하는 것이 좋습니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 액세스 제어 정책
<a name="java-dg-access-control"></a>

 AWS *액세스 제어 정책을* 사용하면 AWS 리소스에 대한 세분화된 액세스 제어를 지정할 수 있습니다. 액세스 제어 정책은 다음과 같은 형태의 *문* 모음으로 이루어집니다.

 *계정 A*에는 *조건 D*가 적용되는 *리소스 C*에서 *작업 B*를 수행할 권한이 있습니다.

위치:
+  **는 보안 *주체* - AWS 리소스 중 하나에 액세스하거나 리소스 중 하나를 수정하도록 요청하는 AWS 계정 입니다.
+  *B*는 *작업* - Amazon SQS 대기열에 메시지를 보내거나 Amazon S3 버킷에 객체를 저장하는 등 AWS 리소스에 액세스하거나 수정하는 방식입니다.
+  *C*는 *리소스* - Amazon SQS 대기열 또는 저장된 객체와 같이 보안 주체가 액세스하려는 AWS 엔터티입니다 Amazon S3.
+  *D*는 *조건 집합*, 즉 주체가 리소스에 액세스할 수 있도록 허용하거나 거부할 시기를 지정하는 선택적 제약 조건입니다. 여러 표현식 조건을 사용할 수 있는 일부 각 서비스에 국한됩니다. 예를 들면, 날짜 조건을 사용하여 특정 시간 이후 또는 이전에만 리소스에 대한 액세스를 허용할 수 있습니다.

## Amazon S3 예제
<a name="s3-example"></a>

다음 예제는 누구나 버킷의 모든 객체를 읽을 수 있도록 허용하지만 해당 버킷에 객체를 업로드할 수 있는 액세스를 (버킷 소유자의 계정 외에도) 두 개의 특정 AWS 계정로 제한하는 정책을 보여줍니다.

```
Statement allowPublicReadStatement = new Statement(Effect.Allow)
    .withPrincipals(Principal.AllUsers)
    .withActions(S3Actions.GetObject)
    .withResources(new S3ObjectResource(myBucketName, "*"));
Statement allowRestrictedWriteStatement = new Statement(Effect.Allow)
    .withPrincipals(new Principal("123456789"), new Principal("876543210"))
    .withActions(S3Actions.PutObject)
    .withResources(new S3ObjectResource(myBucketName, "*"));

Policy policy = new Policy()
    .withStatements(allowPublicReadStatement, allowRestrictedWriteStatement);

AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
s3.setBucketPolicy(myBucketName, policy.toJson());
```

## Amazon SQS 예제
<a name="sqs-example"></a>

정책의 일반적인 사용 중 하나는 Amazon SQS 대기열이 Amazon SNS 주제에서 메시지를 수신하도록 권한을 부여하는 것입니다.

```
Policy policy = new Policy().withStatements(
    new Statement(Effect.Allow)
        .withPrincipals(Principal.AllUsers)
        .withActions(SQSActions.SendMessage)
        .withConditions(ConditionFactory.newSourceArnCondition(myTopicArn)));

Map queueAttributes = new HashMap();
queueAttributes.put(QueueAttributeName.Policy.toString(), policy.toJson());

AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
sqs.setQueueAttributes(new SetQueueAttributesRequest(myQueueUrl, queueAttributes));
```

## Amazon SNS 예제
<a name="sns-example"></a>

일부 서비스는 정책에 사용할 수 있는 추가 조건을 제공합니다. Amazon SNS는 주제 구독 요청의 프로토콜(예: 이메일, HTTP, HTTPS Amazon SQS) 및 엔드포인트(예: 이메일 주소, URL, Amazon SQS ARN)를 기반으로 SNS 주제에 대한 구독을 허용하거나 거부하는 조건을 제공합니다.

```
Condition endpointCondition =
    SNSConditionFactory.newEndpointCondition("*@mycompany.com");

Policy policy = new Policy().withStatements(
    new Statement(Effect.Allow)
        .withPrincipals(Principal.AllUsers)
        .withActions(SNSActions.Subscribe)
        .withConditions(endpointCondition));

AmazonSNS sns = AmazonSNSClientBuilder.defaultClient();
sns.setTopicAttributes(
    new SetTopicAttributesRequest(myTopicArn, "Policy", policy.toJson()));
```