Commit 96b0cb13 by stylefeng

增加rest模块对auth和sign的开关,方便开发时联调

parent 4de73800
package com.stylefeng.guns.rest.config;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import com.stylefeng.guns.core.config.DefaultFastjsonConfig;
import com.stylefeng.guns.rest.config.properties.RestProperties;
import com.stylefeng.guns.rest.modular.auth.converter.WithSignMessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -15,6 +18,7 @@ import org.springframework.context.annotation.Configuration;
public class MessageConverConfig {
@Bean
@ConditionalOnProperty(prefix = RestProperties.REST_PREFIX, name = "sign-open", havingValue = "true", matchIfMissing = true)
public WithSignMessageConverter withSignMessageConverter() {
WithSignMessageConverter withSignMessageConverter = new WithSignMessageConverter();
DefaultFastjsonConfig defaultFastjsonConfig = new DefaultFastjsonConfig();
......@@ -22,4 +26,14 @@ public class MessageConverConfig {
withSignMessageConverter.setSupportedMediaTypes(defaultFastjsonConfig.getSupportedMediaType());
return withSignMessageConverter;
}
@Bean
@ConditionalOnProperty(prefix = RestProperties.REST_PREFIX, name = "sign-open", havingValue = "false")
public FastJsonHttpMessageConverter4 fastJsonHttpMessageConverter4() {
FastJsonHttpMessageConverter4 FastJsonHttpMessageConverter4 = new FastJsonHttpMessageConverter4();
DefaultFastjsonConfig defaultFastjsonConfig = new DefaultFastjsonConfig();
FastJsonHttpMessageConverter4.setFastJsonConfig(defaultFastjsonConfig.fastjsonConfig());
FastJsonHttpMessageConverter4.setSupportedMediaTypes(defaultFastjsonConfig.getSupportedMediaType());
return FastJsonHttpMessageConverter4;
}
}
package com.stylefeng.guns.rest.config;
import com.stylefeng.guns.rest.config.properties.RestProperties;
import com.stylefeng.guns.rest.modular.auth.filter.AuthFilter;
import com.stylefeng.guns.rest.modular.auth.security.DataSecurityAction;
import com.stylefeng.guns.rest.modular.auth.security.impl.Base64SecurityAction;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -16,6 +18,7 @@ import org.springframework.context.annotation.Configuration;
public class WebConfig {
@Bean
@ConditionalOnProperty(prefix = RestProperties.REST_PREFIX, name = "auth-open", havingValue = "true", matchIfMissing = true)
public AuthFilter jwtAuthenticationTokenFilter() {
return new AuthFilter();
}
......
package com.stylefeng.guns.rest.config.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* 项目相关配置
*
* @author fengshuonan
* @date 2017年10月23日16:44:15
*/
@Configuration
@ConfigurationProperties(prefix = RestProperties.REST_PREFIX)
public class RestProperties {
public static final String REST_PREFIX = "rest";
private boolean authOpen = true;
private boolean signOpen = true;
public boolean isAuthOpen() {
return authOpen;
}
public void setAuthOpen(boolean authOpen) {
this.authOpen = authOpen;
}
public boolean isSignOpen() {
return signOpen;
}
public void setSignOpen(boolean signOpen) {
this.signOpen = signOpen;
}
}
rest:
auth-open: false #jwt鉴权机制是否开启(true或者false)
sign-open: false #签名机制是否开启(true或false)
jwt:
header: Authorization #http请求头所需要的字段
secret: mySecret #jwt秘钥
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment