Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李丛阳
education
Commits
f35c5d26
Commit
f35c5d26
authored
Jan 07, 2021
by
岳志航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
111
parent
29bf5c11
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
614 additions
and
87 deletions
+614
-87
pom.xml
pom.xml
+1
-1
CyServiceAuthConfig.java
...ava/org/rcisoft/core/auth/config/CyServiceAuthConfig.java
+41
-0
CyAuthServerFeign.java
...n/java/org/rcisoft/core/auth/feign/CyAuthServerFeign.java
+26
-0
CyResultCode.java
src/main/java/org/rcisoft/core/enums/CyResultCode.java
+41
-0
CyMessCons.java
src/main/java/org/rcisoft/core/result/CyMessCons.java
+19
-0
CyResult.java
src/main/java/org/rcisoft/core/result/CyResult.java
+79
-0
CyResultGenUtil.java
src/main/java/org/rcisoft/core/result/CyResultGenUtil.java
+71
-0
CyAuthClientRunner.java
...main/java/org/rcisoft/core/runner/CyAuthClientRunner.java
+55
-0
RcRedisService.java
src/main/java/org/rcisoft/core/service/RcRedisService.java
+1
-0
RcRedisServiceImpl.java
...ava/org/rcisoft/core/service/impl/RcRedisServiceImpl.java
+23
-0
CyRsaKeyHelper.java
src/main/java/org/rcisoft/core/util/CyRsaKeyHelper.java
+168
-0
CyServiceAuthUtil.java
src/main/java/org/rcisoft/core/util/CyServiceAuthUtil.java
+53
-0
application-dev.yml
src/main/resources/application-dev.yml
+5
-4
logback-spring.xml
src/main/resources/logback-spring.xml
+31
-82
No files found.
pom.xml
View file @
f35c5d26
...
...
@@ -172,7 +172,7 @@
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.39
</version>
<version>
8.0.12
</version>
</dependency>
<!--alibaba fastjson-->
...
...
src/main/java/org/rcisoft/core/auth/config/CyServiceAuthConfig.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
auth
.
config
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
* Created with family.
* author: cy
* Date: 2019/11/28
* Time: 10:55 AM
* description:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
//@Component
public
class
CyServiceAuthConfig
{
private
byte
[]
pubKeyByte
;
@Value
(
"${auth.client.id:null}"
)
private
String
clientId
;
@Value
(
"${auth.client.secret}"
)
private
String
clientSecret
;
@Value
(
"${auth.client.token-header}"
)
private
String
tokenHeader
;
@Value
(
"${spring.application.name}"
)
private
String
applicationName
;
public
String
getClientId
()
{
return
"null"
.
equals
(
clientId
)
?
applicationName
:
clientId
;
}
}
src/main/java/org/rcisoft/core/auth/feign/CyAuthServerFeign.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
auth
.
feign
;
import
org.rcisoft.core.result.CyResult
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
/**
* Created by lcy on 18/4/9.
*/
//@FeignClient(value = "${auth.serviceId}",configuration = {} , fallback = CyAuthServerFeignFallBack.class)
public
interface
CyAuthServerFeign
{
@RequestMapping
(
value
=
"/client/myClient"
)
public
CyResult
getAllowedClient
(
@RequestParam
(
"serviceId"
)
String
serviceId
,
@RequestParam
(
"secret"
)
String
secret
);
@RequestMapping
(
value
=
"/client/token"
,
method
=
RequestMethod
.
POST
)
public
CyResult
getAccessToken
(
@RequestParam
(
"clientId"
)
String
clientId
,
@RequestParam
(
"secret"
)
String
secret
);
@RequestMapping
(
value
=
"/client/servicePubKey"
,
method
=
RequestMethod
.
POST
)
public
CyResult
getServicePublicKey
(
@RequestParam
(
"clientId"
)
String
clientId
,
@RequestParam
(
"secret"
)
String
secret
);
}
src/main/java/org/rcisoft/core/enums/CyResultCode.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
enums
;
/**
* Created with family.
* author: cy
* Date: 2020/3/16
* Time: 2:42 PM
* description:
*/
import
lombok.Getter
;
@Getter
public
enum
CyResultCode
{
SUCCESS
(
200
),
//成功
FAIL
(
400
),
//失败
UNAUTHORIZED
(
401
),
//未认证(签名错误)
UNAUTHENTICATED
(
402
),
//未授权(权限不够)
SERVER_TIMEOUT
(
403
),
//服务延时 hystrix
NOT_FOUND
(
404
),
//接口不存在
INTERNAL_SERVER_ERROR
(
500
),
//服务器内部错误
PARAMETER_ERROR
(
601
),
//参数错误
PARAMETER_DECRYPT_ERROR
(
603
),
//参数解密错误
REDIS_OPERATE_ERROR
(
700
),
//redis 操作失败
DATA_EXISTS
(
602
);
//数据已存在
private
int
code
;
CyResultCode
(
int
code
)
{
this
.
code
=
code
;
}
}
src/main/java/org/rcisoft/core/result/CyMessCons.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
result
;
/**
* Created with family.
* author: cy
* Date: 2020/3/16
* Time: 2:52 PM
* description:
*/
public
class
CyMessCons
{
//操作成功
public
static
final
String
MESSAGE_ALERT_SUCCESS
=
"操作成功"
;
//操作失败
public
static
final
String
MESSAGE_ALERT_ERROR
=
"操作失败"
;
//操作超时
public
static
final
String
MESSAGE_ALERT_OVERTIME
=
"操作超时"
;
//信息非法
public
static
final
String
MESSAGE_ALERT_INFO_INVALID
=
"信息不合法"
;
}
src/main/java/org/rcisoft/core/result/CyResult.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
result
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
org.rcisoft.core.enums.CyResultCode
;
/**
* 统一API响应结果封装
*/
public
class
CyResult
{
private
Integer
code
;
private
String
message
;
private
Object
data
;
/**
*
* @param data
* @return
*/
public
void
setErrorMessage
(
String
message
,
Object
data
)
{
this
.
code
=
CyResultCode
.
FAIL
.
getCode
();
this
.
message
=
message
;
this
.
data
=
data
;
}
public
void
setSucessMessage
(
String
message
,
Object
data
)
{
this
.
code
=
CyResultCode
.
SUCCESS
.
getCode
();
this
.
message
=
message
;
this
.
data
=
data
;
}
public
interface
DefulatJsonView
{}
/**
* desc Dec 20 解决 feign setter 重载方法 可能会冲突问题
* @param cyResultCode
* @return
*/
public
CyResult
setResultCode
(
CyResultCode
cyResultCode
)
{
this
.
code
=
cyResultCode
.
getCode
();
return
this
;
}
@JsonView
(
DefulatJsonView
.
class
)
public
Integer
getCode
()
{
return
code
;
}
public
CyResult
setCode
(
Integer
code
)
{
this
.
code
=
code
;
return
this
;
}
@JsonView
(
DefulatJsonView
.
class
)
public
String
getMessage
()
{
return
message
;
}
public
CyResult
setMessage
(
String
message
)
{
this
.
message
=
message
;
return
this
;
}
@JsonView
(
DefulatJsonView
.
class
)
public
Object
getData
()
{
return
data
;
}
public
CyResult
setData
(
Object
data
)
{
this
.
data
=
data
;
return
this
;
}
@Override
public
String
toString
()
{
return
JSON
.
toJSONString
(
this
);
}
}
src/main/java/org/rcisoft/core/result/CyResultGenUtil.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
result
;
import
org.rcisoft.core.enums.CyResultCode
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.model.PersistModel
;
/**
* Created with family.
* author: cy
* Date: 2020/3/16
* Time: 2:50 PM
* description:
*/
public
class
CyResultGenUtil
{
private
static
final
String
DEFAULT_SUCCESS_MESSAGE
=
"SUCCESS"
;
public
static
CyResult
builder
(
PersistModel
dataModel
,
String
sucMessage
,
String
errMessage
,
Object
data
){
CyResult
cyResult
=
new
CyResult
();
if
(
dataModel
.
isSuccessBySinglePersist
())
cyResult
.
setSucessMessage
(
sucMessage
,
data
);
else
cyResult
.
setErrorMessage
(
errMessage
,
data
);
return
cyResult
;
}
public
static
CyResult
genSuccessResult
()
{
return
new
CyResult
()
.
setResultCode
(
CyResultCode
.
SUCCESS
)
.
setMessage
(
DEFAULT_SUCCESS_MESSAGE
);
}
public
static
CyResult
genSuccessResult
(
Object
data
)
{
return
new
CyResult
()
.
setResultCode
(
CyResultCode
.
SUCCESS
)
.
setMessage
(
DEFAULT_SUCCESS_MESSAGE
)
.
setData
(
data
);
}
public
static
CyResult
genFailResult
(
String
message
)
{
return
new
CyResult
()
.
setResultCode
(
CyResultCode
.
FAIL
)
.
setMessage
(
message
);
}
/**
* 构建原生 result
* @param code
* @param mess
* @param data
* @return
*/
public
static
CyResult
builderOriginResult
(
Integer
code
,
String
mess
,
Object
data
){
return
new
CyResult
()
.
setCode
(
code
)
.
setMessage
(
mess
)
.
setData
(
data
);
}
/**
* 验证 result
* @param result
* @return
*/
public
static
CyResult
validateResult
(
CyResult
result
){
if
(
result
.
getCode
()
!=
CyResultCode
.
SUCCESS
.
getCode
()){
throw
new
ServiceException
(
result
.
getCode
(),
result
.
getMessage
());
}
return
result
;
}
}
src/main/java/org/rcisoft/core/runner/CyAuthClientRunner.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
runner
;
import
lombok.extern.slf4j.Slf4j
;
import
org.rcisoft.core.auth.config.CyServiceAuthConfig
;
import
org.rcisoft.core.auth.feign.CyAuthServerFeign
;
import
org.rcisoft.core.result.CyResult
;
import
org.rcisoft.core.util.CyRsaKeyHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
/**
* Created by lcy on 18/4/9.
*
* 获取用户 client/user 公钥
*/
//@Component
@Slf4j
public
class
CyAuthClientRunner
implements
CommandLineRunner
{
@Autowired
private
CyServiceAuthConfig
rcServiceAuthConfig
;
@Autowired
private
CyAuthServerFeign
rcAuthServerFeign
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
log
.
info
(
"初始化加载服务端pubKey"
);
try
{
refreshServicePubKey
();
}
catch
(
Exception
e
){
log
.
error
(
"初始化加载服务端pubKey失败,1分钟后自动重试!"
,
e
);
}
}
/**
* 刷新service 公钥
*/
@Scheduled
(
cron
=
"0 0/10 * * * ?"
)
public
void
refreshServicePubKey
()
throws
IOException
{
CyResult
resp
=
rcAuthServerFeign
.
getServicePublicKey
(
rcServiceAuthConfig
.
getClientId
(),
rcServiceAuthConfig
.
getClientSecret
());
if
(
resp
.
getCode
()
==
HttpStatus
.
OK
.
value
())
{
Object
data
=
resp
.
getData
();
byte
[]
re
=
CyRsaKeyHelper
.
toBytes
(
data
.
toString
());
this
.
rcServiceAuthConfig
.
setPubKeyByte
(
re
);
}
}
}
src/main/java/org/rcisoft/core/service/RcRedisService.java
View file @
f35c5d26
...
...
@@ -21,6 +21,7 @@ public interface RcRedisService {
*/
public
void
returnResource
(
Jedis
jedis
);
public
void
returnBrokenResource
(
Jedis
jedis
);
/**
* 赋值
* @param key
...
...
src/main/java/org/rcisoft/core/service/impl/RcRedisServiceImpl.java
View file @
f35c5d26
...
...
@@ -21,6 +21,8 @@ public class RcRedisServiceImpl implements RcRedisService {
@Override
public
Jedis
getResource
()
{
log
.
info
(
"++++"
+
jedisPool
+
"---"
);
log
.
info
(
"++++"
+
jedisPool
.
getResource
()+
"---"
);
return
jedisPool
.
getResource
();
}
...
...
@@ -32,6 +34,17 @@ public class RcRedisServiceImpl implements RcRedisService {
}
}
// 出现异常释放资源
@Override
public
synchronized
void
returnBrokenResource
(
Jedis
jedis
)
{
if
(
jedis
!=
null
)
{
jedisPool
.
returnBrokenResource
(
jedis
);
}
}
@Override
public
void
set
(
String
key
,
String
value
,
int
expire
)
{
Jedis
jedis
=
null
;
...
...
@@ -42,6 +55,7 @@ public class RcRedisServiceImpl implements RcRedisService {
jedis
.
expire
(
key
,
expire
);
log
.
info
(
"Redis set success - "
+
key
+
", value:"
+
value
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
value
);
}
finally
{
...
...
@@ -57,6 +71,7 @@ public class RcRedisServiceImpl implements RcRedisService {
jedis
.
set
(
key
,
value
);
log
.
info
(
"Redis set success - "
+
key
+
", value:"
+
value
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
value
);
}
finally
{
...
...
@@ -72,6 +87,7 @@ public class RcRedisServiceImpl implements RcRedisService {
jedis
.
set
(
key
.
getBytes
(),
value
);
log
.
info
(
"Redis set success - "
+
key
+
", value:"
+
value
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
value
);
}
finally
{
...
...
@@ -89,6 +105,7 @@ public class RcRedisServiceImpl implements RcRedisService {
jedis
.
expire
(
key
,
expire
);
log
.
info
(
"Redis set success - "
+
key
+
", value:"
+
value
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
value
);
}
finally
{
...
...
@@ -104,6 +121,7 @@ public class RcRedisServiceImpl implements RcRedisService {
result
=
jedis
.
get
(
key
);
log
.
info
(
"Redis get success - "
+
key
+
", value:"
+
result
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
result
);
}
finally
{
...
...
@@ -121,6 +139,7 @@ public class RcRedisServiceImpl implements RcRedisService {
result
=
jedis
.
get
(
key
.
getBytes
());
log
.
info
(
"Redis get success - "
+
key
+
", value:"
+
result
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
result
);
}
finally
{
...
...
@@ -137,6 +156,7 @@ public class RcRedisServiceImpl implements RcRedisService {
jedis
.
del
(
key
);
log
.
info
(
"Redis del success - "
+
key
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
);
}
finally
{
...
...
@@ -154,6 +174,7 @@ public class RcRedisServiceImpl implements RcRedisService {
result
=
jedis
.
lrange
(
key
,
0
,
-
1
);
log
.
info
(
"Redis get list success - "
+
key
+
", value:"
+
result
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
);
}
finally
{
...
...
@@ -172,6 +193,7 @@ public class RcRedisServiceImpl implements RcRedisService {
jedis
.
rpush
(
key
,
value
);
log
.
info
(
"Redis set list success - "
+
key
+
", value:"
+
value
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
value
);
}
finally
{
...
...
@@ -187,6 +209,7 @@ public class RcRedisServiceImpl implements RcRedisService {
jedis
.
lrem
(
key
,
1
,
value
);
log
.
info
(
"Redis remove list success - "
+
key
+
", value:"
+
value
);
}
catch
(
Exception
e
)
{
returnBrokenResource
(
jedis
);
e
.
printStackTrace
();
log
.
error
(
"Redis set error: "
+
e
.
getMessage
()
+
" - "
+
key
+
", value:"
+
value
);
}
finally
{
...
...
src/main/java/org/rcisoft/core/util/CyRsaKeyHelper.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
util
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
java.io.DataInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.security.*
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created with family.
* author: cy
* Date: 2020/3/16
* Time: 3:02 PM
* description:
*/
public
class
CyRsaKeyHelper
{
/**
* 获取公钥
*
* @param filename
* @return
* @throws Exception
*/
public
PublicKey
getPublicKey
(
String
filename
)
throws
Exception
{
InputStream
resourceAsStream
=
this
.
getClass
().
getClassLoader
().
getResourceAsStream
(
filename
);
DataInputStream
dis
=
new
DataInputStream
(
resourceAsStream
);
byte
[]
keyBytes
=
new
byte
[
resourceAsStream
.
available
()];
dis
.
readFully
(
keyBytes
);
dis
.
close
();
X509EncodedKeySpec
spec
=
new
X509EncodedKeySpec
(
keyBytes
);
KeyFactory
kf
=
KeyFactory
.
getInstance
(
"RSA"
);
return
kf
.
generatePublic
(
spec
);
}
/**
* 获取密钥
*
* @param filename
* @return
* @throws Exception
*/
public
PrivateKey
getPrivateKey
(
String
filename
)
throws
Exception
{
InputStream
resourceAsStream
=
this
.
getClass
().
getClassLoader
().
getResourceAsStream
(
filename
);
DataInputStream
dis
=
new
DataInputStream
(
resourceAsStream
);
byte
[]
keyBytes
=
new
byte
[
resourceAsStream
.
available
()];
dis
.
readFully
(
keyBytes
);
dis
.
close
();
PKCS8EncodedKeySpec
spec
=
new
PKCS8EncodedKeySpec
(
keyBytes
);
KeyFactory
kf
=
KeyFactory
.
getInstance
(
"RSA"
);
return
kf
.
generatePrivate
(
spec
);
}
/**
* 获取公钥
*
* @param publicKey
* @return
* @throws Exception
*/
public
PublicKey
getPublicKey
(
byte
[]
publicKey
)
throws
Exception
{
X509EncodedKeySpec
spec
=
new
X509EncodedKeySpec
(
publicKey
);
KeyFactory
kf
=
KeyFactory
.
getInstance
(
"RSA"
);
return
kf
.
generatePublic
(
spec
);
}
/**
* 获取密钥
*
* @param privateKey
* @return
* @throws Exception
*/
public
PrivateKey
getPrivateKey
(
byte
[]
privateKey
)
throws
Exception
{
PKCS8EncodedKeySpec
spec
=
new
PKCS8EncodedKeySpec
(
privateKey
);
KeyFactory
kf
=
KeyFactory
.
getInstance
(
"RSA"
);
return
kf
.
generatePrivate
(
spec
);
}
/**
* 生存rsa公钥和密钥
*
* @param publicKeyFilename
* @param privateKeyFilename
* @param password
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public
void
generateKey
(
String
publicKeyFilename
,
String
privateKeyFilename
,
String
password
)
throws
IOException
,
NoSuchAlgorithmException
{
KeyPairGenerator
keyPairGenerator
=
KeyPairGenerator
.
getInstance
(
"RSA"
);
SecureRandom
secureRandom
=
new
SecureRandom
(
password
.
getBytes
());
keyPairGenerator
.
initialize
(
1024
,
secureRandom
);
KeyPair
keyPair
=
keyPairGenerator
.
genKeyPair
();
byte
[]
publicKeyBytes
=
keyPair
.
getPublic
().
getEncoded
();
FileOutputStream
fos
=
new
FileOutputStream
(
publicKeyFilename
);
fos
.
write
(
publicKeyBytes
);
fos
.
close
();
byte
[]
privateKeyBytes
=
keyPair
.
getPrivate
().
getEncoded
();
fos
=
new
FileOutputStream
(
privateKeyFilename
);
fos
.
write
(
privateKeyBytes
);
fos
.
close
();
}
/**
* 生存rsa公钥
*
* @param password
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public
static
byte
[]
generatePublicKey
(
String
password
)
throws
IOException
,
NoSuchAlgorithmException
{
KeyPairGenerator
keyPairGenerator
=
KeyPairGenerator
.
getInstance
(
"RSA"
);
SecureRandom
secureRandom
=
new
SecureRandom
(
password
.
getBytes
());
keyPairGenerator
.
initialize
(
1024
,
secureRandom
);
KeyPair
keyPair
=
keyPairGenerator
.
genKeyPair
();
return
keyPair
.
getPublic
().
getEncoded
();
}
/**
* 生存rsa公钥
*
* @param password
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public
static
byte
[]
generatePrivateKey
(
String
password
)
throws
IOException
,
NoSuchAlgorithmException
{
KeyPairGenerator
keyPairGenerator
=
KeyPairGenerator
.
getInstance
(
"RSA"
);
SecureRandom
secureRandom
=
new
SecureRandom
(
password
.
getBytes
());
keyPairGenerator
.
initialize
(
1024
,
secureRandom
);
KeyPair
keyPair
=
keyPairGenerator
.
genKeyPair
();
return
keyPair
.
getPrivate
().
getEncoded
();
}
public
static
Map
<
String
,
byte
[]>
generateKey
(
String
password
)
throws
IOException
,
NoSuchAlgorithmException
{
KeyPairGenerator
keyPairGenerator
=
KeyPairGenerator
.
getInstance
(
"RSA"
);
SecureRandom
secureRandom
=
new
SecureRandom
(
password
.
getBytes
());
keyPairGenerator
.
initialize
(
1024
,
secureRandom
);
KeyPair
keyPair
=
keyPairGenerator
.
genKeyPair
();
byte
[]
publicKeyBytes
=
keyPair
.
getPublic
().
getEncoded
();
byte
[]
privateKeyBytes
=
keyPair
.
getPrivate
().
getEncoded
();
Map
<
String
,
byte
[]>
map
=
new
HashMap
<
String
,
byte
[]>();
map
.
put
(
"pub"
,
publicKeyBytes
);
map
.
put
(
"pri"
,
privateKeyBytes
);
return
map
;
}
public
static
String
toHexString
(
byte
[]
b
)
{
return
(
new
BASE64Encoder
()).
encodeBuffer
(
b
);
}
public
static
final
byte
[]
toBytes
(
String
s
)
throws
IOException
{
return
(
new
BASE64Decoder
()).
decodeBuffer
(
s
);
}
public
static
void
main
(
String
[]
args
)
throws
NoSuchAlgorithmException
{
/*KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
SecureRandom secureRandom = new SecureRandom("123".getBytes());
keyPairGenerator.initialize(1024, secureRandom);
KeyPair keyPair = keyPairGenerator.genKeyPair();
System.out.println(keyPair.getPublic().getEncoded());*/
}
}
src/main/java/org/rcisoft/core/util/CyServiceAuthUtil.java
0 → 100644
View file @
f35c5d26
package
org
.
rcisoft
.
core
.
util
;
import
lombok.extern.slf4j.Slf4j
;
import
org.rcisoft.core.auth.config.CyServiceAuthConfig
;
import
org.rcisoft.core.auth.feign.CyAuthServerFeign
;
//import org.rcisoft.core.result.CyResult;
import
org.rcisoft.core.result.CyResult
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
/**
* Created by lcy on 18/4/9.
*/
//@Component
@Slf4j
@EnableScheduling
public
class
CyServiceAuthUtil
{
@Autowired
private
CyServiceAuthConfig
rcServiceAuthConfig
;
@Autowired
private
CyAuthServerFeign
rcAuthServerFeign
;
/**
* 允许调用的 client
*/
private
List
<
String
>
allowedClient
;
private
String
clientToken
;
@Scheduled
(
cron
=
"0 0/10 * * * ?"
)
public
void
refreshClientToken
()
{
log
.
debug
(
"refresh client token....."
);
CyResult
resp
=
rcAuthServerFeign
.
getAccessToken
(
rcServiceAuthConfig
.
getClientId
(),
rcServiceAuthConfig
.
getClientSecret
());
if
(
resp
.
getCode
()
==
200
)
this
.
clientToken
=
resp
.
getData
().
toString
();
}
public
String
getClientToken
()
{
if
(
this
.
clientToken
==
null
)
{
this
.
refreshClientToken
();
}
return
clientToken
;
}
}
src/main/resources/application-dev.yml
View file @
f35c5d26
...
...
@@ -11,10 +11,10 @@ server:
# org.springframework.web: DEBUG
druid
:
url
:
jdbc:mysql://
127.0.0.1
:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
url
:
jdbc:mysql://
47.94.34.189
:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
#url: jdbc:mysql://120.52.179.75:13318/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username
:
root
password
:
123456
username
:
edu
password
:
edu
initial-size
:
1
min-idle
:
1
max-active
:
20
...
...
@@ -57,7 +57,8 @@ spring:
resources
:
add-mappings
:
false
redis
:
host
:
127.0.0.1
# host: 127.0.0.1
host
:
47.94.34.189
port
:
6379
pool
:
max-idle
:
50
...
...
src/main/resources/logback-spring.xml
View file @
f35c5d26
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<configuration
scan=
"true"
scanPeriod=
"30 seconds"
debug=
"false"
>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property
name=
"LOG_HOME"
value=
"./logs"
/>
<!-- 控制台输出 -->
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder
class=
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"
>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<!--<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>-->
<pattern>
%white(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{10}.%M.%L) - %cyan(%msg%n)
</pattern>
<configuration>
<appender
name=
"consoleLog"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<layout
class=
"ch.qos.logback.classic.PatternLayout"
>
<pattern>
%d - %msg%n
</pattern>
<!--<pattern>
%-5level %d - %msg%n
</pattern>-->
</layout>
</appender>
<appender
name=
"fileInfoLog"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.LevelFilter"
>
<level>
ERROR
</level>
<onMatch>
DENY
</onMatch>
<onMismatch>
ACCEPT
</onMismatch>
</filter>
<encoder>
<pattern>
%date %-5level [%thread] %logger{43}\(%L\) : %msg
</pattern>
</encoder>
<!--滚动策略-->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!--路径-->
<fileNamePattern>
/working/test/info.%d.log
</fileNamePattern>
</rollingPolicy>
</appender>
<!--https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx50601fe1a9207d84&redirect_uri=http://gwf.natapp4.cc/sell/weixin/auth&response_type=code&scope=snsapi_userinfo&state=gwf#wechat_redirect-->
<appender
name=
"fileErrorLog"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!--
临界值过滤器,过滤掉低于指定临界值的日志。当日志级别等于或高于临界值时,过滤器返回NEUTRAL;当日志级别低于临界值时,日志会被拒绝
-->
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
ERROR
</level>
</filter>
<encoder>
<pattern>
%date %-5level [%thread] %logger{43}\(%L\) : %msg
</pattern>
</encoder>
<!--滚动策略-->
<!-- 按照每天生成日志文件 -->
<appender
name=
"FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!--路径-->
<fileNamePattern>
/working/test/error.%d.log
</fileNamePattern>
<!--日志文件输出的文件名-->
<FileNamePattern>
${LOG_HOME}/EDUCATION.log.%d{yyyy-MM-dd}.log
</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>
30
</MaxHistory>
<!--<MaxFileSize>2 KB</MaxFileSize>-->
</rollingPolicy>
<encoder
class=
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"
>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</encoder>
</appender>
<!--
指定对应包名
-->
<logger
name=
"com.minlia"
level=
"DEBUG"
/>
<logger
name=
"org.springframework.data.mybatis"
level=
"DEBUG"
/>
<logger
name=
"org.springframework.aop.aspectj"
level=
"ERROR"
/>
<springProfile
name=
"dev"
>
<root
level=
"debug"
>
<appender-ref
ref=
"consoleLog"
/>
<appender-ref
ref=
"fileInfoLog"
/>
<appender-ref
ref=
"fileErrorLog"
/>
</root>
</springProfile>
<springProfile
name=
"prod"
>
<root
level=
"info"
>
<appender-ref
ref=
"consoleLog"
/>
<appender-ref
ref=
"fileInfoLog"
/>
<appender-ref
ref=
"fileErrorLog"
/>
</root>
</springProfile>
<springProfile
name=
"prod125"
>
<root
level=
"info"
>
<appender-ref
ref=
"consoleLog"
/>
<appender-ref
ref=
"fileInfoLog"
/>
<appender-ref
ref=
"fileErrorLog"
/>
</root>
</springProfile>
<!--myibatis log configure-->
<logger
name=
"com.apache.ibatis"
level=
"TRACE"
/>
<logger
name=
"java.sql.Connection"
level=
"DEBUG"
/>
<logger
name=
"java.sql.Statement"
level=
"DEBUG"
/>
<logger
name=
"java.sql.PreparedStatement"
level=
"DEBUG"
/>
<springProfile
name=
"prod103"
>
<root
level=
"info"
>
<appender-ref
ref=
"consoleLog"
/>
<appender-ref
ref=
"fileInfoLog"
/>
<appender-ref
ref=
"fileErrorLog"
/>
</root>
</springProfile>
<!-- 日志输出级别 -->
<root
level=
"DEBUG"
>
<appender-ref
ref=
"STDOUT"
/>
<appender-ref
ref=
"FILE"
/>
</root>
</configuration>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment