Delete service event creator
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0f31ccab Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0f31ccab Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0f31ccab Branch: refs/heads/audit_logging Commit: 0f31ccaba4643cf5158799497dadb24ba59b4671 Parents: 81ee76e Author: Daniel Gergely <[email protected]> Authored: Thu Feb 18 14:11:05 2016 +0100 Committer: Toader, Sebastian <[email protected]> Committed: Thu Mar 24 13:06:45 2016 +0100 ---------------------------------------------------------------------- .../DeleteServiceRequestAuditEvent.java | 77 ++++++++++++++++++++ .../eventcreator/ServiceEventCreator.java | 12 +++ 2 files changed, 89 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/0f31ccab/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/DeleteServiceRequestAuditEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/DeleteServiceRequestAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/DeleteServiceRequestAuditEvent.java new file mode 100644 index 0000000..f6083d1 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/DeleteServiceRequestAuditEvent.java @@ -0,0 +1,77 @@ +/* + * 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.ambari.server.audit.request.eventcreator; + +import org.apache.ambari.server.audit.request.RequestAuditEvent; + +public class DeleteServiceRequestAuditEvent extends RequestAuditEvent { + + public static class DeleteServiceRequestAuditEventBuilder extends RequestAuditEventBuilder<DeleteServiceRequestAuditEvent, DeleteServiceRequestAuditEventBuilder> { + + private String serviceName; + + public DeleteServiceRequestAuditEventBuilder() { + super.withOperation("Service deletion"); + } + + @Override + protected DeleteServiceRequestAuditEvent newAuditEvent() { + return new DeleteServiceRequestAuditEvent(this); + } + + /** + * Appends to the event the details of the incoming request. + * @param builder builder for the audit event details. + */ + @Override + protected void buildAuditMessage(StringBuilder builder) { + super.buildAuditMessage(builder); + + builder + .append(", Service(") + .append(serviceName) + .append(")"); + } + + public DeleteServiceRequestAuditEventBuilder withService(String service) { + this.serviceName = service; + return this; + } + + } + + protected DeleteServiceRequestAuditEvent() { + } + + /** + * {@inheritDoc} + */ + protected DeleteServiceRequestAuditEvent(DeleteServiceRequestAuditEventBuilder builder) { + super(builder); + } + + /** + * Returns an builder for {@link DeleteServiceRequestAuditEvent} + * @return a builder instance + */ + public static DeleteServiceRequestAuditEventBuilder builder() { + return new DeleteServiceRequestAuditEventBuilder(); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/0f31ccab/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ServiceEventCreator.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ServiceEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ServiceEventCreator.java index ad0c381..9b2f064 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ServiceEventCreator.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ServiceEventCreator.java @@ -82,6 +82,18 @@ public class ServiceEventCreator implements RequestAuditEventCreator { public AuditEvent createAuditEvent(Request request, Result result) { String username = ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername(); + if(request.getRequestType() == Request.Type.DELETE) { + return DeleteServiceRequestAuditEvent.builder() + .withTimestamp(DateTime.now()) + .withRequestType(request.getRequestType()) + .withResultStatus(result.getStatus()) + .withUrl(request.getURI()) + .withRemoteIp(request.getRemoteAddress()) + .withUserName(username) + .withService(request.getResource().getKeyValueMap().get(Resource.Type.Service)) + .build(); + } + String operation = getOperation(request); if (result.getStatus().isErrorState()) {
