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

cn.bestwu.api.sign.ApiSignConfiguration Maven / Gradle / Ivy

package cn.bestwu.api.sign;

import org.springframework.aop.SpringProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration;

/**
 * 接口签名 自动配置
 *
 * @author Peter Wu
 */
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass({ SpringProxy.class })
@ConditionalOnProperty(prefix = "api.sign", name = "enabled", havingValue = "true")
@EnableConfigurationProperties({ ApiSignProperties.class })
public class ApiSignConfiguration {
	@Autowired
	private ApiSignProperties properties;

	/**
	 * @return 签名验证切面
	 */
	@Bean
	@Order(Ordered.HIGHEST_PRECEDENCE + 11)
	public ApiSignAspect apiSignAspect() {
		ApiSignAspect apiSignAspect = new ApiSignAspect();
		apiSignAspect.setSignMode(properties.getSignMode());
		apiSignAspect.setSignParameter(properties.getSignParameter());
		apiSignAspect.setSkipAdmin(properties.isSkipAdmin());
		return apiSignAspect;
	}

	/**
	 * @return 默认签名算法
	 */
	@Bean
	@ConditionalOnMissingBean(ApiSignAdpter.class)
	@ConditionalOnBean(AuthorizationServerEndpointsConfiguration.class)
	public DefaultApiSign defaultApiSign() {
		return new DefaultApiSign();
	}

	/**
	 * @return 网站管理员签名计算接口
	 */
	@Bean
	public ApiSignEndpoint apiSignEndpoint() {
		return new ApiSignEndpoint(properties);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy