This is an automated email from the ASF dual-hosted git repository.

pinal-shah pushed a commit to branch atlas-2.6
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/atlas-2.6 by this push:
     new 39aeb1949f ATLAS-5434:- Missing SERVICE_NOTIFICATION_POST 
authorization on rest-notification NotificationREST POST /topic/{topicName} for 
2.6 branch.and ATLAS-5377: Remove duplicate NotificationREST endpoint from 
webapp for 2.6 branch
39aeb1949f is described below

commit 39aeb1949fed05c079a9b503e57f662217ff4ca6
Author: UmeshPatil-1 <[email protected]>
AuthorDate: Tue Nov 17 15:12:33 2026 +0530

    ATLAS-5434:- Missing SERVICE_NOTIFICATION_POST authorization on 
rest-notification NotificationREST POST /topic/{topicName} for 2.6 branch.and 
ATLAS-5377: Remove duplicate NotificationREST endpoint from webapp for 2.6 
branch
    
    * ATLAS-5434: Add rest notification authorization and shared error mappers 
for 2.6 (backport ATLAS-5365)
    
    * ATLAS-5434: Drop explicit Jersey class lists from rest web.xml; rely on 
Spring scan (2.6, backport ATLAS-5365)
    
    * ATLAS-5377: Remove duplicate NotificationREST endpoint from the main 
webapp (port 21000) and require hooks to use rest-notification-webapp (port 
41000/rest) only.
    
    (cherry picked from commit 4af1c264d34c517f9c26fd711d914a6be2fcf0e4)
    
    * ATLAS-5377: Updated NotificationRestIT to assert endpoint is removed from 
webapp (expect error, not 204).
    
    (cherry picked from commit e832af3a69ba55403995c954cbf37d4ffec89f2a)
    
    * ATLAS-5377: Updated assertion and shorter fail-fast message as per review.
    
    (cherry picked from commit 939bd702bc5eceeb94623c19f3f7139f0a5de4a2)
---
 .../main/java/org/apache/atlas/AtlasConstants.java |   3 +-
 .../atlas/notification/rest/RestNotification.java  |  10 +-
 .../atlas/notification/RestNotificationTest.java   |  44 ++++---
 .../rest/web/rest/NotificationREST.java            |   5 +
 .../src/main/webapp/WEB-INF/web.xml                |   4 -
 server-common/pom.xml                              |   4 +
 .../server/common}/errors/AllExceptionMapper.java  |   2 +-
 .../common}/errors/AtlasBaseExceptionMapper.java   |   2 +-
 .../server/common}/errors/ExceptionMapperUtil.java |   8 +-
 .../common}/errors/NotFoundExceptionMapper.java    |   2 +-
 .../apache/atlas/web/rest/NotificationREST.java    | 134 ---------------------
 .../atlas/web/errors/AllExceptionMapperTest.java   |   1 +
 .../web/errors/AtlasBaseExceptionMapperTest.java   |  14 +++
 .../atlas/web/errors/ExceptionMapperUtilTest.java  |   1 +
 .../web/errors/NotFoundExceptionMapperTest.java    |   1 +
 .../atlas/web/integration/NotificationRestIT.java  |  32 +++--
 16 files changed, 86 insertions(+), 181 deletions(-)

