REM:
1. 移动认证接口配置
This commit is contained in:
HuangXin 2021-09-15 16:24:41 +08:00
parent 5af36c1ac3
commit 61dee2a42b
1 changed files with 70 additions and 71 deletions

View File

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