Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MaxKey单点登录官方(MaxKeyTop)
MaxKey
提交
6caa74b0
MaxKey
项目概览
MaxKey单点登录官方(MaxKeyTop)
/
MaxKey
9 个月 前同步成功
通知
75
Star
3
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MaxKey
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6caa74b0
编写于
2月 20, 2022
作者:
M
MaxKey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HttpEncoder StreamUtils Preconditions
上级
76f089a3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
175 addition
and
13 deletion
+175
-13
maxkey-common/src/main/java/org/maxkey/util/HttpEncoder.java
maxkey-common/src/main/java/org/maxkey/util/HttpEncoder.java
+7
-6
maxkey-common/src/main/java/org/maxkey/util/Preconditions.java
...y-common/src/main/java/org/maxkey/util/Preconditions.java
+93
-0
maxkey-common/src/main/java/org/maxkey/util/StreamUtils.java
maxkey-common/src/main/java/org/maxkey/util/StreamUtils.java
+65
-0
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyApplication.java
...eb-maxkey/src/main/java/org/maxkey/MaxKeyApplication.java
+3
-3
maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtApplication.java
...eb-mgt/src/main/java/org/maxkey/MaxKeyMgtApplication.java
+7
-4
未找到文件。
maxkey-common/src/main/java/org/maxkey/util/HttpEncoder.java
浏览文件 @
6caa74b0
...
...
@@ -35,16 +35,17 @@ public abstract class HttpEncoder {
ENCODING_RULES
=
Collections
.
unmodifiableMap
(
rules
);
}
public
static
String
encode
(
String
plain
)
throws
Exception
{
String
encoded
;
public
static
String
encode
(
String
plain
)
{
String
encoded
=
null
;
try
{
encoded
=
URLEncoder
.
encode
(
plain
,
CHARSET
);
for
(
Map
.
Entry
<
String
,
String
>
rule
:
ENCODING_RULES
.
entrySet
())
{
encoded
=
applyRule
(
encoded
,
rule
.
getKey
(),
rule
.
getValue
());
}
}
catch
(
UnsupportedEncodingException
uee
)
{
throw
new
Exception
(
"Charset not found while encoding string: "
+
CHARSET
,
uee
);
}
for
(
Map
.
Entry
<
String
,
String
>
rule
:
ENCODING_RULES
.
entrySet
())
{
encoded
=
applyRule
(
encoded
,
rule
.
getKey
(),
rule
.
getValue
());
uee
.
printStackTrace
();
}
return
encoded
;
}
...
...
maxkey-common/src/main/java/org/maxkey/util/Preconditions.java
0 → 100644
浏览文件 @
6caa74b0
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed 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
org.maxkey.util
;
import
java.util.Locale
;
import
java.util.regex.Pattern
;
import
org.maxkey.client.oauth.model.OAuthConstants
;
/**
* Utils for checking preconditions and invariants
*/
public
abstract
class
Preconditions
{
private
static
final
String
DEFAULT_MESSAGE
=
"Received an invalid parameter"
;
// scheme = alpha *( alpha | digit | "+" | "-" | "." )
private
static
final
String
URL_REGEXP
=
"^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+"
;
/**
* Checks that an object is not null.
*
* @param object any object
* @param errorMsg error message
*
* @throws IllegalArgumentException if the object is null
*/
public
static
void
checkNotNull
(
Object
object
,
String
errorMsg
)
{
check
(
object
!=
null
,
errorMsg
);
}
/**
* Checks that a string is not null or empty
*
* @param string any string
* @param errorMsg error message
*
* @throws IllegalArgumentException if the string is null or empty
*/
public
static
void
checkEmptyString
(
String
string
,
String
errorMsg
)
{
check
(
string
!=
null
&&
!
string
.
trim
().
isEmpty
(),
errorMsg
);
}
/**
* Checks that a URL is valid
*
* @param url any string
* @param errorMsg error message
*/
public
static
void
checkValidUrl
(
String
url
,
String
errorMsg
)
{
checkEmptyString
(
url
,
errorMsg
);
check
(
isUrl
(
url
),
errorMsg
);
}
/**
* Checks that a URL is a valid OAuth callback
*
* @param url any string
* @param errorMsg error message
*/
public
static
void
checkValidOAuthCallback
(
String
url
,
String
errorMsg
)
{
checkEmptyString
(
url
,
errorMsg
);
if
(
url
.
toLowerCase
(
Locale
.
getDefault
()).
compareToIgnoreCase
(
OAuthConstants
.
OUT_OF_BAND
)
!=
0
)
{
check
(
isUrl
(
url
),
errorMsg
);
}
}
private
static
boolean
isUrl
(
String
url
)
{
return
Pattern
.
compile
(
URL_REGEXP
).
matcher
(
url
).
matches
();
}
private
static
void
check
(
boolean
requirements
,
String
error
)
{
if
(!
requirements
)
{
throw
new
IllegalArgumentException
(
error
==
null
||
error
.
trim
().
length
()
<=
0
?
DEFAULT_MESSAGE
:
error
);
}
}
}
maxkey-common/src/main/java/org/maxkey/util/StreamUtils.java
0 → 100644
浏览文件 @
6caa74b0
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed 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
org.maxkey.util
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.util.zip.GZIPInputStream
;
/**
* Utils to deal with Streams.
*/
public
abstract
class
StreamUtils
{
/**
* Returns the stream contents as an UTF-8 encoded string
*
* @param is input stream
* @return string contents
* @throws java.io.IOException in any. SocketTimeout in example
*/
public
static
String
getStreamContents
(
InputStream
is
)
throws
IOException
{
Preconditions
.
checkNotNull
(
is
,
"Cannot get String from a null object"
);
final
char
[]
buffer
=
new
char
[
0x10000
];
final
StringBuilder
out
=
new
StringBuilder
();
try
(
Reader
in
=
new
InputStreamReader
(
is
,
"UTF-8"
))
{
int
read
;
do
{
read
=
in
.
read
(
buffer
,
0
,
buffer
.
length
);
if
(
read
>
0
)
{
out
.
append
(
buffer
,
0
,
read
);
}
}
while
(
read
>=
0
);
}
return
out
.
toString
();
}
/**
* Return String content from a gzip stream
*
* @param is input stream
* @return string contents
* @throws java.io.IOException in any. SocketTimeout in example
*/
public
static
String
getGzipStreamContents
(
InputStream
is
)
throws
IOException
{
Preconditions
.
checkNotNull
(
is
,
"Cannot get String from a null object"
);
final
GZIPInputStream
gis
=
new
GZIPInputStream
(
is
);
return
getStreamContents
(
gis
);
}
}
\ No newline at end of file
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyApplication.java
浏览文件 @
6caa74b0
...
...
@@ -54,9 +54,9 @@ public class MaxKeyApplication extends SpringBootServletInitializer {
}
catch
(
ServletException
e
)
{
_logger
.
error
(
"ServletException"
,
e
);
}
_logger
.
info
(
"MaxKey at
"
+
new
DateTime
());
_logger
.
info
(
"MaxKey Server Port "
+
applicationContext
.
getBean
(
ApplicationConfig
.
class
).
getPort
());
_logger
.
info
(
"MaxKey at
{}"
,
new
DateTime
());
_logger
.
info
(
"MaxKey Server Port
{}
"
,
applicationContext
.
getBean
(
ApplicationConfig
.
class
).
getPort
());
_logger
.
info
(
"MaxKey started."
);
}
...
...
maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtApplication.java
浏览文件 @
6caa74b0
...
...
@@ -61,16 +61,19 @@ public class MaxKeyMgtApplication extends SpringBootServletInitializer {
public
static
void
main
(
String
[]
args
)
{
_logger
.
info
(
"Start MaxKeyMgtApplication ..."
);
ConfigurableApplicationContext
applicationContext
=
SpringApplication
.
run
(
MaxKeyMgtApplication
.
class
,
args
);
InitializeContext
initWebContext
=
new
InitializeContext
(
applicationContext
);
ConfigurableApplicationContext
applicationContext
=
SpringApplication
.
run
(
MaxKeyMgtApplication
.
class
,
args
);
InitializeContext
initWebContext
=
new
InitializeContext
(
applicationContext
);
try
{
initWebContext
.
init
(
null
);
}
catch
(
ServletException
e
)
{
_logger
.
error
(
"Exception "
,
e
);
}
_logger
.
info
(
"MaxKeyMgt at "
+
new
DateTime
());
_logger
.
info
(
"MaxKeyMgt Server Port "
+
applicationContext
.
getBean
(
ApplicationConfig
.
class
).
getPort
());
_logger
.
info
(
"MaxKeyMgt at {}"
,
new
DateTime
());
_logger
.
info
(
"MaxKeyMgt Server Port {}"
,
applicationContext
.
getBean
(
ApplicationConfig
.
class
).
getPort
());
_logger
.
info
(
"MaxKeyMgt started."
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录