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

org.swiftboot.auth.SwiftbootAuthConfig Maven / Gradle / Ivy

The newest version!
package org.swiftboot.auth;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.swiftboot.auth.filter.AuthFilter;
import org.swiftboot.auth.interceptor.UserSessionArgumentResolver;
import org.swiftboot.auth.service.SessionService;
import org.swiftboot.auth.service.impl.MockSessionServiceImpl;
import org.swiftboot.auth.service.impl.SessionServiceRedisImpl;
import org.swiftboot.service.service.RedisService;

import java.util.List;

/**
 * @author swiftech 2019-05-24
 **/
@Configuration
@EnableConfigurationProperties
@Order(2)
public class SwiftbootAuthConfig implements WebMvcConfigurer {

    @Bean
    @ConditionalOnProperty(value = "swiftboot.auth.enabled", havingValue = "true")
    public AuthFilter authFilter() {
        return new AuthFilter();
    }

    /**
     * 只有配置为 redis 存储会话才会加载
     *
     * @return
     */
    @Bean
    @ConditionalOnBean(RedisService.class)
    @ConditionalOnProperty(value = "swiftboot.auth.session.type", havingValue = "redis")
    public SessionService redisSessionService() {
        return new SessionServiceRedisImpl();
    }

    /**
     * 默认的会话管理
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(SessionService.class)
    public SessionService mockSessionService() {
        return new MockSessionServiceImpl();
    }

    @Bean
    public UserSessionArgumentResolver userSessionArgumentResolver() {
        return new UserSessionArgumentResolver();
    }

    @Override
    public void addArgumentResolvers(List resolvers) {
        resolvers.add(userSessionArgumentResolver());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy