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.security.Principal;
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(
                () -> Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())
                        .map(Principal::getName).orElse("unauthorized"));
    }

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

@@ -38,80 +38,8 @@
 h;%0A%0A
-import org.springframework.security.core.context.SecurityContextHolder;%0A
 impo
@@ -88,16 +88,16 @@
 eption;%0A
+
 import o
@@ -364,40 +364,8 @@
 le;%0A
-import java.security.Principal;%0A
 impo
@@ -861,181 +861,14 @@
 nal.
-of(%0A                () -%3E Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())%0A                        .map(Principal::getName).orElse(%22unauthorized%22)
+empty(
 );%0A 

Use Optional.empty()