package org.zalando.nakadi.plugin.auth;

import org.springframework.security.core.context.SecurityContextHolder;
import org.zalando.nakadi.plugin.api.PluginException;
import org.zalando.nakadi.plugin.api.authz.AuthorizationAttribute;
import org.zalando.nakadi.plugin.api.authz.AuthorizationService;
import org.zalando.nakadi.plugin.api.authz.Resource;
import org.zalando.nakadi.plugin.api.authz.Subject;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;

public class DefaultAuthorizationService implements AuthorizationService {

    @Override
    public boolean isAuthorized(final Operation operation, final Resource resource) {
        return true;
    }

    @Override
    public boolean isAuthorizationAttributeValid(final AuthorizationAttribute authorizationAttribute) {
        return true;
    }

    @Override
    @Nullable
    public Optional<Subject> getSubject() {
        return Optional.of(() -> SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
    }

    @Override
    public List<Resource> filter(final List<Resource> input) throws PluginException {
        return input;
    }
}

@@ -432,16 +432,48 @@
 llable;%0A
+import java.security.Principal;%0A
 import j
@@ -968,14 +968,51 @@
 .of(
-() -%3E 
+%0A                () -%3E Optional.ofNullable(
 Secu
@@ -1065,33 +1065,70 @@
 on()
-.getPrincipal().toString(
+)%0A                        .map(Principal::getName).orElse(null
 ));%0A

Fix tests