parent
5af36c1ac3
commit
61dee2a42b
|
@ -1,71 +1,70 @@
|
||||||
package com.dispose.config;
|
package com.dispose.interceptor;
|
||||||
|
|
||||||
import com.dispose.common.AuthConfigValue;
|
import com.dispose.common.AuthConfigValue;
|
||||||
import com.dispose.interceptor.TokenInterceptor;
|
import lombok.Getter;
|
||||||
import lombok.Getter;
|
import lombok.Setter;
|
||||||
import lombok.Setter;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PostConstruct;
|
import java.util.Optional;
|
||||||
import java.util.Optional;
|
|
||||||
|
/**
|
||||||
/**
|
* The type Auth configure.
|
||||||
* The type Auth configure.
|
*
|
||||||
*
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
* @author <huangxin@cmhi.chinamoblie.com>
|
*/
|
||||||
*/
|
@Getter
|
||||||
@Getter
|
@Setter
|
||||||
@Setter
|
@Component
|
||||||
@Component
|
@ConfigurationProperties(prefix = "auth")
|
||||||
@ConfigurationProperties(prefix = "auth")
|
@Configuration
|
||||||
@Configuration
|
public class AuthConfigureFilter implements WebMvcConfigurer {
|
||||||
public class AuthConfigure implements WebMvcConfigurer {
|
/**
|
||||||
/**
|
* The Token timeout minute.
|
||||||
* The Token timeout minute.
|
*/
|
||||||
*/
|
private Long tokenTimeoutMinute;
|
||||||
private Long tokenTimeoutMinute;
|
|
||||||
|
/**
|
||||||
/**
|
* The Verify request token.
|
||||||
* The Verify request token.
|
*/
|
||||||
*/
|
private Boolean verifyRequestToken;
|
||||||
private Boolean verifyRequestToken;
|
|
||||||
|
/**
|
||||||
/**
|
* Init global value.
|
||||||
* Init global value.
|
*/
|
||||||
*/
|
@PostConstruct
|
||||||
@PostConstruct
|
private void initGlobalValue() {
|
||||||
private void initGlobalValue() {
|
AuthConfigValue.TOKEN_EXPIRED_TIME_MS =
|
||||||
AuthConfigValue.TOKEN_EXPIRED_TIME_MS =
|
Optional.of(tokenTimeoutMinute * 60 * 1000).orElse((long) 30 * 60 * 1000);
|
||||||
Optional.of(tokenTimeoutMinute * 60 * 1000).orElse((long) 30 * 60 * 1000);
|
AuthConfigValue.VERIFY_REQUEST_TOKEN = Optional.ofNullable(verifyRequestToken).orElse(true);
|
||||||
AuthConfigValue.VERIFY_REQUEST_TOKEN = Optional.ofNullable(verifyRequestToken).orElse(true);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Init auth interceptor token interceptor.
|
||||||
* Init auth interceptor token interceptor.
|
*
|
||||||
*
|
* @return the token interceptor
|
||||||
* @return the token interceptor
|
*/
|
||||||
*/
|
@Bean
|
||||||
@Bean
|
public TokenInterceptor initAuthInterceptor() {
|
||||||
public TokenInterceptor initAuthInterceptor() {
|
return new TokenInterceptor();
|
||||||
return new TokenInterceptor();
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Add interceptors.
|
||||||
* Add interceptors.
|
*
|
||||||
*
|
* @param registry the registry
|
||||||
* @param registry the registry
|
*/
|
||||||
*/
|
@Override
|
||||||
@Override
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
// 注册需要检查token的控制器接口
|
||||||
// 注册需要检查token的控制器接口
|
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/auth/logout");
|
||||||
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/auth/logout");
|
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/manager/**");
|
||||||
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/manager/**");
|
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/task/**");
|
||||||
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/task/**");
|
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/info/**");
|
||||||
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/info/**");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
Loading…
Reference in New Issue