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

shz.auth.AuthAutoConfiguration Maven / Gradle / Ivy

package shz.auth;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import shz.api.server.ApiDetail;
import shz.api.server.entity.SysApi;
import shz.auth.filter.AbstractApiFilter;
import shz.auth.filter.VisitFilter;
import shz.auth.listener.VisitListener;
import shz.core.Help;

import javax.servlet.DispatcherType;

@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(AbstractApiFilter.class)
class AuthAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(VisitListener.class)
    VisitListener visitListener() {
        return new VisitListener();
    }

    @Bean
    ServletListenerRegistrationBean visitListenerRegistrationBean(VisitListener visitListener) {
        ServletListenerRegistrationBean slrb = new ServletListenerRegistrationBean<>();
        slrb.setOrder(Ordered.HIGHEST_PRECEDENCE);
        slrb.setListener(visitListener);
        return slrb;
    }

    @Bean
    @ConditionalOnMissingBean(VisitFilter.class)
    VisitFilter visitFilter() {
        return new VisitFilter();
    }

    @Bean
    FilterRegistrationBean visitFilterRegistrationBean(VisitFilter visitFilter) {
        FilterRegistrationBean frb = new FilterRegistrationBean<>();
        frb.setOrder(visitFilter.order());
        frb.setFilter(visitFilter);
        frb.setName(Help.pojo(visitFilter.getClass().getSimpleName()));
        frb.addUrlPatterns("/*");
        frb.setDispatcherTypes(DispatcherType.REQUEST);
        return frb;
    }

    @Bean
     FilterRegistrationBean> apiFilterRegistrationBean(AbstractApiFilter apiFilter) {
        FilterRegistrationBean> frb = new FilterRegistrationBean<>();
        frb.setOrder(apiFilter.order());
        frb.setFilter(apiFilter);
        frb.setName(Help.pojo(apiFilter.getClass().getSimpleName()));
        frb.addUrlPatterns("/*");
        frb.setDispatcherTypes(DispatcherType.REQUEST);
        return frb;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy