将私钥都分离放到配置文件中
This commit is contained in:
@@ -10,9 +10,7 @@ import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.util.Auth;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -23,31 +21,29 @@ import java.io.InputStream;
|
||||
*/
|
||||
@Service
|
||||
public class QiniuServiceImpl implements QiniuService {
|
||||
private Configuration cfg = new Configuration(Zone.zone2());
|
||||
private UploadManager uploadManager;
|
||||
private BucketManager bucketManager;
|
||||
private Auth auth;
|
||||
private static Configuration cfg = new Configuration(Zone.zone2());
|
||||
private static UploadManager uploadManager;
|
||||
private static BucketManager bucketManager;
|
||||
private static Auth auth;
|
||||
|
||||
private static String bucket;
|
||||
|
||||
|
||||
{
|
||||
/* ***** 必填 ******
|
||||
* 七牛的配置 *
|
||||
* ***** 必填 ******
|
||||
*/
|
||||
// accessKeyString,secretKeyString,bucketString:请替换为自己的值
|
||||
String accessKey = "accessKeyString";
|
||||
String secretKey = "secretKeyString";
|
||||
bucket = "bucketString";
|
||||
@Value("${qiniu.accessKey}")
|
||||
private String accessKey;
|
||||
@Value("${qiniu.secretKey}")
|
||||
private String secretKey;
|
||||
@Value("${qiniu.bucket}")
|
||||
private String bucket;
|
||||
|
||||
private void init() {
|
||||
if (auth == null || uploadManager == null || bucketManager == null) {
|
||||
auth = Auth.create(accessKey, secretKey);
|
||||
uploadManager = new UploadManager(cfg);
|
||||
bucketManager = new BucketManager(auth, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QiniuResponse uploadFile(InputStream is, String fileName) {
|
||||
init();
|
||||
//文件存在则删除文件
|
||||
if (continueFile(fileName)) {
|
||||
try {
|
||||
@@ -69,6 +65,7 @@ public class QiniuServiceImpl implements QiniuService {
|
||||
|
||||
@Override
|
||||
public FileInfo[] getFileList() {
|
||||
init();
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, "", 1000, "");
|
||||
FileInfo[] items = null;
|
||||
while (fileListIterator.hasNext()) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
@@ -33,8 +34,8 @@ public class JwtUtil {
|
||||
/**
|
||||
* JWT 秘钥需自行设置不可泄露
|
||||
*/
|
||||
private static final String SECRET = "xxx";
|
||||
|
||||
@Value("${jwt.secret}")
|
||||
private String SECRET;
|
||||
|
||||
public String generateToken(User user, boolean isRemember) {
|
||||
Map<String, Object> claims = new HashMap<>(16);
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
server.port=8081
|
||||
|
||||
# 七牛的密钥配置
|
||||
qiniu.accessKey=YBbgFf7wAtCCOa1EIY890C3bQwDgJSMNeWTJnNVP
|
||||
qiniu.secretKey=fg7MM82GDq8UTDqtReN3vRugUwlnI2GzmEHOWuKn
|
||||
qiniu.bucket=xiaohai
|
||||
# sitemap 存放地址
|
||||
sitemap.path=/home/xiaohai/Desktop/sitemap.xml
|
||||
# 生成JWT时候的密钥
|
||||
jwt.secret=sdjfioasd56415615631sf;[pp]apsidf;
|
||||
|
||||
spring.jpa.show-sql=false
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
# 上传单个文件的大小
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
server.port=8081
|
||||
|
||||
sitemap.path=C:\\Users\\zh564\\Desktop\\sitemap.xml
|
||||
## 七牛的密钥配置
|
||||
qiniu.accessKey=
|
||||
qiniu.secretKey=
|
||||
qiniu.bucket=
|
||||
## sitemap 存放地址
|
||||
sitemap.path=
|
||||
## 生成JWT时候的密钥
|
||||
jwt.secret=
|
||||
|
||||
##spring.jpa.show-sql=false
|
||||
##spring.jpa.hibernate.ddl-auto=update
|
||||
@@ -17,9 +24,9 @@ spring.jackson.default-property-inclusion=non_null
|
||||
|
||||
################# 数据库 ##################
|
||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/test_blog?serverTimezone=UCT&allowPublicKeyRetrieval=true&useSSL=false
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=zhenghai
|
||||
spring.datasource.url=
|
||||
spring.datasource.username=
|
||||
spring.datasource.password=
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
|
||||
|
||||
@@ -42,7 +49,7 @@ server.tomcat.protocol-header = X-Forwarded-Proto
|
||||
|
||||
|
||||
############### email ##############
|
||||
spring.mail.host=smtp.163.com
|
||||
spring.mail.host=
|
||||
spring.mail.username=
|
||||
spring.mail.password=
|
||||
spring.mail.properties.mail.smtp.auth=true
|
||||
|
||||
Reference in New Issue
Block a user