This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new b8a2ef3309a HDDS-16403. Replace deprecated
java.security.AccessControlException in HttpFSServer (#11231)
b8a2ef3309a is described below
commit b8a2ef3309ab8128c7f9cf170d9279625a3d4faf
Author: sravani <[email protected]>
AuthorDate: Tue Sep 15 13:48:05 2026 +0530
HDDS-16403. Replace deprecated java.security.AccessControlException in
HttpFSServer (#11231)
---
.../fs/http/server/HttpFSExceptionProvider.java | 5 +-
.../apache/ozone/fs/http/server/HttpFSServer.java | 2 +-
.../http/server/TestHttpFSExceptionProvider.java | 59 ++++++++++++++++++++++
3 files changed, 64 insertions(+), 2 deletions(-)
diff --git
a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSExceptionProvider.java
b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSExceptionProvider.java
index 05608f77266..bbaed1d16f5 100644
---
a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSExceptionProvider.java
+++
b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSExceptionProvider.java
@@ -23,6 +23,7 @@
import javax.ws.rs.ext.Provider;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.scm.container.ContainerException;
+import org.apache.hadoop.security.AccessControlException;
import org.apache.ozone.lib.service.FileSystemAccessException;
import org.apache.ozone.lib.wsrs.ExceptionProvider;
import org.slf4j.Logger;
@@ -45,6 +46,7 @@ public class HttpFSExceptionProvider extends
ExceptionProvider {
* Maps different exceptions thrown by HttpFSServer to HTTP status codes.
* <ul>
* <li>SecurityException : HTTP UNAUTHORIZED</li>
+ * <li>AccessControlException : HTTP UNAUTHORIZED</li>
* <li>FileNotFoundException : HTTP NOT_FOUND</li>
* <li>IOException : INTERNAL_HTTP SERVER_ERROR</li>
* <li>UnsupporteOperationException : HTTP BAD_REQUEST</li>
@@ -64,7 +66,8 @@ public Response toResponse(Throwable throwable) {
if (throwable instanceof ContainerException) {
throwable = throwable.getCause();
}
- if (throwable instanceof SecurityException) {
+ if (throwable instanceof SecurityException
+ || throwable instanceof AccessControlException) {
status = Response.Status.UNAUTHORIZED;
} else if (throwable instanceof FileNotFoundException) {
status = Response.Status.NOT_FOUND;
diff --git
a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServer.java
b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServer.java
index 4c2974deec5..e0bbe4d2e38 100644
---
a/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServer.java
+++
b/hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/HttpFSServer.java
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
-import java.security.AccessControlException;
import java.security.PrivilegedExceptionAction;
import java.text.MessageFormat;
import java.util.EnumSet;
@@ -48,6 +47,7 @@
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.http.JettyUtils;
+import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
import
org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation;
import org.apache.ozone.fs.http.HttpFSConstants;
diff --git
a/hadoop-ozone/httpfsgateway/src/test/java/org/apache/ozone/fs/http/server/TestHttpFSExceptionProvider.java
b/hadoop-ozone/httpfsgateway/src/test/java/org/apache/ozone/fs/http/server/TestHttpFSExceptionProvider.java
new file mode 100644
index 00000000000..d9ac45cd732
--- /dev/null
+++
b/hadoop-ozone/httpfsgateway/src/test/java/org/apache/ozone/fs/http/server/TestHttpFSExceptionProvider.java
@@ -0,0 +1,59 @@
+/*
+ * 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.ozone.fs.http.server;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import javax.ws.rs.core.Response;
+import org.apache.hadoop.security.AccessControlException;
+import org.apache.ozone.lib.service.FileSystemAccessException;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link HttpFSExceptionProvider}.
+ */
+public class TestHttpFSExceptionProvider {
+
+ @Test
+ public void accessControlExceptionMapsToUnauthorized() {
+ HttpFSExceptionProvider provider = new HttpFSExceptionProvider();
+ Response response = provider.toResponse(
+ new AccessControlException("User not in HttpFSServer admin group"));
+ assertThat(response.getStatus())
+ .isEqualTo(Response.Status.UNAUTHORIZED.getStatusCode());
+ }
+
+ @Test
+ public void wrappedAccessControlExceptionMapsToUnauthorized() {
+ HttpFSExceptionProvider provider = new HttpFSExceptionProvider();
+ Response response = provider.toResponse(new FileSystemAccessException(
+ FileSystemAccessException.ERROR.H03,
+ new AccessControlException("permission denied")));
+ assertThat(response.getStatus())
+ .isEqualTo(Response.Status.UNAUTHORIZED.getStatusCode());
+ }
+
+ @Test
+ public void genericIOExceptionMapsToServerError() {
+ HttpFSExceptionProvider provider = new HttpFSExceptionProvider();
+ Response response = provider.toResponse(new IOException("io failure"));
+ assertThat(response.getStatus())
+ .isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]