Commit a6f8d1fb by 张爱江

add publick-base

parent a2fc5cf3
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
/mvnw
/mvnw.cmd
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>ydl-public-base-api</module>
<module>ydl-public-base-service</module>
<module>ydl-public-base-inf</module>
</modules>
<parent>
<groupId>com.ydl</groupId>
<artifactId>ydl-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<groupId>com.ydl</groupId>
<artifactId>ydl-public-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ydl-public-base</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<ydl.common.version>3.0.0-SNAPSHOT</ydl.common.version>
</properties>
<dependencies>
<dependency>
<groupId>com.ydl</groupId>
<artifactId>ydl-common</artifactId>
<version>${ydl.common.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.ydl</groupId>
<artifactId>ydl-common</artifactId>
<version>${ydl.common.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ydl-public-base</artifactId>
<groupId>com.ydl</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ydl-public-base-api</artifactId>
<dependencies>
<dependency>
<groupId>com.ydl</groupId>
<artifactId>ydl-public-base-inf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>soul-common</artifactId>
<groupId>org.dromara</groupId>
</exclusion>
<exclusion>
<artifactId>soul-web</artifactId>
<groupId>org.dromara</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- 支持 @ConfigurationProperties 注解 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!-- 导入Dubbo jar包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.2</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.ydl.auth;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.ydl.auth.apis"))
.paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfoBuilder().title("壹点灵服务端接口文档").description("壹点灵接口管理").license("MIT").licenseUrl("http://opensource.org/licenses/MIT")
.contact(new Contact("", "", "")).version("1.0").build();
return apiInfo;
}
}
\ No newline at end of file
package com.ydl.auth;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@Slf4j
@ComponentScan({ "com.ydl" })
@EnableScheduling
public class YdlAuthApplication {
public static void main(String[] args) {
try {
SpringApplication.run(YdlAuthApplication.class, args);
} catch (Throwable e) {
log.error("",e);
}
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ydl.auth.apis;
/**
* Constants.
*
* @author xiaoyu(Myth)
*/
public interface Constants {
/**
* The constant APP_PARAM.
*/
String APP_PARAM = "appParam";
/**
* The constant REQUESTDTO.
*/
String REQUESTDTO = "requestDTO";
/**
* The constant CLIENT_RESPONSE_ATTR.
*/
String CLIENT_RESPONSE_ATTR = "webHandlerClientResponse";
/**
* The constant DUBBO_RPC_RESULT.
*/
String DUBBO_RPC_RESULT = "dubbo_rpc_result";
/**
* The constant DUBBO_RPC_RESULT_EMPTY.
*/
String DUBBO_RPC_RESULT_EMPTY = "dubbo has not return value!";
/**
* The constant CLIENT_RESPONSE_RESULT_TYPE.
*/
String CLIENT_RESPONSE_RESULT_TYPE = "webHandlerClientResponseResultType";
/**
* The constant CLIENT_RESPONSE_CONN_ATTR.
*/
String CLIENT_RESPONSE_CONN_ATTR = "nettyClientResponseConnection";
/**
* The constant HTTP_TIME_OUT.
*/
String HTTP_TIME_OUT = "httpTimeOut";
/**
* Original response Content-Type attribute name.
*/
String ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR = "original_response_content_type";
/**
* The constant HTTP_URL.
*/
String HTTP_URL = "httpUrl";
/**
* The constant DUBBO_PARAMS.
*/
String DUBBO_PARAMS = "dubbo_params";
/**
* The constant DECODE.
*/
String DECODE = "UTF-8";
/**
* The constant MODULE.
*/
String MODULE = "module";
/**
* The constant METHOD.
*/
String METHOD = "method";
/**
* The constant APP_KEY.
*/
String APP_KEY = "appKey";
/**
* The constant EXT_INFO.
*/
String EXT_INFO = "extInfo";
/**
* The constant PATH_VARIABLE.
*/
String PATH_VARIABLE = "pathVariable";
/**
* The constant HTTP_METHOD.
*/
String HTTP_METHOD = "httpMethod";
/**
* The constant RPC_TYPE.
*/
String RPC_TYPE = "rpcType";
/**
* The constant SIGN.
*/
String SIGN = "sign";
/**
* The constant PATH.
*/
String PATH = "path";
/**
* The constant VERSION.
*/
String VERSION = "version";
/**
* The constant SIGN_PARAMS_ERROR.
*/
String SIGN_PARAMS_ERROR = "认证参数传入不完整!";
/**
* The constant SIGN_APP_KEY_IS_NOT_EXIST.
*/
String SIGN_APP_KEY_IS_NOT_EXIST = "认证签名APP_KEY,不存在";
/**
* The constant SIGN_PATH_NOT_EXIST.
*/
String SIGN_PATH_NOT_EXIST = "认证Key未配置路径获取未匹配";
/**
* The constant SIGN_VALUE_IS_ERROR.
*/
String SIGN_VALUE_IS_ERROR = "签名值错误!";
/**
* The constant TIMESTAMP.
*/
String TIMESTAMP = "timestamp";
/**
* The constant REJECT_MSG.
*/
String REJECT_MSG = " You are forbidden to visit";
/**
* The constant REWRITE_URI.
*/
String REWRITE_URI = "rewrite_uri";
/**
* The constant HTTP_ERROR_RESULT.
*/
String HTTP_ERROR_RESULT = "this is bad request or fuse ing please try again later";
/**
* The constant DUBBO_ERROR_RESULT.
*/
String DUBBO_ERROR_RESULT = "dubbo rpc have error or fuse ing please check your param and try again later";
/**
* The constant SPRING_CLOUD_ERROR_RESULT.
*/
String SPRING_CLOUD_ERROR_RESULT = "spring cloud rpc have error or fuse ing please check your param and try again later";
/**
* The constant TIMEOUT_RESULT.
*/
String TIMEOUT_RESULT = "this request is time out Please try again later";
/**
* The constant UPSTREAM_NOT_FIND.
*/
String UPSTREAM_NOT_FIND = "this can not rule upstream please check you configuration!";
/**
* The constant TOO_MANY_REQUESTS.
*/
String TOO_MANY_REQUESTS = "the request is too fast please try again later";
/**
* The constant SIGN_IS_NOT_PASS.
*/
String SIGN_IS_NOT_PASS = "sign is not pass,Please check you sign algorithm!";
/**
* The constant LINE_SEPARATOR.
*/
String LINE_SEPARATOR = System.getProperty("line.separator");
/**
* hystrix withExecutionIsolationSemaphoreMaxConcurrentRequests.
*/
int MAX_CONCURRENT_REQUESTS = 100;
/**
* hystrix withCircuitBreakerErrorThresholdPercentage.
*/
int ERROR_THRESHOLD_PERCENTAGE = 50;
/**
* hystrix withCircuitBreakerRequestVolumeThreshold.
*/
int REQUEST_VOLUME_THRESHOLD = 20;
/**
* hystrix withCircuitBreakerSleepWindowInMilliseconds.
*/
int SLEEP_WINDOW_INMILLISECONDS = 5000;
/**
* The constant TIME_OUT.
*/
long TIME_OUT = 3000;
/**
* The constant COLONS.
*/
String COLONS = ":";
}
package com.ydl.auth.apis;
import com.alibaba.dubbo.config.annotation.Reference;
import com.google.common.collect.Maps;
import com.ydl.auth.dto.AccessRequestDto;
import com.ydl.auth.dto.RequestDTO;
import com.ydl.auth.inf.AppAuthFacade;
import com.ydl.auth.inf.ComOssFacade;
import com.ydl.common.dto.BaseDtoResponse;
import com.ydl.common.helper.ResponseFormatterHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "/sign")
@Api(description = "获取签名")
public class SignController {
@Reference(version = "1.0.0")
private AppAuthFacade appAuthFacade;
@Reference(version = "1.0.0")
private ComOssFacade comOssFacade;
@RequestMapping(value = "/getAccessKey", method = RequestMethod.POST)
@ApiOperation(value = "获取验签")
public BaseDtoResponse<String> getAccessKey(@RequestBody AccessRequestDto requestDto) throws Exception {
String appSecret = appAuthFacade.getSecretByAppKey(requestDto.getAppKey());
Long timeStamp = System.currentTimeMillis();
String version = "1.0.0";
Map<String,String> paramMap = new HashMap<>();
paramMap.put("timestamp",timeStamp+"");
paramMap.put("path",requestDto.getPath());
paramMap.put("version",version);
String sign = generateSign(appSecret,paramMap);
return ResponseFormatterHelper.success(sign);
}
@RequestMapping(value = "/get-temporary-url", method = RequestMethod.GET)
@ApiOperation(value = "获取临时地址")
public BaseDtoResponse<String> getTemporaryUrlByOriginalUrl(@RequestParam(value = "originalUrl",required = true) String originalUrl){
return comOssFacade.getTemporaryUrlByOriginalUrl(originalUrl);
}
@RequestMapping(value = "/get-temporary-url-bath", method = RequestMethod.GET)
@ApiOperation(value = "批量获取临时地址")
public BaseDtoResponse<List<String>> getBathTemporaryUrlByOriginalUrl(@RequestParam(value = "urls",required = true) List<String> originalUrls){
return comOssFacade.getBathTemporaryUrlByOriginalUrl(originalUrls);
}
public String generateSign( String signKey, Map<String, String> params) {
List<String> storedKeys = Arrays.stream(params.keySet()
.toArray(new String[]{}))
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());
final String sign = storedKeys.stream()
.filter(key -> !Objects.equals(key, Constants.SIGN))
.map(key -> String.join("", key, params.get(key)))
.collect(Collectors.joining()).trim()
.concat(signKey);
return DigestUtils.md5DigestAsHex(sign.getBytes()).toUpperCase();
}
private Map<String, String> buildParamsMap(final RequestDTO dto) {
Map<String, String> map = Maps.newHashMapWithExpectedSize(3);
map.put(Constants.TIMESTAMP, dto.getTimestamp());
map.put(Constants.PATH, dto.getPath());
map.put(Constants.VERSION, "1.0.0");
return map;
}
}
package com.ydl.auth.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.Serializable;
@Data
public class AccessRequestDto implements Serializable {
@ApiModelProperty(value = "appKey",required = true)
private String appKey;
@ApiModelProperty(value = "path",required = true)
private String path;
}
package com.ydl.auth.dto;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* the soul request DTO .
*
* @author xiaoyu(Myth)
*/
@Data
public class RequestDTO implements Serializable {
/**
* is module data.
*/
private String module;
/**
* is method name .
*/
private String method;
private String httpMethod;
/**
* this is sign .
*/
private String sign;
/**
* timestamp .
*/
private String timestamp;
/**
* appKey .
*/
private String appKey;
/**
* path.
*/
private String path;
/**
* the contextPath.
*/
private String contextPath;
/**
* realUrl.
*/
private String realUrl;
/**
* this is dubbo params.
*/
private String dubboParams;
/**
* startDateTime.
*/
private LocalDateTime startDateTime;
}
server:
port: 8089
servlet:
context-path: /ydlAuth
spring:
profiles:
active: local
application:
name: ydl-auth-security-api
logging:
file: /opt/release/logs/test/${spring.application.name}-DEBUG.log
level:
root: debug
com.ydl: debug
web: debug
---
spring:
profiles: local
dubbo:
application:
name: ydl-auth-security-api
registry:
id: zookeeper
address: zookeeper://127.0.0.1:2181
#address: zookeeper://47.97.49.44:2181?backup=47.97.49.44:2182,47.97.49.44:2183
protocol: zookeeper
---
spring:
profiles: dev
dubbo:
application:
name: ydl-auth-security-api
registry:
id: zookeeper
#address: zookeeper://127.0.0.1:2181
address: zookeeper://47.97.49.44:2181?backup=47.97.49.44:2182,47.97.49.44:2183
#address: zookeeper://172.16.1.34:2181?backup=172.16.226.95:2181,172.16.197.219:2181
protocol: zookeeper
kafka:
producer:
servers: 47.111.174.49:9091
---
spring:
profiles: pre
dubbo:
application:
name: ydl-auth-security-api
registry:
id: zookeeper
address: zookeeper://172.16.1.34:2181?backup=172.16.226.95:2181,172.16.197.219:2181
protocol: zookeeper
---
spring:
profiles: prod
dubbo:
application:
name: ydl-auth-security-api
registry:
id: zookeeper
address: zookeeper://172.16.1.34:2181?backup=172.16.226.95:2181,172.16.197.219:2181
protocol: zookeeper
logging:
file: /opt/release/logs/prod/${spring.application.name}-DEBUG.log
level:
root: debug
com.ydl: debug
web: debug
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ydl-public-base</artifactId>
<groupId>com.ydl</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ydl-public-base-inf</artifactId>
</project>
\ No newline at end of file
package com.ydl.auth.inf;
public interface AppAuthFacade {
String getSecretByAppKey(String appKey);
}
package com.ydl.auth.inf;
import com.ydl.common.dto.BaseDtoResponse;
import java.util.List;
/**
* @program ydl-auth
* @description: ComOssFacade
* @author: wangjianfeng
* @create: 2020/03/03 18:30
*/
public interface ComOssFacade {
public BaseDtoResponse<String> getTemporaryUrlByOriginalUrl(String originalUrl);
public BaseDtoResponse<List<String>> getBathTemporaryUrlByOriginalUrl(List<String> originalUrls);
}
package com.ydl.auth.po;
import lombok.Data;
@Data
public class AppAuth {
private Long id;
private String appKey;
private String appSecret;
private String userId;
private String phone;
private String extInfo;
private Byte enabled;
private Long dateCreated;
private Long dateUpdated;
}
package com.ydl.auth.po.rsp;
import lombok.Data;
import java.io.Serializable;
@Data
public class AppAuthRsp implements Serializable {
private Long id;
private String appKey;
private String appSecret;
private String userId;
private String phone;
private String extInfo;
private Byte enabled;
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ydl-public-base</artifactId>
<groupId>com.ydl</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ydl-public-base-service</artifactId>
<dependencies>
<dependency>
<groupId>com.ydl</groupId>
<artifactId>ydl-public-base-inf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!--mybatis依赖-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>3.4.0</version>
<exclusions>
<exclusion>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-ram</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-sts</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-ecs</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>[7.2.0, 7.2.99]</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>happy-dns-java</artifactId>
<version>0.1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ydl</groupId>
<artifactId>ydl-dbprovider</artifactId>
<version>2.0.3-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.ydl.auth.service;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@Slf4j
@ComponentScan({ "com.ydl" })
@EnableScheduling
@EnableDubbo
public class YdlAuthServiceApplication {
public static void main(String[] args) {
try {
SpringApplication.run(YdlAuthServiceApplication.class, args);
} catch (Throwable e) {
log.error("",e);
}
}
}
\ No newline at end of file
package com.ydl.auth.service.beans;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.Serializable;
/**
* @program ydl-auth
* @description: ossProperties
* @author: wangjianfeng
* @create: 2020/03/03 18:19
*/
@Component
@Data
public class OssProperties implements Serializable {
@Value("${alioss.key.accessKeyId}")
private String aliossKeyAccessKeyId;
@Value("${alioss.key.accessKeySecret}")
private String aliossKeyAccessKeySecret;
@Value("${alioss.endpoint}")
private String aliossEndpoint;
@Value("${alioss.bucketName}")
private String aliossBucketName;
@Value("${yp.host}")
private String ypHost;
@Value("${yp.secret}")
private String ypSecret;
@Value("${qnoss.key.accessKey}")
private String qnossKeyAccessKey;
@Value("${qnoss.key.secretKey}")
private String qnossKeySecretKey;
@Value("${alioss.host}")
private String aliossHost;
@Value("${qnoss.key.domainOfBucket}")
private String qnossKeyDomainOfBucket;
}
package com.ydl.auth.service.biz;
public interface AppAuthBiz {
String getSecretByAppKey(String appKey);
}
package com.ydl.auth.service.biz.impl;
import com.ydl.auth.service.biz.AppAuthBiz;
import com.ydl.auth.service.dao.AppAuthMapper;
import com.ydl.auth.po.AppAuth;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
@Service
public class AppAuthBizImpl implements AppAuthBiz {
@Resource
private AppAuthMapper mapper;
@Override
public String getSecretByAppKey(String appKey) {
Example example = new Example(AppAuth.class);
example.createCriteria().andEqualTo("appKey",appKey);
AppAuth appAuth = mapper.selectOneByExample(example);
return appAuth==null?"":appAuth.getAppSecret();
}
}
package com.ydl.auth.service.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.google.common.collect.Sets;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.apache.ibatis.session.AutoMappingBehavior;
import org.apache.ibatis.session.AutoMappingUnknownColumnBehavior;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.LocalCacheScope;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import tk.mybatis.spring.annotation.MapperScan;
import java.io.IOException;
@Configuration
@MapperScan("com.ydl.*.service.dao")
public class MybatisConfig {
@Bean
public SqlSessionFactoryBean sqlSessionFactoryBean(DruidDataSource druidDataSource,
org.apache.ibatis.session.Configuration configuration) throws IOException {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(druidDataSource);
sqlSessionFactoryBean.setConfiguration(configuration);
sqlSessionFactoryBean.setTypeAliasesPackage("com.ydl.**.po");
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources("classpath*:sqlmap/*Mapper.xml"));
return sqlSessionFactoryBean;
}
/**
* 部分配置,
* 配置详解:http://www.mybatis.org/mybatis-3/zh/configuration.html
*
* @return
*/
@Bean
public org.apache.ibatis.session.Configuration properties() {
org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
configuration.setCacheEnabled(false);
configuration.setLazyLoadingEnabled(false);
configuration.setMultipleResultSetsEnabled(true);
configuration.setUseColumnLabel(true);
configuration.setUseGeneratedKeys(true);
configuration.setAutoMappingBehavior(AutoMappingBehavior.FULL);
configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.WARNING);
configuration.setDefaultExecutorType(ExecutorType.REUSE);
configuration.setDefaultStatementTimeout(20000);
configuration.setSafeRowBoundsEnabled(false);
configuration.setMapUnderscoreToCamelCase(true);
configuration.setLogImpl(StdOutImpl.class);
configuration.setLocalCacheScope(LocalCacheScope.SESSION);
configuration.setJdbcTypeForNull(JdbcType.OTHER);
configuration.setLazyLoadTriggerMethods(
Sets.newHashSet("equals", "clone", "hashCode", "toString"));
return configuration;
}
@Bean
public DataSourceTransactionManager transactionManager(DruidDataSource druidDataSource) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(druidDataSource);
return dataSourceTransactionManager;
}
}
\ No newline at end of file
package com.ydl.auth.service.config.source;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
@Configuration
@EnableConfigurationProperties({ DataSourceProps.class })
public class DataSourceConfig {
private final DataSourceProps sourceProps;
private final Environment environment;
@Autowired
public DataSourceConfig(DataSourceProps sourceProps, Environment environment) {
this.sourceProps = sourceProps;
this.environment = environment;
}
@Bean
public DruidDataSource druidDataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl(sourceProps.getJdbcUrl());
druidDataSource.setUsername(sourceProps.getUserName());
druidDataSource.setPassword(sourceProps.getPassword());
druidDataSource.setDriverClassName(sourceProps.getDriverClassName());
return druidDataSource;
}
}
package com.ydl.auth.service.config.source;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("druid.pool")
public class DataSourceProps {
private String userName;
private String password;
private String jdbcUrl;
private String driverClassName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getJdbcUrl() {
return jdbcUrl;
}
public void setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
}
package com.ydl.auth.service.dao;
import com.ydl.common.service.BaseMapper;
import com.ydl.auth.po.AppAuth;
public interface AppAuthMapper extends BaseMapper<AppAuth> {
}
package com.ydl.auth.service.enums;
public enum YunYMEnum {
QN_STATIC1(0,"static.ydlcdn.com"),
QN_VIDEEO(1,"video.ydlcdn.com"),
QN_STATIC2(2,"static.yidianling.com"),
QN_HAOSHI99(3,"www.haoshi99.com"),
YP_IMG(4,"img.ydlcdn.com"),
YP_IMG2(5,"img.ydlcdn.com"),
YP_M(6, "m.haoshi99.com"),
AL_IMG(7,"ydlimg.oss-cn-shanghai.aliyuncs.com"),
AL_FILE(8,"ydlfile.oss-cn-shanghai.aliyuncs.com"),
AL_REDORD(9,"ydl-recording.oss-cn-shanghai.aliyuncs.com"),
QN_SELF(10,"qn.wangdaye.net"),
YP_SELF(11,"beans.wangdaye.net"),
AL_SELF(12,"alioss.wangdaye.net");
private Integer key;
private String value;
private YunYMEnum(Integer key, String value) {
this.key = key;
this.value = value;
}
public Integer key() {
return key;
}
public Integer getKey() {
return key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
package com.ydl.auth.service.facade;
import com.alibaba.dubbo.config.annotation.Service;
import com.ydl.auth.inf.AppAuthFacade;
import com.ydl.auth.service.biz.AppAuthBiz;
import javax.annotation.Resource;
@Service(version = "1.0.0",interfaceClass = AppAuthFacade.class,timeout = 500000)
public class AppAuthFacadeImpl implements AppAuthFacade {
@Resource
private AppAuthBiz AppAuthBiz;
@Override
public String getSecretByAppKey(String appKey) {
return AppAuthBiz.getSecretByAppKey(appKey);
}
}
package com.ydl.auth.service.facade;
import com.alibaba.dubbo.config.annotation.Service;
import com.ydl.auth.inf.AppAuthFacade;
import com.ydl.auth.inf.ComOssFacade;
import com.ydl.auth.service.enums.YunYMEnum;
import com.ydl.auth.service.utils.OssUrlUtil;
import com.ydl.common.dto.BaseDtoResponse;
import com.ydl.common.helper.ResponseFormatterHelper;
import com.ydl.common.service.RedisCacheStorage;
import com.ydl.common.utils.Util;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @program ydl-auth
* @description: ComOssFacadeImpl
* @author: wangjianfeng
* @create: 2020/03/03 18:31
*/
@Service(version = "1.0.0",interfaceClass = ComOssFacade.class,timeout = 500000)
public class ComOssFacadeImpl implements ComOssFacade {
private static Long expressedTime = 3600 * 1000l;
@Resource
private RedisCacheStorage redisCacheStorage;
@Resource
private OssUrlUtil ossUrlUtil;
@Override
public BaseDtoResponse<String> getTemporaryUrlByOriginalUrl(String originalUrl) {
String resultUrl = "";
String rKey = "oss_"+originalUrl;
String rStr = redisCacheStorage.sget(rKey).toString();
if(Util.isEmpty(rStr)||rStr.length()!=0){
return ResponseFormatterHelper.success(rStr);
}
originalUrl =originalUrl.replace("http://","");
originalUrl = originalUrl.replace("https://","");
if(originalUrl.startsWith(YunYMEnum.QN_STATIC1.getValue())
||originalUrl.startsWith(YunYMEnum.QN_VIDEEO.getValue())
||originalUrl.startsWith(YunYMEnum.QN_STATIC2.getValue())
||originalUrl.startsWith(YunYMEnum.QN_HAOSHI99.getValue())
){
String host = "";
//七牛云逻辑
if(originalUrl.startsWith(YunYMEnum.QN_STATIC1.getValue())){
host = YunYMEnum.QN_STATIC1.getValue();
}
else if(originalUrl.startsWith(YunYMEnum.QN_VIDEEO.getValue())){
host = YunYMEnum.QN_VIDEEO.getValue();
}
else if(originalUrl.startsWith(YunYMEnum.QN_STATIC2.getValue())){
host = YunYMEnum.QN_STATIC2.getValue();
}
else if(originalUrl.startsWith(YunYMEnum.QN_HAOSHI99.getValue())){
host = YunYMEnum.QN_HAOSHI99.getValue();
}
String key = originalUrl.replace(host,"");
resultUrl = ossUrlUtil.getQnyTemporaryUrl(host,key,expressedTime);
}
else if(originalUrl.startsWith(YunYMEnum.AL_IMG.getValue())
||originalUrl.startsWith(YunYMEnum.AL_FILE.getValue())
||originalUrl.startsWith(YunYMEnum.AL_REDORD.getValue())){
//阿里云逻辑
String host = "";
//七牛云逻辑
if(originalUrl.startsWith(YunYMEnum.AL_IMG.getValue())){
host = YunYMEnum.AL_IMG.getValue();
}
else if(originalUrl.startsWith(YunYMEnum.AL_FILE.getValue())){
host = YunYMEnum.AL_FILE.getValue();
}
else if(originalUrl.startsWith(YunYMEnum.AL_REDORD.getValue())){
host = YunYMEnum.AL_REDORD.getValue();
}
String key = originalUrl.replace(host,"");
resultUrl = ossUrlUtil.getAliyTemporaryUrl(host,key,expressedTime);
}
else if(originalUrl.startsWith(YunYMEnum.YP_IMG.getValue())
||originalUrl.startsWith(YunYMEnum.YP_IMG2.getValue())
||originalUrl.startsWith(YunYMEnum.YP_M.getValue())){
//又拍云逻辑
String host = "";
//七牛云逻辑
if(originalUrl.startsWith(YunYMEnum.YP_IMG.getValue())){
host = YunYMEnum.YP_IMG.getValue();
}
else if(originalUrl.startsWith(YunYMEnum.YP_IMG2.getValue())){
host = YunYMEnum.YP_IMG2.getValue();
}
else if(originalUrl.startsWith(YunYMEnum.YP_M.getValue())){
host = YunYMEnum.YP_M.getValue();
}
String key = originalUrl.replace(host,"");
resultUrl = ossUrlUtil.getYpyTemporaryUrl(host,key,expressedTime);
}
redisCacheStorage.sset(rKey,resultUrl,expressedTime-10000);//设短一点防止交叉时间取不到
return ResponseFormatterHelper.success(resultUrl);
}
@Override
public BaseDtoResponse<List<String>> getBathTemporaryUrlByOriginalUrl(List<String> originalUrls) {
List<String> resultList = new ArrayList<>();
for (String url: originalUrls) {
String result = getTemporaryUrlByOriginalUrl(url).getData();
resultList.add(result);
}
return ResponseFormatterHelper.success(resultList);
}
}
package com.ydl.auth.service.utils;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing;
import com.qiniu.util.Auth;
import com.ydl.auth.service.beans.OssProperties;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import java.io.Serializable;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @program ydl-auth
* @description: OssUtil
* @author: wangjianfeng
* @create: 2020/03/03 19:12
*/
@Data
@Component
public class OssUrlUtil implements Serializable {
@Autowired
private OssProperties ossProperties;
public String getAliyTemporaryUrl(String host,String key,Long expressedTime){
String tagetUrl = "";
List<String> contentList = getAliyContentList(key);
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(ossProperties.getAliossEndpoint(),
ossProperties.getAliossKeyAccessKeyId(), ossProperties.getAliossKeyAccessKeySecret());
for (String objectName:contentList) {
Date expiration = new Date(System.currentTimeMillis() + expressedTime);
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
String replaceStr = ossProperties.getAliossBucketName()+ossProperties.getAliossEndpoint()
.replace("http://","")
.replace("https://","");
URL url = ossClient.generatePresignedUrl(ossProperties.getAliossBucketName(), objectName, expiration);
String tag_url = url.toString().replace(replaceStr,host);
System.out.println("aliyun 生成的临时url为 "+tag_url);
tagetUrl = tag_url;
}
// 关闭OSSClient。
ossClient.shutdown();
return tagetUrl;
}
public String getYpyTemporaryUrl(String host,String key,Long expressedTime){
Long currentTime = System.currentTimeMillis();
Long etime = currentTime + expressedTime;
String urlString = "/"+key;
String sign = DigestUtils.md5DigestAsHex( (ossProperties.getYpSecret()+ "&"+ etime+"&"+ urlString).getBytes() );
Integer startIndex = sign.length()/2-4;
Integer endIndex = sign.length()/2+4;
String temStr = sign.substring(startIndex, endIndex);
String _upt = temStr + etime;
String requestUrl = host +urlString+"?_upt="+_upt;
return requestUrl;
}
public String getQnyTemporaryUrl(String host,String key,Long expressedTime) {
// 文档url https://developer.qiniu.com/kodo/sdk/1239/java#private-get
String finalUrl = "";
try {
String accessKey = ossProperties.getQnossKeyAccessKey();
String secretKey = ossProperties.getQnossKeySecretKey();
String fileName = key;
String domainOfBucket = host;
String encodedFileName = URLEncoder.encode(fileName, "utf-8").replace("+", "%20");
String publicUrl = String.format("%s/%s", domainOfBucket, encodedFileName);
Auth auth = Auth.create(accessKey, secretKey);
finalUrl = auth.privateDownloadUrl(publicUrl, expressedTime);
System.out.println("七牛云url " +finalUrl);
return finalUrl;
} catch (Exception e) {
e.printStackTrace();
}
return finalUrl;
}
public List<String> getAliyContentList(String KeyPrefix){
List<String> result = new ArrayList<>();
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(ossProperties.getAliossEndpoint(),
ossProperties.getAliossKeyAccessKeyId(), ossProperties.getAliossKeyAccessKeySecret());
// 列举文件。 如果不设置KeyPrefix,则列举存储空间下所有的文件。KeyPrefix,则列举包含指定前缀的文件。
ObjectListing objectListing = ossClient.listObjects(ossProperties.getAliossBucketName(),KeyPrefix);
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
for (OSSObjectSummary s : sums) {
result.add(s.getKey());
System.out.println("\t" + s.getKey());
}
// 关闭OSSClient。
ossClient.shutdown();
return result;
}
}
server:
port: 8090
spring:
profiles:
active: local
application:
name: ydl-auth-security-service
dubbo:
scan:
basePackages: com.ydl.auth.service.facade
#
#druid:
# pool:
# user-name: ydl
# password: tt12345
# jdbc-url: jdbc:mysql://120.26.213.52:3306/ydl_gateway?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&allowMultiQueries=true
# driver-class-name: com.mysql.jdbc.Driver
druid:
pool:
user-name: ydl
password: tt12345
jdbc-url: jdbc:mysql://120.26.213.52:3306/ydl?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8
driver-class-name: com.mysql.jdbc.Driver
swagger:
dubbo:
application:
version: 1.0.0
groupId: null
artifactId: com.ydl
cluster: rpc
doc: swagger-dubbo
enable: true
---
spring:
profiles: local
dubbo:
application:
name: ydl-auth-security-service
registry:
id: zookeeper
address: zookeeper://127.0.0.1:2181
#address: zookeeper://47.97.49.44:2181?backup=47.97.49.44:2182,47.97.49.44:2183
protocol: zookeeper
provider:
protocols:
- id: dubbo
name: dubbo
port: 30013
threads: 200
- jsonrpc:
id: jsonrpc
name: jsonrpc
port: 30014
threads: 200
druid:
pool:
user-name: ydl
password: tt12345
jdbc-url: jdbc:mysql://120.26.213.52:3306/ydl_gateway?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&allowMultiQueries=true
driver-class-name: com.mysql.jdbc.Driver
logging:
file: logs/${spring.application.name}-DEBUG.log
level:
root: debug
com.ydl: debug
com.ydl.advertise.service.dao: info
alioss:
key:
accessKeyId: LTAI4Fedci5X2Eud8Ums22Vd
accessKeySecret: PHoALBYiYloB3I6QH4n9fYIy0Ld9Y4
bucketName: encryption-test-wjf
host: alioss.wangdaye.net
endpoint: http://oss-cn-beijing.aliyuncs.com
yp:
host: http://beans.wangdaye.net
secret: 051388698738wjf
qnoss:
key:
accessKey: gGXzdekPDgxfKNWVFP5IH2_H2xM1XDHq1-c-PVDw
secretKey: CQ_Z7eZe0tKG1uinRyAb9sUaeW7MzphAMk6qBeEm
domainOfBucket: qn.wangdaye.net
---
spring:
profiles: dev
dubbo:
application:
name: ydl-auth-security-service
provider:
registry:
id: zookeeper
#address: zookeeper://127.0.0.1:2181
address: zookeeper://47.97.49.44:2181?backup=47.97.49.44:2182,47.97.49.44:2183
#address: zookeeper://172.16.1.34:2181?backup=172.16.226.95:2181,172.16.197.219:2181
protocol: zookeeper
protocols:
- id: dubbo
name: dubbo
port: 30013
threads: 200
- jsonrpc:
id: jsonrpc
name: jsonrpc
port: 30014
threads: 200
druid:
pool:
user-name: ydl
password: tt12345
jdbc-url: jdbc:mysql://120.26.213.52:3306/ydl_gateway?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&allowMultiQueries=true
driver-class-name: com.mysql.jdbc.Driver
logging:
file: /opt/release/logs/test/${spring.application.name}-DEBUG.log
level:
com.ydl.advertise.service.dao: info
---
spring:
profiles: auto_test
dubbo:
application:
name: ydl-auth-security-service
registry:
id: zookeeper
# address: zookeeper://127.0.0.1:2181
# address: zookeeper://127.0.0.1:2181?backup=127.0.0.1:2182,127.0.0.1:2183
address: zookeeper://172.16.1.34:2181?backup=172.16.226.95:2181,172.16.197.219:2181
protocol: zookeeper
provider:
protocols:
- id: dubbo
name: dubbo
port: 30013
threads: 200
- jsonrpc:
id: jsonrpc
name: jsonrpc
port: 30014
threads: 200
logging:
file: /opt/release/logs/test/${spring.application.name}-DEBUG.log
---
spring:
profiles: pre
dubbo:
application:
name: ydl-auth-security-service
provider:
protocols:
- id: dubbo
name: dubbo
port: 30013
threads: 200
- jsonrpc:
id: jsonrpc
name: jsonrpc
port: 30014
threads: 200
logging:
file: /opt/release/logs/pre/${spring.application.name}-DEBUG.log
---
spring:
profiles: prod
dubbo:
application:
name: ydl-auth-security-service
registry:
id: zookeeper
address: zookeeper://172.16.1.34:2181?backup=172.16.226.95:2181,172.16.197.219:2181
protocol: zookeeper
provider:
protocols:
- id: dubbo
name: dubbo
port: 30013
threads: 200
- jsonrpc:
id: jsonrpc
name: jsonrpc
port: 30014
threads: 200
druid:
pool:
user-name: ydl_co
password: EBX8&EvQRL#GV4MsmqHi6gfEHO3@$_1Z
jdbc-url: jdbc:mysql://rm-bp139aq706gz7bjhg.mysql.rds.aliyuncs.com:3306/ydl_gateway?zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8&allowMultiQueries=true
driver-class-name: com.mysql.jdbc.Driver
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.ydl.auth.service.dao.AppAuthMapper">
</mapper>
\ No newline at end of file
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