Skip to content
Merged
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions rest-notification-webapp/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions server-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading