Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1019 from zalando/aruha-2134
Browse files Browse the repository at this point in the history
Audit log gets correct user id
  • Loading branch information
Kunal-Jha authored Feb 7, 2019
2 parents 115b7b6 + 6e51ddc commit e268a28
Show file tree
Hide file tree
Showing 31 changed files with 107 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.zalando.nakadi.validation.JsonSchemaEnrichment;
import org.zalando.nakadi.validation.ValidationStrategy;

import java.util.Optional;
import java.util.Set;

@Configuration
Expand All @@ -46,7 +45,7 @@ public FeatureToggleService featureToggleServiceLocal(final ZooKeeperHolder zooK
final boolean defaultState = featuresConfig.getDefaultState(featureStr);
LOG.info("Setting feature {} to {}", featureStr, defaultState);
final FeatureWrapper featureWrapper = new FeatureWrapper(Feature.valueOf(featureStr), defaultState);
featureToggleService.setFeature(featureWrapper, Optional.empty());
featureToggleService.setFeature(featureWrapper);
}
}
return featureToggleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import static org.springframework.http.ResponseEntity.noContent;
import static org.springframework.http.ResponseEntity.ok;
import static org.zalando.nakadi.util.RequestUtils.getUser;

@RestController
public class CursorsController {
Expand Down Expand Up @@ -101,7 +100,7 @@ public ResponseEntity<?> resetCursors(
@Valid @RequestBody final ItemsWrapper<SubscriptionCursorWithoutToken> cursors,
final NativeWebRequest request)
throws NoSuchEventTypeException, InvalidCursorException, InternalNakadiException {
cursorsService.resetCursors(subscriptionId, convertToNakadiCursors(cursors), getUser(request));
cursorsService.resetCursors(subscriptionId, convertToNakadiCursors(cursors));
return noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import static org.springframework.http.ResponseEntity.status;
import static org.zalando.nakadi.service.FeatureToggleService.Feature.DISABLE_EVENT_TYPE_CREATION;
import static org.zalando.nakadi.service.FeatureToggleService.Feature.DISABLE_EVENT_TYPE_DELETION;
import static org.zalando.nakadi.util.RequestUtils.getUser;

@RestController
@RequestMapping(value = "/event-types")
Expand Down Expand Up @@ -89,7 +88,7 @@ public ResponseEntity<?> create(@Valid @RequestBody final EventTypeBase eventTyp
throw new ValidationException(errors);
}

eventTypeService.create(eventType, getUser(request));
eventTypeService.create(eventType);

return ResponseEntity.status(HttpStatus.CREATED).headers(generateWarningHeaders(eventType)).build();
}
Expand All @@ -106,7 +105,7 @@ public ResponseEntity<?> delete(@PathVariable("name") final String eventTypeName
throw new ForbiddenOperationException("Event Type deletion is disabled");
}

eventTypeService.delete(eventTypeName, getUser(request));
eventTypeService.delete(eventTypeName);

return status(HttpStatus.OK).build();
}
Expand All @@ -128,7 +127,7 @@ public ResponseEntity<?> update(
throw new ValidationException(errors);
}

eventTypeService.update(name, eventType, getUser(request));
eventTypeService.update(name, eventType);

return status(HttpStatus.OK).headers(generateWarningHeaders(eventType)).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static org.apache.http.HttpHeaders.CONTENT_LOCATION;
import static org.springframework.http.HttpStatus.OK;
import static org.zalando.nakadi.service.FeatureToggleService.Feature.DISABLE_SUBSCRIPTION_CREATION;
import static org.zalando.nakadi.util.RequestUtils.getUser;


@RestController
Expand Down Expand Up @@ -66,8 +65,7 @@ public ResponseEntity<?> createOrGetSubscription(@Valid @RequestBody final Subsc
throw new SubscriptionCreationDisabledException("Subscription creation is temporarily unavailable");
}
try {
final Subscription subscription = subscriptionService.createSubscription(subscriptionBase,
getUser(request));
final Subscription subscription = subscriptionService.createSubscription(subscriptionBase);
return prepareLocationResponse(subscription);
} catch (final DuplicatedSubscriptionException ex) {
throw new InconsistentStateException("Unexpected problem occurred when creating subscription", ex);
Expand All @@ -87,7 +85,7 @@ public ResponseEntity<?> updateSubscription(
if (errors.hasErrors()) {
throw new ValidationException(errors);
}
subscriptionService.updateSubscription(subscriptionId, subscription, getUser(request));
subscriptionService.updateSubscription(subscriptionId, subscription);
return ResponseEntity.noContent().build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import javax.validation.Valid;

import static org.zalando.nakadi.domain.ResourceImpl.ADMIN_RESOURCE;
import static org.zalando.nakadi.util.RequestUtils.getUser;

@RestController
@RequestMapping(value = "/settings")
Expand Down Expand Up @@ -56,7 +55,7 @@ public ResponseEntity blacklist(@PathVariable("blacklist_type") final BlacklistS
if (!adminService.isAdmin(AuthorizationService.Operation.WRITE)) {
throw new ForbiddenOperationException("Admin privileges are required to perform this operation");
}
blacklistService.blacklist(name, blacklistType, getUser(request));
blacklistService.blacklist(name, blacklistType);
return ResponseEntity.noContent().build();
}

Expand All @@ -68,7 +67,7 @@ public ResponseEntity whitelist(@PathVariable("blacklist_type") final BlacklistS
if (!adminService.isAdmin(AuthorizationService.Operation.WRITE)) {
throw new ForbiddenOperationException("Admin privileges are required to perform this operation");
}
blacklistService.whitelist(name, blacklistType, getUser(request));
blacklistService.whitelist(name, blacklistType);
return ResponseEntity.noContent().build();
}

Expand All @@ -88,7 +87,7 @@ public ResponseEntity<?> setFeature(@RequestBody final FeatureToggleService.Feat
if (!adminService.isAdmin(AuthorizationService.Operation.WRITE)) {
throw new ForbiddenOperationException("Admin privileges are required to perform this operation");
}
featureToggleService.setFeature(featureWrapper, getUser(request));
featureToggleService.setFeature(featureWrapper);
return ResponseEntity.noContent().build();
}

Expand All @@ -111,7 +110,7 @@ public ResponseEntity<?> updateAdmins(@Valid @RequestBody final ResourceAuthoriz
if (errors.hasErrors()) {
throw new ValidationException(errors);
}
adminService.updateAdmins(authz.toPermissionsList(ADMIN_RESOURCE), getUser(request));
adminService.updateAdmins(authz.toPermissionsList(ADMIN_RESOURCE));
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.ResponseEntity.status;
import static org.zalando.nakadi.util.RequestUtils.getUser;

@RestController
public class StoragesController {
Expand Down Expand Up @@ -61,7 +60,7 @@ public ResponseEntity<?> createStorage(@RequestBody final String storage,
if (!adminService.isAdmin(AuthorizationService.Operation.WRITE)) {
throw new ForbiddenOperationException("Admin privileges required to perform this operation");
}
storageService.createStorage(new JSONObject(storage), getUser(request));
storageService.createStorage(new JSONObject(storage));
return status(CREATED).build();
}

Expand All @@ -82,7 +81,7 @@ public ResponseEntity<?> deleteStorage(@PathVariable("id") final String id, fina
if (!adminService.isAdmin(AuthorizationService.Operation.WRITE)) {
throw new ForbiddenOperationException("Admin privileges required to perform this operation");
}
storageService.deleteStorage(id, getUser(request));
storageService.deleteStorage(id);
return status(NO_CONTENT).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.ResponseEntity.status;
import static org.zalando.nakadi.util.RequestUtils.getUser;


@RestController
Expand Down Expand Up @@ -66,7 +65,7 @@ public ResponseEntity<?> deleteSubscription(@PathVariable("id") final String sub
final NativeWebRequest request)
throws DbWriteOperationsBlockedException, NoSuchSubscriptionException, NoSuchEventTypeException,
ServiceTemporarilyUnavailableException, InternalNakadiException {
subscriptionService.deleteSubscription(subscriptionId, getUser(request));
subscriptionService.deleteSubscription(subscriptionId);
return status(NO_CONTENT).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.stream.Collectors;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.zalando.nakadi.util.RequestUtils.getUser;

@RestController
@RequestMapping(value = "/event-types/{name}/timelines", produces = APPLICATION_JSON_VALUE)
Expand All @@ -40,7 +39,7 @@ public ResponseEntity<?> createTimeline(@PathVariable("name") final String event
final NativeWebRequest request)
throws AccessDeniedException, TimelineException, TopicRepositoryException, InconsistentStateException,
RepositoryProblemException {
timelineService.createTimeline(eventTypeName, timelineRequest.getStorageId(), getUser(request));
timelineService.createTimeline(eventTypeName, timelineRequest.getStorageId());
return ResponseEntity.status(HttpStatus.CREATED).build();
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/zalando/nakadi/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public List<Permission> getAdmins() {
return addDefaultAdmin(authorizationDbRepository.listAdmins());
}

public void updateAdmins(final List<Permission> newAdmins, final Optional<String> user)
public void updateAdmins(final List<Permission> newAdmins)
throws DbWriteOperationsBlockedException {
if (featureToggleService.isFeatureEnabled(FeatureToggleService.Feature.DISABLE_DB_WRITE_OPERATIONS)) {
throw new DbWriteOperationsBlockedException("Cannot update admins: write operations on DB " +
Expand All @@ -77,8 +77,7 @@ public void updateAdmins(final List<Permission> newAdmins, final Optional<String
Optional.of(ResourceAuthorization.fromPermissionsList(newAdmins)),
NakadiAuditLogPublisher.ResourceType.ADMINS,
NakadiAuditLogPublisher.ActionType.UPDATED,
"-",
user);
"-");
}

public boolean isAdmin(final AuthorizationService.Operation operation) throws PluginException {
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/zalando/nakadi/service/BlacklistService.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Map<String, Map<String, Set<String>>> getBlacklist() {
"apps", getChildren(Type.PRODUCER_APP)));
}

public void blacklist(final String name, final Type type, final Optional<String> user) throws RuntimeException {
public void blacklist(final String name, final Type type) throws RuntimeException {
try {
final boolean oldValue = isBlocked(type, name);

Expand All @@ -128,14 +128,13 @@ public void blacklist(final String name, final Type type, final Optional<String>
Optional.of(newEntry),
NakadiAuditLogPublisher.ResourceType.BLACKLIST_ENTRY,
actionType,
newEntry.getId(),
user);
newEntry.getId());
} catch (final Exception e) {
throw new RuntimeException("Issue occurred while creating node in zk", e);
}
}

public void whitelist(final String name, final Type type, final Optional<String> user) throws RuntimeException {
public void whitelist(final String name, final Type type) throws RuntimeException {
try {
final CuratorFramework curator = zooKeeperHolder.get();
final String path = createBlacklistEntryPath(name, type);
Expand All @@ -148,8 +147,7 @@ public void whitelist(final String name, final Type type, final Optional<String>
Optional.empty(),
NakadiAuditLogPublisher.ResourceType.BLACKLIST_ENTRY,
NakadiAuditLogPublisher.ActionType.DELETED,
entry.getId(),
user);
entry.getId());
}
} catch (final Exception e) {
throw new RuntimeException("Issue occurred while deleting node from zk", e);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/zalando/nakadi/service/CursorsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public List<SubscriptionCursorWithoutToken> getSubscriptionCursors(final String
return cursorsListBuilder.build();
}

public void resetCursors(final String subscriptionId, final List<NakadiCursor> cursors, final Optional<String> user)
public void resetCursors(final String subscriptionId, final List<NakadiCursor> cursors)
throws ServiceTemporarilyUnavailableException, NoSuchSubscriptionException,
UnableProcessException, OperationTimeoutException, ZookeeperException,
InternalNakadiException, NoSuchEventTypeException, InvalidCursorException {
Expand Down Expand Up @@ -207,8 +207,7 @@ public void resetCursors(final String subscriptionId, final List<NakadiCursor> c
Optional.of(new ItemsWrapper<>(newCursors)),
NakadiAuditLogPublisher.ResourceType.CURSORS,
NakadiAuditLogPublisher.ActionType.UPDATED,
subscriptionId,
user);
subscriptionId);
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/zalando/nakadi/service/EventTypeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public List<EventType> list() {
return eventTypeRepository.list();
}

public void create(final EventTypeBase eventType, final Optional<String> user)
public void create(final EventTypeBase eventType)
throws TopicCreationException,
InternalNakadiException,
NoSuchPartitionStrategyException,
Expand Down Expand Up @@ -182,7 +182,7 @@ public void create(final EventTypeBase eventType, final Optional<String> user)

nakadiAuditLogPublisher.publish(Optional.empty(), Optional.of(eventType),
NakadiAuditLogPublisher.ResourceType.EVENT_TYPE, NakadiAuditLogPublisher.ActionType.CREATED,
eventType.getName(), user);
eventType.getName());
}

private void validateCompaction(final EventTypeBase eventType) throws
Expand Down Expand Up @@ -219,7 +219,7 @@ private void setDefaultEventTypeOptions(final EventTypeBase eventType) {
}
}

public void delete(final String eventTypeName, final Optional<String> user) throws EventTypeDeletionException,
public void delete(final String eventTypeName) throws EventTypeDeletionException,
AccessDeniedException, NoSuchEventTypeException, ConflictException, ServiceTemporarilyUnavailableException,
DbWriteOperationsBlockedException {
if (featureToggleService.isFeatureEnabled(FeatureToggleService.Feature.DISABLE_DB_WRITE_OPERATIONS)) {
Expand Down Expand Up @@ -287,7 +287,7 @@ public void delete(final String eventTypeName, final Optional<String> user) thro

nakadiAuditLogPublisher.publish(Optional.of(eventType), Optional.empty(),
NakadiAuditLogPublisher.ResourceType.EVENT_TYPE, NakadiAuditLogPublisher.ActionType.DELETED,
eventType.getName(), user);
eventType.getName());
}

private Multimap<TopicRepository, String> deleteEventTypeIfNoSubscriptions(final String eventType) {
Expand Down Expand Up @@ -325,8 +325,7 @@ private boolean hasSubscriptions(final String eventTypeName) {
}

public void update(final String eventTypeName,
final EventTypeBase eventTypeBase,
final Optional<String> user)
final EventTypeBase eventTypeBase)
throws TopicConfigException,
InconsistentStateException,
NakadiRuntimeException,
Expand Down Expand Up @@ -388,7 +387,7 @@ public void update(final String eventTypeName,

nakadiAuditLogPublisher.publish(Optional.of(original), Optional.of(eventType),
NakadiAuditLogPublisher.ResourceType.EVENT_TYPE, NakadiAuditLogPublisher.ActionType.UPDATED,
eventType.getName(), user);
eventType.getName());
}

private void updateRetentionTime(final EventType original, final EventType eventType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
public interface FeatureToggleService {

void setFeature(FeatureWrapper feature, Optional<String> user);
void setFeature(FeatureWrapper feature);

boolean isFeatureEnabled(Feature feature);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean isFeatureEnabled(final Feature feature) {
}
}

public void setFeature(final FeatureWrapper feature, final Optional<String> user) {
public void setFeature(final FeatureWrapper feature) {
try {
final boolean oldState = isFeatureEnabled(feature.getFeature());
final CuratorFramework curator = zkHolder.get();
Expand All @@ -75,8 +75,7 @@ public void setFeature(final FeatureWrapper feature, final Optional<String> user
Optional.of(feature),
NakadiAuditLogPublisher.ResourceType.FEATURE,
NakadiAuditLogPublisher.ActionType.UPDATED,
feature.getFeature().getId(),
user);
feature.getFeature().getId());
}
} catch (final KeeperException.NoNodeException nne) {
LOG.debug("Feature {} was already disabled", feature.getFeature().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.zalando.nakadi.exceptions.runtime.NakadiBaseException;

import java.io.IOException;
import java.util.Optional;

@Component
@ConfigurationProperties(prefix = "nakadi.audit")
Expand Down Expand Up @@ -62,7 +61,7 @@ public void onApplicationEvent(final ContextRefreshedEvent event) throws IOExcep
final EventTypeBase eventType = objectMapper.readValue(auditEventTypeString, typeReference);

try {
eventTypeService.create(eventType, Optional.of(owningApplication));
eventTypeService.create(eventType);
} catch (final DuplicatedEventTypeNameException e) {
LOG.debug("Audit event type already exists " + eventType.getName());
} catch (final NakadiBaseException e) {
Expand Down
Loading

0 comments on commit e268a28

Please sign in to comment.