diff --git a/common/src/main/java/org/apache/atlas/AtlasConstants.java 
b/common/src/main/java/org/apache/atlas/AtlasConstants.java
index cc0d507633..e2930062ce 100644
--- a/common/src/main/java/org/apache/atlas/AtlasConstants.java
+++ b/common/src/main/java/org/apache/atlas/AtlasConstants.java
@@ -31,7 +31,8 @@ public final class AtlasConstants {
     public static final String ATLAS_SERVICES_ENABLED        = 
"atlas.services.enabled";
     public static final String CLUSTER_NAME_ATTRIBUTE        = "clusterName";
     public static final String DEFAULT_APP_PORT_STR          = "21000";
-    public static final String DEFAULT_ATLAS_REST_ADDRESS    = 
"http://localhost:21000";;
+    public static final String DEFAULT_ATLAS_REST_ADDRESS           = 
"http://localhost:21000";;
+    public static final String DEFAULT_REST_NOTIFICATION_ADDRESS    = 
"http://localhost:41000/rest";;
     public static final String DEFAULT_TYPE_VERSION          = "1.0";
     public static final int    ATLAS_SHUTDOWN_HOOK_PRIORITY  = 30;
 
diff --git 
a/notification/src/main/java/org/apache/atlas/notification/rest/RestNotification.java
 
b/notification/src/main/java/org/apache/atlas/notification/rest/RestNotification.java
index e94afddc9e..0743545ffc 100644
--- 
a/notification/src/main/java/org/apache/atlas/notification/rest/RestNotification.java
+++ 
b/notification/src/main/java/org/apache/atlas/notification/rest/RestNotification.java
@@ -47,10 +47,9 @@ public class RestNotification extends AbstractNotification {
     private static final Logger LOG = 
LoggerFactory.getLogger(RestNotification.class);
 
     private static final int    BATCH_MAX_LENGTH_BYTES = 
AtlasConfiguration.NOTIFICATION_REST_BODY_MAX_LENGTH_BYTES.getInt();
-    private static final String ATLAS_HOOK_REST_NOTIFICATION_ENDPOINT   = 
"atlas.hook.rest.notification.address";
+    private static final String ATLAS_HOOK_REST_NOTIFICATION_ENDPOINT   = 
AtlasConfiguration.NOTIFICATION_HOOK_REST_ADDRESS.getPropertyName();
     private static final String BASIC_AUTH_USERNAME    = 
"atlas.rest.basic.auth.username";
     private static final String BASIC_AUTH_PASSWORD    = 
"atlas.rest.basic.auth.password";
-    private static final String DEFAULT_ATLAS_URL      = 
"http://localhost:31000/";;
 
     private static final Map<NotificationType, String> PRODUCER_TOPIC_MAP = 
new HashMap<>();
 
@@ -115,11 +114,8 @@ public class RestNotification extends AbstractNotification 
{
             String[] atlasEndPoint = 
configuration.getStringArray(ATLAS_HOOK_REST_NOTIFICATION_ENDPOINT);
 
             if (isEndpointNotSpecified(atlasEndPoint)) {
-                atlasEndPoint = 
configuration.getStringArray(AtlasConstants.ATLAS_REST_ADDRESS_KEY);
-            }
-
-            if (isEndpointNotSpecified(atlasEndPoint)) {
-                atlasEndPoint = new String[] {DEFAULT_ATLAS_URL};
+                throw new AtlasException(ATLAS_HOOK_REST_NOTIFICATION_ENDPOINT 
+ " is required for rest-notification-webapp (e.g. "
+                        + AtlasConstants.DEFAULT_REST_NOTIFICATION_ADDRESS + 
")");
             }
 
             if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
diff --git 
a/notification/src/test/java/org/apache/atlas/notification/RestNotificationTest.java
 
b/notification/src/test/java/org/apache/atlas/notification/RestNotificationTest.java
index 7e5f6841c6..032da6f9c8 100644
--- 
a/notification/src/test/java/org/apache/atlas/notification/RestNotificationTest.java
+++ 
b/notification/src/test/java/org/apache/atlas/notification/RestNotificationTest.java
@@ -25,6 +25,7 @@ import org.apache.atlas.AtlasBaseClient;
 import org.apache.atlas.AtlasClientV2;
 import org.apache.atlas.AtlasConfiguration;
 import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.AtlasException;
 import org.apache.atlas.kafka.NotificationProvider;
 import org.apache.atlas.notification.rest.RestNotification;
 import org.apache.commons.configuration2.Configuration;
@@ -67,6 +68,7 @@ public class RestNotificationTest {
         conf = ApplicationProperties.get();
 
         
conf.setProperty(AtlasConfiguration.NOTIFICATION_HOOK_REST_ENABLED.getPropertyName(),
 true);
+        
conf.setProperty(AtlasConfiguration.NOTIFICATION_HOOK_REST_ADDRESS.getPropertyName(),
 "http://localhost:41000/rest";);
         conf.setProperty(NotificationProvider.CONF_ATLAS_HOOK_SPOOL_ENABLED, 
false);
 
         notifier = NotificationProvider.get();
@@ -149,23 +151,17 @@ public class RestNotificationTest {
         assertEquals(configuredEndpoints[0], 
"http://atlas-rest.example.com:41000/rest";);
     }
 
-    @Test
-    public void testRestNotificationEndpointFallsBackToAtlasRestAddress() 
throws Exception {
+    @Test(expectedExceptions = AtlasException.class)
+    public void testRestNotificationFailsFastWhenHookAddressNotConfigured() 
throws Exception {
         Configuration localConf = new BaseConfiguration();
-        localConf.setProperty("atlas.rest.address", 
"http://atlas-main.example.com:21000";);
         localConf.setProperty("atlas.rest.basic.auth.username", "admin");
         localConf.setProperty("atlas.rest.basic.auth.password", "admin123");
 
-        RestNotification restNotification = new RestNotification(localConf);
-
-        String[] configuredEndpoints = 
getConfiguredBaseUrls(restNotification.atlasClientV2);
-
-        assertEquals(configuredEndpoints.length, 1);
-        assertEquals(configuredEndpoints[0], 
"http://atlas-main.example.com:21000";);
+        new RestNotification(localConf);
     }
 
-    @Test
-    public void 
testRestNotificationFallsBackToAtlasRestWhenNotificationAddressesAllBlank() 
throws Exception {
+    @Test(expectedExceptions = AtlasException.class)
+    public void testRestNotificationFailsFastWhenHookAddressesAllBlank() 
throws Exception {
         Configuration localConf = new BaseConfiguration();
         localConf.addProperty("atlas.hook.rest.notification.address", "");
         localConf.addProperty("atlas.hook.rest.notification.address", "   ");
@@ -173,12 +169,30 @@ public class RestNotificationTest {
         localConf.setProperty("atlas.rest.basic.auth.username", "admin");
         localConf.setProperty("atlas.rest.basic.auth.password", "admin123");
 
-        RestNotification restNotification = new RestNotification(localConf);
+        new RestNotification(localConf);
+    }
 
-        String[] configuredEndpoints = 
getConfiguredBaseUrls(restNotification.atlasClientV2);
+    @Test(expectedExceptions = AtlasException.class)
+    public void 
testRestNotificationFailsFastWhenOnlyAtlasRestAddressConfigured() throws 
Exception {
+        Configuration localConf = new BaseConfiguration();
+        localConf.setProperty("atlas.rest.address", 
"http://atlas-main.example.com:21000";);
+        localConf.setProperty("atlas.rest.basic.auth.username", "admin");
+        localConf.setProperty("atlas.rest.basic.auth.password", "admin123");
 
-        assertEquals(configuredEndpoints.length, 1);
-        assertEquals(configuredEndpoints[0], 
"http://atlas-main.example.com:21000";);
+        new RestNotification(localConf);
+    }
+
+    @Test
+    public void testRestNotificationFailFastExceptionMessage() {
+        Configuration localConf = new BaseConfiguration();
+
+        try {
+            new RestNotification(localConf);
+            fail("Expected AtlasException when 
atlas.hook.rest.notification.address is not configured");
+        } catch (AtlasException e) {
+            
assertTrue(e.getMessage().contains("atlas.hook.rest.notification.address is 
required"));
+            assertTrue(e.getMessage().contains("http://localhost:41000/rest";));
+        }
     }
 
     private String[] getConfiguredBaseUrls(AtlasClientV2 atlasClientV2) throws 
Exception {
diff --git 
a/rest-notification-webapp/src/main/java/org/apache/atlas/notification/rest/web/rest/NotificationREST.java
 
b/rest-notification-webapp/src/main/java/org/apache/atlas/notification/rest/web/rest/NotificationREST.java
index 1e97145692..14b9062ca8 100644
--- 
a/rest-notification-webapp/src/main/java/org/apache/atlas/notification/rest/web/rest/NotificationREST.java
+++ 
b/rest-notification-webapp/src/main/java/org/apache/atlas/notification/rest/web/rest/NotificationREST.java
@@ -21,6 +21,9 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import org.apache.atlas.AtlasConfiguration;
 import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.authorize.AtlasAdminAccessRequest;
+import org.apache.atlas.authorize.AtlasAuthorizationUtils;
+import org.apache.atlas.authorize.AtlasPrivilege;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.hook.AtlasHook;
 import org.apache.atlas.kafka.KafkaNotification;
@@ -88,6 +91,8 @@ public class NotificationREST {
     public void handleNotifications(@PathParam("topicName") String topicName, 
@Context HttpServletRequest request) throws AtlasBaseException, IOException {
         LOG.debug("Handling notifications for topic {}", topicName);
 
+        AtlasAuthorizationUtils.verifyAccess(new 
AtlasAdminAccessRequest(AtlasPrivilege.SERVICE_NOTIFICATION_POST), "post on 
rest notification service");
+
         if (!TOPICS.contains(topicName)) {
             throw new AtlasBaseException(AtlasErrorCode.INVALID_TOPIC_NAME, 
topicName);
         }
diff --git a/rest-notification-webapp/src/main/webapp/WEB-INF/web.xml 
b/rest-notification-webapp/src/main/webapp/WEB-INF/web.xml
index 06647d59e4..868fc7029d 100644
--- a/rest-notification-webapp/src/main/webapp/WEB-INF/web.xml
+++ b/rest-notification-webapp/src/main/webapp/WEB-INF/web.xml
@@ -31,10 +31,6 @@
         <servlet-class>
             com.sun.jersey.spi.spring.container.servlet.SpringServlet
         </servlet-class>
-        <init-param>
-            <param-name>com.sun.jersey.config.property.packages</param-name>
-            <param-value>org.apache.atlas.notification.rest</param-value>
-        </init-param>
         <init-param>
             <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
             <param-value>true</param-value>
diff --git a/server-common/pom.xml b/server-common/pom.xml
index e437c6b8ae..b8d441bfde 100644
--- a/server-common/pom.xml
+++ b/server-common/pom.xml
@@ -60,6 +60,10 @@
             <groupId>com.sun.jersey</groupId>
             <artifactId>jersey-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-server</artifactId>
+        </dependency>
         <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/AllExceptionMapper.java
similarity index 97%
rename from 
webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java
rename to 
server-common/src/main/java/org/apache/atlas/server/common/errors/AllExceptionMapper.java
index aeae95be9f..58ed24de18 100644
--- a/webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java
+++ 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/AllExceptionMapper.java
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.atlas.web.errors;
+package org.apache.atlas.server.common.errors;
 
 import org.springframework.stereotype.Component;
 
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/AtlasBaseExceptionMapper.java
old mode 100755
new mode 100644
similarity index 98%
rename from 
webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
rename to 
server-common/src/main/java/org/apache/atlas/server/common/errors/AtlasBaseExceptionMapper.java
index 6f74c83d2c..29542b9d3b
--- 
a/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
+++ 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/AtlasBaseExceptionMapper.java
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.atlas.web.errors;
+package org.apache.atlas.server.common.errors;
 
 import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.exception.AtlasBaseException;
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/ExceptionMapperUtil.java
similarity index 84%
rename from 
webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
rename to 
server-common/src/main/java/org/apache/atlas/server/common/errors/ExceptionMapperUtil.java
index 5189ea5bf6..615aafdb2b 100644
--- a/webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
+++ 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/ExceptionMapperUtil.java
@@ -15,7 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.atlas.web.errors;
+package org.apache.atlas.server.common.errors;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,16 +28,16 @@ public class ExceptionMapperUtil {
     }
 
     @SuppressWarnings("UnusedParameters")
-    protected static String formatErrorMessage(long id, Exception exception) {
+    public static String formatErrorMessage(long id, Exception exception) {
         return String.format("There was an error processing your request. It 
has been logged (ID %016x).", id);
     }
 
-    protected static void logException(long id, Exception exception) {
+    public static void logException(long id, Exception exception) {
         LOGGER.error(formatLogMessage(id, exception), exception);
     }
 
     @SuppressWarnings("UnusedParameters")
-    protected static String formatLogMessage(long id, Throwable exception) {
+    public static String formatLogMessage(long id, Throwable exception) {
         return String.format("Error handling a request: %016x", id);
     }
 }
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/NotFoundExceptionMapper.java
similarity index 96%
rename from 
webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
rename to 
server-common/src/main/java/org/apache/atlas/server/common/errors/NotFoundExceptionMapper.java
index 7aee1ae292..641f3d90fe 100644
--- 
a/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
+++ 
b/server-common/src/main/java/org/apache/atlas/server/common/errors/NotFoundExceptionMapper.java
@@ -15,7 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.atlas.web.errors;
+package org.apache.atlas.server.common.errors;
 
 import org.apache.atlas.exception.NotFoundException;
 import org.springframework.stereotype.Component;
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/rest/NotificationREST.java 
b/webapp/src/main/java/org/apache/atlas/web/rest/NotificationREST.java
deleted file mode 100644
index 8c01c2e73a..0000000000
--- a/webapp/src/main/java/org/apache/atlas/web/rest/NotificationREST.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.atlas.web.rest;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import org.apache.atlas.AtlasConfiguration;
-import org.apache.atlas.AtlasErrorCode;
-import org.apache.atlas.authorize.AtlasAuthorizationUtils;
-import org.apache.atlas.authorize.AtlasNotificationRequest;
-import org.apache.atlas.authorize.AtlasPrivilege;
-import org.apache.atlas.exception.AtlasBaseException;
-import org.apache.atlas.hook.AtlasHook;
-import org.apache.atlas.kafka.KafkaNotification;
-import org.apache.atlas.notification.NotificationException;
-import org.apache.atlas.notification.NotificationInterface;
-import org.apache.atlas.server.common.util.Servlets;
-import org.apache.atlas.utils.AtlasJson;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-@Path("v2/notification")
-@Singleton
-@Service
-@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
-@Produces({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
-public class NotificationREST {
-    private static final Logger LOG = 
LoggerFactory.getLogger(NotificationREST.class);
-
-    public static final String ATLAS_HOOK_TOPIC     = 
AtlasConfiguration.NOTIFICATION_HOOK_TOPIC_NAME.getString();
-    public static final String ATLAS_ENTITIES_TOPIC = 
AtlasConfiguration.NOTIFICATION_ENTITIES_TOPIC_NAME.getString();
-
-    private static final String[]    ATLAS_HOOK_CONSUMER_TOPICS     = 
AtlasConfiguration.NOTIFICATION_HOOK_CONSUMER_TOPIC_NAMES.getStringArray(ATLAS_HOOK_TOPIC);
-    private static final String[]    ATLAS_ENTITIES_CONSUMER_TOPICS = 
AtlasConfiguration.NOTIFICATION_ENTITIES_CONSUMER_TOPIC_NAMES.getStringArray(ATLAS_ENTITIES_TOPIC);
-    private static final Set<String> TOPICS                         = new 
HashSet<>();
-
-    private final NotificationInterface notificationInterface;
-
-    @Inject
-    public NotificationREST(NotificationInterface notificationInterface) {
-        this.notificationInterface = notificationInterface;
-    }
-
-    /**
-     * Publish notifications on Kafka topic
-     *
-     *  @param topicName - nameOfTheQueue
-     *  @throws AtlasBaseException
-     */
-    @POST
-    @Path("/topic/{topicName}")
-    @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
-    public void handleNotifications(@PathParam("topicName") String topicName, 
@Context HttpServletRequest request) throws AtlasBaseException, IOException {
-        LOG.debug("Handling notifications for topic {}", topicName);
-
-        AtlasAuthorizationUtils.verifyAccess(new 
AtlasNotificationRequest(AtlasPrivilege.POST_NOTIFICATION, topicName), "post on 
notification topic ", topicName);
-
-        if (!TOPICS.contains(topicName)) {
-            throw new AtlasBaseException(AtlasErrorCode.INVALID_TOPIC_NAME, 
topicName);
-        }
-
-        String       messagesAsJson = Servlets.getRequestPayload(request);
-        List<String> messages       = getMessagesToNotify(messagesAsJson);
-
-        try {
-            KafkaNotification notifier = (KafkaNotification) 
notificationInterface;
-
-            notifier.sendInternal(topicName, messages, 
AtlasHook.isHookMsgsSortEnabled);
-        } catch (NotificationException exception) {
-            List<String> failedMessages      = exception.getFailedMessages();
-            String       concatenatedMessage = 
StringUtils.join(failedMessages, "\n");
-
-            throw new 
AtlasBaseException(AtlasErrorCode.NOTIFICATION_EXCEPTION, exception, 
concatenatedMessage);
-        } catch (Exception exception) {
-            throw new 
AtlasBaseException(AtlasErrorCode.NOTIFICATION_EXCEPTION, exception, 
exception.getMessage());
-        }
-    }
-
-    private List<String> getMessagesToNotify(String messagesAsJson) {
-        List<String> messages = new ArrayList<>();
-
-        try {
-            ArrayNode messageNodes = 
AtlasJson.parseToV1ArrayNode(messagesAsJson);
-
-            for (JsonNode messageNode : messageNodes) {
-                messages.add(AtlasJson.toV1Json(messageNode));
-            }
-        } catch (IOException e) {
-            messages.add(messagesAsJson);
-        }
-
-        return messages;
-    }
-
-    static {
-        TOPICS.addAll(Arrays.asList(ATLAS_HOOK_CONSUMER_TOPICS));
-        TOPICS.addAll(Arrays.asList(ATLAS_ENTITIES_CONSUMER_TOPICS));
-    }
-}
diff --git 
a/webapp/src/test/java/org/apache/atlas/web/errors/AllExceptionMapperTest.java 
b/webapp/src/test/java/org/apache/atlas/web/errors/AllExceptionMapperTest.java
index 004cfee85b..e8934328a3 100644
--- 
a/webapp/src/test/java/org/apache/atlas/web/errors/AllExceptionMapperTest.java
+++ 
b/webapp/src/test/java/org/apache/atlas/web/errors/AllExceptionMapperTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.atlas.web.errors;
 
+import org.apache.atlas.server.common.errors.AllExceptionMapper;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
diff --git 
a/webapp/src/test/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapperTest.java
 
b/webapp/src/test/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapperTest.java
index e4543854d9..e9672e33e1 100644
--- 
a/webapp/src/test/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapperTest.java
+++ 
b/webapp/src/test/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapperTest.java
@@ -20,6 +20,7 @@ package org.apache.atlas.web.errors;
 
 import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.exception.AtlasBaseException;
+import org.apache.atlas.server.common.errors.AtlasBaseExceptionMapper;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -82,4 +83,17 @@ public class AtlasBaseExceptionMapperTest {
             assertTrue(true);
         }
     }
+
+    @Test
+    public void testUnauthorizedAccessResponse() {
+        AtlasBaseException testException = new AtlasBaseException(
+                AtlasErrorCode.UNAUTHORIZED_ACCESS, "testuser", "post on rest 
notification service");
+
+        Response response = atlasBaseExceptionMapper.toResponse(testException);
+
+        assertEquals(response.getStatus(), 
Response.Status.FORBIDDEN.getStatusCode());
+        String entity = (String) response.getEntity();
+        assertTrue(entity.contains("ATLAS-403-00-001"));
+        assertTrue(entity.contains("not authorized to perform post on rest 
notification service"));
+    }
 }
diff --git 
a/webapp/src/test/java/org/apache/atlas/web/errors/ExceptionMapperUtilTest.java 
b/webapp/src/test/java/org/apache/atlas/web/errors/ExceptionMapperUtilTest.java
index 83ed8cfafd..12ea8e5c08 100644
--- 
a/webapp/src/test/java/org/apache/atlas/web/errors/ExceptionMapperUtilTest.java
+++ 
b/webapp/src/test/java/org/apache/atlas/web/errors/ExceptionMapperUtilTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.atlas.web.errors;
 
+import org.apache.atlas.server.common.errors.ExceptionMapperUtil;
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertNotNull;
diff --git 
a/webapp/src/test/java/org/apache/atlas/web/errors/NotFoundExceptionMapperTest.java
 
b/webapp/src/test/java/org/apache/atlas/web/errors/NotFoundExceptionMapperTest.java
index 988bfd5af1..9f643e103f 100644
--- 
a/webapp/src/test/java/org/apache/atlas/web/errors/NotFoundExceptionMapperTest.java
+++ 
b/webapp/src/test/java/org/apache/atlas/web/errors/NotFoundExceptionMapperTest.java
@@ -19,6 +19,7 @@
 package org.apache.atlas.web.errors;
 
 import org.apache.atlas.exception.NotFoundException;
+import org.apache.atlas.server.common.errors.NotFoundExceptionMapper;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
diff --git 
a/webapp/src/test/java/org/apache/atlas/web/integration/NotificationRestIT.java 
b/webapp/src/test/java/org/apache/atlas/web/integration/NotificationRestIT.java
index 96df5d5996..54c1a4bcea 100644
--- 
a/webapp/src/test/java/org/apache/atlas/web/integration/NotificationRestIT.java
+++ 
b/webapp/src/test/java/org/apache/atlas/web/integration/NotificationRestIT.java
@@ -17,7 +17,7 @@
  */
 package org.apache.atlas.web.integration;
 
-import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.sun.jersey.api.client.ClientResponse;
 import org.apache.atlas.AtlasClientV2;
 import org.apache.atlas.AtlasServiceException;
 import org.apache.atlas.utils.TestResourceFileUtils;
@@ -30,40 +30,46 @@ import java.util.Date;
 
 import static org.apache.atlas.kafka.KafkaNotification.ATLAS_HOOK_TOPIC;
 import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 
+/**
+ * ATLAS-5377: hook notification REST ingress was removed from the main Atlas 
webapp.
+ * Canonical endpoint is rest-notification-webapp only. These integration 
tests verify
+ * that POST /api/atlas/v2/notification/topic/{topicName} is not served on 
main webapp.
+ */
 public class NotificationRestIT extends BaseResourceIT {
     @Test
-    public void unAuthPostNotification() throws IOException {
+    public void unAuthPostNotificationRejected() throws IOException {
         AtlasClientV2 unAuthClient = new AtlasClientV2(atlasUrls, new String[] 
{"admin", "wr0ng_pa55w0rd"});
 
         try {
-            unAuthClient.postNotificationToTopic(ATLAS_HOOK_TOPIC, new 
ArrayList<String>(Collections.singletonList("Dummy")));
+            unAuthClient.postNotificationToTopic(ATLAS_HOOK_TOPIC, new 
ArrayList<>(Collections.singletonList("Dummy")));
+
+            fail("Expected postNotificationToTopic to fail on main webapp");
         } catch (AtlasServiceException e) {
             assertNotNull(e.getStatus(), "expected server error code in the 
status");
         }
     }
 
     @Test
-    public void postNotificationBasicTest() throws Exception {
+    public void notificationEndpointRemovedFromMainWebapp() throws Exception {
         String dbName        = "db_" + randomString();
         String clusterName   = "cl" + randomString();
-        String qualifiedName = dbName + "@" + clusterName;
 
         String notificationString = 
TestResourceFileUtils.getJson("notifications/create-db")
                 .replaceAll("--name--", dbName).replaceAll("--clName--", 
clusterName)
                 .replace("\"--ts--\"", String.valueOf((new Date()).getTime()));
 
         try {
-            atlasClientV2.postNotificationToTopic(ATLAS_HOOK_TOPIC, new 
ArrayList<String>(Collections.singletonList(notificationString)));
+            atlasClientV2.postNotificationToTopic(ATLAS_HOOK_TOPIC, new 
ArrayList<>(Collections.singletonList(notificationString)));
 
-            waitFor(MAX_WAIT_TIME, () -> {
-                ArrayNode results = searchByDSL(String.format("%s where 
qualifiedName='%s'", DATABASE_TYPE_BUILTIN, qualifiedName));
-
-                return results.size() == 1;
-            });
+            fail("Expected notification POST to fail — endpoint removed from 
main webapp (ATLAS-5377)");
         } catch (AtlasServiceException e) {
-            assertNull(e.getStatus(), "expected no server error code in the 
status");
+            assertNotNull(e.getStatus(), "expected HTTP error when posting to 
removed endpoint");
+
+            assertTrue(e.getStatus().getStatusCode() != 
ClientResponse.Status.NO_CONTENT.getStatusCode(),
+                    "notification POST must not return 204 on main webapp");
         }
     }
 }

Reply via email to