Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E3DB218B41 for ; Thu, 24 Mar 2016 12:08:34 +0000 (UTC) Received: (qmail 13399 invoked by uid 500); 24 Mar 2016 12:08:34 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 13300 invoked by uid 500); 24 Mar 2016 12:08:34 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 12578 invoked by uid 99); 24 Mar 2016 12:08:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Mar 2016 12:08:33 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AD662E9770; Thu, 24 Mar 2016 12:08:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stoader@apache.org To: commits@ambari.apache.org Date: Thu, 24 Mar 2016 12:08:47 -0000 Message-Id: <69db190945e247c98cd2e6b3a28d3ada@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [15/51] [abbrv] ambari git commit: Component addition to host audit event Component addition to host audit event Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b07aa180 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b07aa180 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b07aa180 Branch: refs/heads/audit_logging Commit: b07aa180dd8e16be2a5ebe6bfea88b63a4713a8a Parents: d9ef0ee Author: Daniel Gergely Authored: Tue Feb 23 14:07:01 2016 +0100 Committer: Toader, Sebastian Committed: Thu Mar 24 13:06:46 2016 +0100 ---------------------------------------------------------------------- .../AddComponentToHostRequestAuditEvent.java | 83 ++++++++++++++++++++ .../request/eventcreator/HostEventCreator.java | 38 ++++++++- 2 files changed, 119 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b07aa180/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java new file mode 100644 index 0000000..4270505 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java @@ -0,0 +1,83 @@ +/* + * 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.event; + +import org.apache.ambari.server.audit.request.RequestAuditEvent; + +public class AddComponentToHostRequestAuditEvent extends RequestAuditEvent { + + public static class AddComponentToHostRequestAuditEventBuilder extends RequestAuditEventBuilder { + + private String hostName; + private String component; + + public AddComponentToHostRequestAuditEventBuilder() { + super.withOperation("Component addition to host"); + } + + @Override + protected AddComponentToHostRequestAuditEvent newAuditEvent() { + return new AddComponentToHostRequestAuditEvent(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(", Hostname(") + .append(hostName) + .append(", Component(") + .append(component) + .append(")"); + } + + public AddComponentToHostRequestAuditEventBuilder withHostName(String hostName) { + this.hostName = hostName; + return this; + } + + public AddComponentToHostRequestAuditEventBuilder withComponent(String component) { + this.component = component; + return this; + } + } + + protected AddComponentToHostRequestAuditEvent() { + } + + /** + * {@inheritDoc} + */ + protected AddComponentToHostRequestAuditEvent(AddComponentToHostRequestAuditEventBuilder builder) { + super(builder); + } + + /** + * Returns an builder for {@link AddComponentToHostRequestAuditEvent} + * @return a builder instance + */ + public static AddComponentToHostRequestAuditEventBuilder builder() { + return new AddComponentToHostRequestAuditEventBuilder(); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b07aa180/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java index fef39fb..837f6b6 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java @@ -29,6 +29,7 @@ import org.apache.ambari.server.audit.AuditEvent; import org.apache.ambari.server.audit.StartOperationFailedAuditEvent; import org.apache.ambari.server.audit.StartOperationSucceededAuditEvent; import org.apache.ambari.server.audit.request.RequestAuditEventCreator; +import org.apache.ambari.server.audit.request.event.AddComponentToHostRequestAuditEvent; import org.apache.ambari.server.audit.request.event.AddHostRequestAuditEvent; import org.apache.ambari.server.audit.request.event.DeleteAlertGroupRequestAuditEvent; import org.apache.ambari.server.audit.request.event.DeleteHostRequestAuditEvent; @@ -40,9 +41,9 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; /** - * This creator handles host requests (add, delete) + * This creator handles host requests (add, delete, add component) * For resource type {@link Resource.Type#HostComponent} - * and request types {@link Request.Type#POST} and {@link Request.Type#DELETE} + * and request types {@link Request.Type#POST}, {@link Request.Type#DELETE} and {@link Request.Type#QUERY_POST} */ public class HostEventCreator implements RequestAuditEventCreator { @@ -54,6 +55,7 @@ public class HostEventCreator implements RequestAuditEventCreator { { requestTypes.add(Request.Type.POST); requestTypes.add(Request.Type.DELETE); + requestTypes.add(Request.Type.QUERY_POST); } private Set resourceTypes = new HashSet(); @@ -105,6 +107,17 @@ public class HostEventCreator implements RequestAuditEventCreator { .withUserName(username) .withHostName(getHostName(request)) .build(); + case QUERY_POST: + return AddComponentToHostRequestAuditEvent.builder() + .withTimestamp(DateTime.now()) + .withRequestType(request.getRequestType()) + .withResultStatus(result.getStatus()) + .withUrl(request.getURI()) + .withRemoteIp(request.getRemoteAddress()) + .withUserName(username) + .withHostName(getHostNameFromQuery(request)) + .withComponent(getHostComponent(request)) + .build(); default: return null; } @@ -116,4 +129,25 @@ public class HostEventCreator implements RequestAuditEventCreator { } return null; } + + private String getHostComponent(Request request) { + if(!request.getBody().getNamedPropertySets().isEmpty()) { + Set> set = (Set>)request.getBody().getNamedPropertySets().iterator().next().getProperties().get("host_components"); + if(set != null && !set.isEmpty()) { + return set.iterator().next().get(PropertyHelper.getPropertyId("HostRoles","component_name")); + } + } + return null; + } + + private String getHostNameFromQuery(Request request) { + final String key = PropertyHelper.getPropertyId("Hosts","host_name"); + if(request.getBody().getQueryString().contains(key)) { + String q = request.getBody().getQueryString(); + int startIndex = q.indexOf(key) + key.length() + 1; + int endIndex = q.indexOf("&", startIndex) == -1 ? q.length() : q.indexOf("&", startIndex); + return q.substring(startIndex, endIndex); + } + return null; + } }