Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yujianwangzivayy
MaxKey
提交
2e90f578
MaxKey
项目概览
yujianwangzivayy
/
MaxKey
与 Fork 源项目一致
Fork自
MaxKey单点登录官方(MaxKeyTop) / MaxKey
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MaxKey
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2e90f578
编写于
4月 12, 2020
作者:
MaxKey单点登录官方
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SmsOtpAuthnYunxin
上级
bfde3eee
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
150 addition
and
143 deletion
+150
-143
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/AbstractOptAuthn.java
...java/org/maxkey/crypto/password/opt/AbstractOptAuthn.java
+1
-1
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/MailOtpAuthn.java
...ava/org/maxkey/crypto/password/opt/impl/MailOtpAuthn.java
+2
-2
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/SmsOtpAuthn.java
...java/org/maxkey/crypto/password/opt/impl/SmsOtpAuthn.java
+2
-2
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/SendSms.java
...java/org/maxkey/crypto/password/opt/impl/sms/SendSms.java
+0
-7
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/netease/SmsOtpAuthnCheckSumBuilder.java
...word/opt/impl/sms/netease/SmsOtpAuthnCheckSumBuilder.java
+1
-1
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/netease/SmsOtpAuthnYunxin.java
...ypto/password/opt/impl/sms/netease/SmsOtpAuthnYunxin.java
+9
-9
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/package-info.java
...org/maxkey/crypto/password/opt/impl/sms/package-info.java
+0
-1
maxkey-core/src/main/java/org/maxkey/util/StringGenerator.java
...y-core/src/main/java/org/maxkey/util/StringGenerator.java
+135
-120
未找到文件。
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/AbstractOptAuthn.java
浏览文件 @
2e90f578
...
...
@@ -33,7 +33,7 @@ public abstract class AbstractOptAuthn {
private
final
JdbcTemplate
jdbcTemplate
;
public
static
final
class
O
PT_TYPES
{
public
static
final
class
O
ptTypes
{
// 手机
public
static
int
MOBILE
=
2
;
// 短信
...
...
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/MailOtpAuthn.java
浏览文件 @
2e90f578
...
...
@@ -37,7 +37,7 @@ public class MailOtpAuthn extends AbstractOptAuthn {
_logger
.
debug
(
"token "
+
token
+
" send to user +"
+
userInfo
.
getUsername
()
+
", email "
+
userInfo
.
getEmail
());
this
.
insertDataBase
(
userInfo
,
token
,
userInfo
.
getUsername
(),
O
PT_TYPES
.
EMAIL
);
this
.
insertDataBase
(
userInfo
,
token
,
userInfo
.
getUsername
(),
O
ptTypes
.
EMAIL
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -47,7 +47,7 @@ public class MailOtpAuthn extends AbstractOptAuthn {
@Override
public
boolean
validate
(
UserInfo
userInfo
,
String
token
)
{
return
this
.
validateDataBase
(
userInfo
,
token
,
O
PT_TYPES
.
EMAIL
);
return
this
.
validateDataBase
(
userInfo
,
token
,
O
ptTypes
.
EMAIL
);
}
public
void
setEmailConfig
(
EmailConfig
emailConfig
)
{
...
...
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/SmsOtpAuthn.java
浏览文件 @
2e90f578
...
...
@@ -15,13 +15,13 @@ public class SmsOtpAuthn extends AbstractOptAuthn {
String
token
=
this
.
genToken
(
userInfo
);
// TODO:You must add send sms code here
this
.
insertDataBase
(
userInfo
,
token
,
userInfo
.
getUsername
(),
O
PT_TYPES
.
SMS
);
this
.
insertDataBase
(
userInfo
,
token
,
userInfo
.
getUsername
(),
O
ptTypes
.
SMS
);
return
true
;
}
@Override
public
boolean
validate
(
UserInfo
userInfo
,
String
token
)
{
return
this
.
validateDataBase
(
userInfo
,
token
,
O
PT_TYPES
.
SMS
);
return
this
.
validateDataBase
(
userInfo
,
token
,
O
ptTypes
.
SMS
);
}
}
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/SendSms.java
已删除
100644 → 0
浏览文件 @
bfde3eee
package
org.maxkey.crypto.password.opt.impl.sms
;
public
interface
SendSms
{
public
String
sendSms
();
}
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/netease/S
endSmsYunxi
nCheckSumBuilder.java
→
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/netease/S
msOtpAuth
nCheckSumBuilder.java
浏览文件 @
2e90f578
...
...
@@ -2,7 +2,7 @@ package org.maxkey.crypto.password.opt.impl.sms.netease;
import
java.security.MessageDigest
;
public
class
S
endSmsYunxi
nCheckSumBuilder
{
public
class
S
msOtpAuth
nCheckSumBuilder
{
// 计算并获取CheckSum
public
static
String
getCheckSum
(
String
appSecret
,
String
nonce
,
String
curTime
)
{
return
encode
(
"sha1"
,
appSecret
+
nonce
+
curTime
);
...
...
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/netease/S
endSms
Yunxin.java
→
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/netease/S
msOtpAuthn
Yunxin.java
浏览文件 @
2e90f578
...
...
@@ -11,7 +11,8 @@ import org.apache.http.client.methods.HttpPost;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
org.maxkey.crypto.password.opt.impl.sms.SendSms
;
import
org.maxkey.crypto.password.opt.impl.SmsOtpAuthn
;
import
org.springframework.jdbc.core.JdbcTemplate
;
/**
* 网易云信的短信验证.
...
...
@@ -19,7 +20,12 @@ import org.maxkey.crypto.password.opt.impl.sms.SendSms;
*
*/
public
class
SendSmsYunxin
implements
SendSms
{
public
class
SmsOtpAuthnYunxin
extends
SmsOtpAuthn
{
public
SmsOtpAuthnYunxin
(
JdbcTemplate
jdbcTemplate
)
{
super
(
jdbcTemplate
);
// TODO Auto-generated constructor stub
}
//发送验证码的请求路径URL
private
static
final
String
SERVER_URL
=
"https://api.netease.im/sms/sendcode.action"
;
...
...
@@ -49,7 +55,7 @@ public class SendSmsYunxin implements SendSms {
/*
* 参考计算CheckSum的java代码,在上述文档的参数列表中,有CheckSum的计算文档示例
*/
String
checkSum
=
S
endSmsYunxi
nCheckSumBuilder
String
checkSum
=
S
msOtpAuth
nCheckSumBuilder
.
getCheckSum
(
APP_SECRET
,
NONCE
,
curTime
);
// 设置请求的header
...
...
@@ -93,11 +99,5 @@ public class SendSmsYunxin implements SendSms {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
sendSms
(
null
);
}
@Override
public
String
sendSms
()
{
// TODO Auto-generated method stub
return
null
;
}
}
maxkey-core/src/main/java/org/maxkey/crypto/password/opt/impl/sms/package-info.java
已删除
100644 → 0
浏览文件 @
bfde3eee
package
org.maxkey.crypto.password.opt.impl.sms
;
\ No newline at end of file
maxkey-core/src/main/java/org/maxkey/util/StringGenerator.java
浏览文件 @
2e90f578
...
...
@@ -7,133 +7,148 @@ import java.text.SimpleDateFormat;
import
java.util.Date
;
import
java.util.Random
;
import
java.util.UUID
;
import
org.maxkey.crypto.Base64Utils
;
public
class
StringGenerator
{
private
static
final
int
MAX_PID
=
65536
;
private
char
[]
DEFAULT_CODEC
=
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_NUMBER
=
"1234567890"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_LOWERCASE
=
"abcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_UPPERCASE
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_LETTERS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_NUMBER_LETTERS
=
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
int
processId
;
private
static
final
String
uuidRegex
=
"^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$"
;
private
Random
random
=
new
SecureRandom
();
private
int
length
;
static
{
final
String
jvmName
=
ManagementFactory
.
getRuntimeMXBean
().
getName
();
int
index
=
jvmName
.
indexOf
(
'@'
);
if
(
index
<
1
)
throw
new
RuntimeException
(
"Could not get PID"
);
private
static
final
int
MAX_PID
=
65536
;
private
static
final
char
[]
DEFAULT_CODEC
=
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_NUMBER
=
"1234567890"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_LOWERCASE
=
"abcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_UPPERCASE
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_LETTERS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
final
char
[]
DEFAULT_CODE_NUMBER_LETTERS
=
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
public
static
int
processId
;
private
static
final
String
uuidRegex
=
"^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$"
;
private
Random
random
=
new
SecureRandom
();
private
int
length
;
private
char
[]
codec
=
DEFAULT_CODEC
;
static
{
final
String
jvmName
=
ManagementFactory
.
getRuntimeMXBean
().
getName
();
int
index
=
jvmName
.
indexOf
(
'@'
);
if
(
index
<
1
)
{
throw
new
RuntimeException
(
"Could not get PID"
);
}
try
{
processId
=
Integer
.
parseInt
(
jvmName
.
substring
(
0
,
index
))
%
MAX_PID
;
processId
=
Integer
.
parseInt
(
jvmName
.
substring
(
0
,
index
))
%
MAX_PID
;
}
catch
(
NumberFormatException
e
)
{
throw
new
RuntimeException
(
"Could not get PID"
);
}
}
/**
* Create a generator with the default length (6).
*/
public
StringGenerator
()
{
this
(
6
);
}
/**
* Create a generator of random strings of the length provided
*
* @param length the length of the strings generated
*/
public
StringGenerator
(
int
length
)
{
this
.
length
=
length
;
}
public
StringGenerator
(
char
[]
defaultCode
,
int
length
)
{
this
.
DEFAULT_CODEC
=
defaultCode
;
this
.
length
=
length
;
}
public
String
randomGenerate
()
{
byte
[]
verifierBytes
=
new
byte
[
length
];
random
.
nextBytes
(
verifierBytes
);
return
getString
(
verifierBytes
);
}
public
String
uuidGenerate
()
{
return
UUID
.
randomUUID
().
toString
().
toLowerCase
();
}
public
String
uniqueGenerate
()
{
StringBuffer
uniqueString
=
new
StringBuffer
(
""
);
this
.
length
=
9
;
String
randomString
=
randomGenerate
();
uniqueString
.
append
(
randomString
.
subSequence
(
0
,
4
));
Date
currentDate
=
new
Date
();
DateFormat
dateFormat
=
new
SimpleDateFormat
(
"ddMMyyyyHHmmssSSS"
);
String
dateString
=
Base64Utils
.
encodeBase64
(
dateFormat
.
format
(
currentDate
).
getBytes
());
dateString
=
dateString
.
substring
(
0
,
dateString
.
length
()-
1
);
uniqueString
.
append
(
dateString
);
uniqueString
.
append
(
randomString
.
subSequence
(
5
,
8
));
return
uniqueString
.
toString
();
}
/**
* Convert these random bytes to a verifier string. The length of the byte array can be
* {@link #setLength(int) configured}. The default implementation mods the bytes to fit into the
* ASCII letters 1-9, A-Z, a-z .
*
* @param verifierBytes The bytes.
* @return The string.
*/
protected
String
getString
(
byte
[]
verifierBytes
)
{
char
[]
chars
=
new
char
[
verifierBytes
.
length
];
for
(
int
i
=
0
;
i
<
verifierBytes
.
length
;
i
++)
{
chars
[
i
]
=
DEFAULT_CODEC
[((
verifierBytes
[
i
]
&
0xFF
)
%
DEFAULT_CODEC
.
length
)];
}
return
new
String
(
chars
);
}
/**
* The random value generator used to create token secrets.
*
* @param random The random value generator used to create token secrets.
*/
public
void
setRandom
(
Random
random
)
{
this
.
random
=
random
;
}
/**
* The length of string to generate.
*
* @param length the length to set
*/
public
void
setLength
(
int
length
)
{
this
.
length
=
length
;
}
public
static
boolean
uuidMatches
(
String
uuidString
)
{
return
uuidString
.
matches
(
uuidRegex
);
}
}
/**
* Create a generator with the default length (6).
*/
public
StringGenerator
()
{
this
(
6
);
}
/**
* Create a generator of random strings of the length provided.
*
* @param length the length of the strings generated
*/
public
StringGenerator
(
int
length
)
{
this
.
length
=
length
;
}
public
StringGenerator
(
char
[]
defaultCode
,
int
length
)
{
this
.
codec
=
defaultCode
;
this
.
length
=
length
;
}
/**
* randomGenerate.
* @return
*/
public
String
randomGenerate
()
{
byte
[]
verifierBytes
=
new
byte
[
length
];
random
.
nextBytes
(
verifierBytes
);
return
getString
(
verifierBytes
);
}
public
String
uuidGenerate
()
{
return
UUID
.
randomUUID
().
toString
().
toLowerCase
();
}
/**
* uniqueGenerate.
* @return
*/
public
String
uniqueGenerate
()
{
StringBuffer
uniqueString
=
new
StringBuffer
(
""
);
this
.
length
=
9
;
String
randomString
=
randomGenerate
();
uniqueString
.
append
(
randomString
.
subSequence
(
0
,
4
));
Date
currentDate
=
new
Date
();
DateFormat
dateFormat
=
new
SimpleDateFormat
(
"ddMMyyyyHHmmssSSS"
);
String
dateString
=
Base64Utils
.
encodeBase64
(
dateFormat
.
format
(
currentDate
).
getBytes
());
dateString
=
dateString
.
substring
(
0
,
dateString
.
length
()
-
1
);
uniqueString
.
append
(
dateString
);
uniqueString
.
append
(
randomString
.
subSequence
(
5
,
8
));
return
uniqueString
.
toString
();
}
/**
* Convert these random bytes to a verifier string. The length of the byte array
* can be {@link #setLength(int) configured}. The default implementation mods
* the bytes to fit into the ASCII letters 1-9, A-Z, a-z .
*
* @param verifierBytes The bytes.
* @return The string.
*/
protected
String
getString
(
byte
[]
verifierBytes
)
{
char
[]
chars
=
new
char
[
verifierBytes
.
length
];
for
(
int
i
=
0
;
i
<
verifierBytes
.
length
;
i
++)
{
chars
[
i
]
=
codec
[((
verifierBytes
[
i
]
&
0xFF
)
%
codec
.
length
)];
}
return
new
String
(
chars
);
}
/**
* The random value generator used to create token secrets.
*
* @param random The random value generator used to create token secrets.
*/
public
void
setRandom
(
Random
random
)
{
this
.
random
=
random
;
}
/**
* The length of string to generate.
*
* @param length the length to set
*/
public
void
setLength
(
int
length
)
{
this
.
length
=
length
;
}
public
void
setCodec
(
char
[]
codec
)
{
this
.
codec
=
codec
;
}
public
static
boolean
uuidMatches
(
String
uuidString
)
{
return
uuidString
.
matches
(
uuidRegex
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录