Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.ozone.s3.endpoint;

import java.io.IOException;
import java.io.InputStream;
import javax.ws.rs.core.Response;
import org.apache.hadoop.ozone.s3.endpoint.ObjectEndpoint.ObjectRequestContext;
import org.apache.hadoop.ozone.s3.exception.OS3Exception;

/** Performs audit logging for {@link ObjectOperationHandler}s. */
class AuditingObjectOperationHandler extends ObjectOperationHandler {

private final ObjectOperationHandler delegate;

AuditingObjectOperationHandler(ObjectOperationHandler delegate) {
this.delegate = delegate;
copyDependenciesFrom(delegate);
}

@Override
Response handleDeleteRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception {
try {
verifyBucketOwner(context);
Response response = delegate.handleDeleteRequest(context, keyName);
auditWriteSuccess(context.getAction());
return response;
} catch (Exception e) {
auditWriteFailure(context.getAction(), e);
throw e;
}
}

@Override
Response handleGetRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception {
try {
verifyBucketOwner(context);
Response response = delegate.handleGetRequest(context, keyName);
auditReadSuccess(context.getAction(), context.getPerf());
return response;
} catch (Exception e) {
auditReadFailure(context.getAction(), e);
throw e;
}
}

@Override
Response handleHeadRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception {
try {
verifyBucketOwner(context);
Response response = delegate.handleHeadRequest(context, keyName);
auditReadSuccess(context.getAction());
return response;
} catch (Exception e) {
auditReadFailure(context.getAction(), e);
throw e;
}
}

@Override
Response handlePutRequest(ObjectRequestContext context, String keyName, InputStream body)
throws IOException, OS3Exception {
try {
verifyBucketOwner(context);
Response response = delegate.handlePutRequest(context, keyName, body);
auditWriteSuccess(context.getAction(), context.getPerf());
return response;
} catch (Exception e) {
auditWriteFailure(context.getAction(), e);
throw e;
}
}

private void verifyBucketOwner(ObjectRequestContext context) throws IOException {
if (S3Owner.hasBucketOwnershipVerificationConditions(getHeaders())) {
S3Owner.verifyBucketOwnerCondition(getHeaders(), context.getBucketName(), context.getBucket().getOwner());
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use chain as its name is better? just suggestion

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.ozone.s3.endpoint;

import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.hadoop.ozone.s3.endpoint.ObjectEndpoint.ObjectRequestContext;
import org.apache.hadoop.ozone.s3.exception.OS3Exception;

/** Chain of responsibility for {@link ObjectOperationHandler}s. */
final class CompositeObjectOperationHandler extends ObjectOperationHandler {

private final List<ObjectOperationHandler> handlers;

private CompositeObjectOperationHandler(List<ObjectOperationHandler> handlers) {
this.handlers = handlers;
}

@Override
Response handleDeleteRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception {
for (ObjectOperationHandler handler : handlers) {
Response response = handler.handleDeleteRequest(context, keyName);
if (response != null) {
return response;
}
}
return null;
}

@Override
Response handleGetRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception {
for (ObjectOperationHandler handler : handlers) {
Response response = handler.handleGetRequest(context, keyName);
if (response != null) {
return response;
}
}
return null;
}

@Override
Response handleHeadRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception {
for (ObjectOperationHandler handler : handlers) {
Response response = handler.handleHeadRequest(context, keyName);
if (response != null) {
return response;
}
}
return null;
}

@Override
Response handlePutRequest(ObjectRequestContext context, String keyName, InputStream body)
throws IOException, OS3Exception {
for (ObjectOperationHandler handler : handlers) {
Response response = handler.handlePutRequest(context, keyName, body);
if (response != null) {
return response;
}
}
return null;
}

static Builder newBuilder(ObjectEndpoint endpoint) {
return new Builder(endpoint);
}

/** Builds {@code CompositeObjectOperationHandler}. */
static final class Builder {
private final List<ObjectOperationHandler> handlers = new LinkedList<>();
private final ObjectEndpoint endpoint;

private Builder(ObjectEndpoint endpoint) {
this.endpoint = endpoint;
}

/** Append {@code handler} to the list of delegates. */
Builder add(ObjectOperationHandler handler) {
handlers.add(handler.copyDependenciesFrom(endpoint));
return this;
}

/** Create {@code CompositeObjectOperationHandler} with the list of delegates. */
ObjectOperationHandler build() {
return new CompositeObjectOperationHandler(handlers)
.copyDependenciesFrom(endpoint);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ void setOzoneConfiguration(OzoneConfiguration conf) {
* Used for initializing handler instances.
*/
protected void copyDependenciesTo(EndpointBase target) {
if (this == target) {
return;
}
target.queryParams = queryParams;
target.s3Auth = s3Auth;
target.setClient(this.client);
Expand Down Expand Up @@ -820,11 +823,11 @@ public int getChunkSize() {
return chunkSize;
}

public MessageDigest getMD5DigestInstance() {
public static MessageDigest getMD5DigestInstance() {
return MD5_PROVIDER.get();
}

public MessageDigest getSha256DigestInstance() {
public static MessageDigest getSha256DigestInstance() {
return SHA_256_PROVIDER.get();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.ozone.s3.endpoint;

import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.NOT_IMPLEMENTED;
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;

import java.io.IOException;
import java.io.InputStream;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
import org.apache.hadoop.ozone.audit.S3GAction;
import org.apache.hadoop.ozone.s3.endpoint.ObjectEndpoint.ObjectRequestContext;
import org.apache.hadoop.ozone.s3.util.S3Consts;

/** Not implemented yet. */
class ObjectAclHandler extends ObjectOperationHandler {

@Override
Response handlePutRequest(ObjectRequestContext context, String keyName, InputStream body) throws IOException {
if (context.ignore(getAction())) {
return null;
}

try {
throw newError(NOT_IMPLEMENTED, keyName);
} catch (Exception e) {
getMetrics().updatePutObjectAclFailureStats(context.getStartNanos());
throw e;
}
}

@SuppressWarnings("SwitchStatementWithTooFewBranches")
S3GAction getAction() {
if (queryParams().get(S3Consts.QueryParams.ACL) == null) {
return null;
}

switch (getContext().getMethod()) {
case HttpMethod.PUT:
return S3GAction.PUT_OBJECT_ACL;
default:
return null;
}
}
}
Loading