Skip to content

Commit ffb7a36

Browse files
authored
ATLAS-5365: Missing SERVICE_NOTIFICATION_POST authorization on rest-notification NotificationREST POST /topic/{topicName}. (#716)
* ATLAS-5365: Add rest notification authorization and shared error mappers,and move Jersey exception mappers to server-common with rest web.xml updates for Java 17 and JSON error parity with webapp. * ATLAS-5365: Drop explicit Jersey class lists from rest web.xml; rely on Spring scan (like webapp).
1 parent c1ec5db commit ffb7a36

11 files changed

Lines changed: 33 additions & 11 deletions

File tree

rest-notification-webapp/src/main/java/org/apache/atlas/notification/rest/web/rest/NotificationREST.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import com.fasterxml.jackson.databind.node.ArrayNode;
2222
import org.apache.atlas.AtlasConfiguration;
2323
import org.apache.atlas.AtlasErrorCode;
24+
import org.apache.atlas.authorize.AtlasAdminAccessRequest;
25+
import org.apache.atlas.authorize.AtlasAuthorizationUtils;
26+
import org.apache.atlas.authorize.AtlasPrivilege;
2427
import org.apache.atlas.exception.AtlasBaseException;
2528
import org.apache.atlas.hook.AtlasHook;
2629
import org.apache.atlas.kafka.KafkaNotification;
@@ -88,6 +91,8 @@ public NotificationREST(NotificationInterface notificationInterface) {
8891
public void handleNotifications(@PathParam("topicName") String topicName, @Context HttpServletRequest request) throws AtlasBaseException, IOException {
8992
LOG.debug("Handling notifications for topic {}", topicName);
9093

94+
AtlasAuthorizationUtils.verifyAccess(new AtlasAdminAccessRequest(AtlasPrivilege.SERVICE_NOTIFICATION_POST), "post on rest notification service");
95+
9196
if (!TOPICS.contains(topicName)) {
9297
throw new AtlasBaseException(AtlasErrorCode.INVALID_TOPIC_NAME, topicName);
9398
}

rest-notification-webapp/src/main/webapp/WEB-INF/web.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
<servlet-class>
3232
com.sun.jersey.spi.spring.container.servlet.SpringServlet
3333
</servlet-class>
34-
<init-param>
35-
<param-name>com.sun.jersey.config.property.packages</param-name>
36-
<param-value>org.apache.atlas.notification.rest</param-value>
37-
</init-param>
3834
<init-param>
3935
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
4036
<param-value>true</param-value>

server-common/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
<groupId>com.sun.jersey</groupId>
6161
<artifactId>jersey-core</artifactId>
6262
</dependency>
63+
<dependency>
64+
<groupId>com.sun.jersey</groupId>
65+
<artifactId>jersey-server</artifactId>
66+
</dependency>
6367
<dependency>
6468
<groupId>commons-io</groupId>
6569
<artifactId>commons-io</artifactId>

webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java renamed to server-common/src/main/java/org/apache/atlas/server/common/errors/AllExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19-
package org.apache.atlas.web.errors;
19+
package org.apache.atlas.server.common.errors;
2020

2121
import org.springframework.stereotype.Component;
2222

webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java renamed to server-common/src/main/java/org/apache/atlas/server/common/errors/AtlasBaseExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19-
package org.apache.atlas.web.errors;
19+
package org.apache.atlas.server.common.errors;
2020

2121
import org.apache.atlas.AtlasErrorCode;
2222
import org.apache.atlas.exception.AtlasBaseException;

webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java renamed to server-common/src/main/java/org/apache/atlas/server/common/errors/ExceptionMapperUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package org.apache.atlas.web.errors;
18+
package org.apache.atlas.server.common.errors;
1919

2020
import org.slf4j.Logger;
2121
import org.slf4j.LoggerFactory;
@@ -28,16 +28,16 @@ private ExceptionMapperUtil() {
2828
}
2929

3030
@SuppressWarnings("UnusedParameters")
31-
protected static String formatErrorMessage(long id, Exception exception) {
31+
public static String formatErrorMessage(long id, Exception exception) {
3232
return String.format("There was an error processing your request. It has been logged (ID %016x).", id);
3333
}
3434

35-
protected static void logException(long id, Exception exception) {
35+
public static void logException(long id, Exception exception) {
3636
LOGGER.error(formatLogMessage(id, exception), exception);
3737
}
3838

3939
@SuppressWarnings("UnusedParameters")
40-
protected static String formatLogMessage(long id, Throwable exception) {
40+
public static String formatLogMessage(long id, Throwable exception) {
4141
return String.format("Error handling a request: %016x", id);
4242
}
4343
}

webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java renamed to server-common/src/main/java/org/apache/atlas/server/common/errors/NotFoundExceptionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package org.apache.atlas.web.errors;
18+
package org.apache.atlas.server.common.errors;
1919

2020
import org.apache.atlas.exception.NotFoundException;
2121
import org.springframework.stereotype.Component;

webapp/src/test/java/org/apache/atlas/web/errors/AllExceptionMapperTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.atlas.web.errors;
2020

21+
import org.apache.atlas.server.common.errors.AllExceptionMapper;
2122
import org.testng.annotations.BeforeClass;
2223
import org.testng.annotations.Test;
2324

webapp/src/test/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapperTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.atlas.AtlasErrorCode;
2222
import org.apache.atlas.exception.AtlasBaseException;
23+
import org.apache.atlas.server.common.errors.AtlasBaseExceptionMapper;
2324
import org.testng.annotations.BeforeClass;
2425
import org.testng.annotations.Test;
2526

@@ -82,4 +83,17 @@ public void testToResponse() {
8283
assertTrue(true);
8384
}
8485
}
86+
87+
@Test
88+
public void testUnauthorizedAccessResponse() {
89+
AtlasBaseException testException = new AtlasBaseException(
90+
AtlasErrorCode.UNAUTHORIZED_ACCESS, "testuser", "post on rest notification service");
91+
92+
Response response = atlasBaseExceptionMapper.toResponse(testException);
93+
94+
assertEquals(response.getStatus(), Response.Status.FORBIDDEN.getStatusCode());
95+
String entity = (String) response.getEntity();
96+
assertTrue(entity.contains("ATLAS-403-00-001"));
97+
assertTrue(entity.contains("not authorized to perform post on rest notification service"));
98+
}
8599
}

webapp/src/test/java/org/apache/atlas/web/errors/ExceptionMapperUtilTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.atlas.web.errors;
2020

21+
import org.apache.atlas.server.common.errors.ExceptionMapperUtil;
2122
import org.testng.annotations.Test;
2223

2324
import static org.testng.Assert.assertNotNull;

0 commit comments

Comments
 (0)