All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hawt.springboot.ExposedEndpoint Maven / Gradle / Ivy

The newest version!
package io.hawt.springboot;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class ExposedEndpoint implements Condition {

    private static final String WEB_EXPOSURE_INCLUDE = "management.endpoints.web.exposure.include";
    private static final Bindable> STRING_LIST = Bindable.listOf(String.class);

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Map attributes = metadata.getAnnotationAttributes(ConditionalOnExposedEndpoint.class.getName());

        if (attributes != null) {
            String endpointName = (String) attributes.get("name");
            Environment environment = context.getEnvironment();
            BindResult> property = Binder.get(environment).bind(WEB_EXPOSURE_INCLUDE, STRING_LIST);
            List exposedEndpoints = property.orElse(Collections.emptyList());
            return exposedEndpoints.contains(endpointName) || exposedEndpoints.contains("*");
        }

        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy