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 1e97145692f..14b9062ca8e 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.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 NotificationREST(NotificationInterface notificationInterface) {
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 06647d59e4c..868fc7029de 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 @@
com.sun.jersey.spi.spring.container.servlet.SpringServlet
-
- com.sun.jersey.config.property.packages
- org.apache.atlas.notification.rest
-
com.sun.jersey.api.json.POJOMappingFeature
true
diff --git a/server-common/pom.xml b/server-common/pom.xml
index 4298c29c276..7eb80492e06 100644
--- a/server-common/pom.xml
+++ b/server-common/pom.xml
@@ -60,6 +60,10 @@
com.sun.jersey
jersey-core
+
+ com.sun.jersey
+ jersey-server
+
commons-io
commons-io
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 aeae95be9fd..58ed24de183 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 6f74c83d2c5..29542b9d3be
--- 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 5189ea5bf64..615aafdb2b2 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 @@ private 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 7aee1ae2924..641f3d90fe5 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/test/java/org/apache/atlas/web/errors/AllExceptionMapperTest.java b/webapp/src/test/java/org/apache/atlas/web/errors/AllExceptionMapperTest.java
index 004cfee85b4..e8934328a38 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 8e3d09c5796..c9a82dc0c2d 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 @@
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;
@@ -63,4 +64,17 @@ public void testToResponse() {
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 83ed8cfafda..12ea8e5c081 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 988bfd5af17..9f643e103f6 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;