Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
cfbec47a
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cfbec47a
编写于
8月 24, 2020
作者:
H
Haoran Meng
提交者:
GitHub
8月 24, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7016 from terrymanu/dev
Decouple AuthenticationEngine.handshake() and BackendConnection
上级
12028966
5d5df2ab
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
27 addition
and
29 deletion
+27
-29
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/ConnectionIdGenerator.java
.../shardingsphere/proxy/frontend/ConnectionIdGenerator.java
+1
-1
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
...e/proxy/frontend/netty/FrontendChannelInboundHandler.java
+1
-1
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngine.java
.../proxy/frontend/mysql/auth/MySQLAuthenticationEngine.java
+4
-4
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java
...proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java
+1
-1
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngineTest.java
...xy/frontend/mysql/auth/MySQLAuthenticationEngineTest.java
+14
-16
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java
...ntend/postgresql/auth/PostgreSQLAuthenticationEngine.java
+4
-4
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/engine/AuthenticationEngine.java
...ingsphere/proxy/frontend/engine/AuthenticationEngine.java
+2
-2
未找到文件。
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/ConnectionIdGenerator.java
浏览文件 @
cfbec47a
...
...
@@ -37,7 +37,7 @@ public final class ConnectionIdGenerator {
*/
public
static
ConnectionIdGenerator
getInstance
()
{
return
INSTANCE
;
}
}
/**
* Get next connection ID.
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
浏览文件 @
cfbec47a
...
...
@@ -58,7 +58,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
@Override
public
void
channelActive
(
final
ChannelHandlerContext
context
)
{
ChannelThreadExecutorGroup
.
getInstance
().
register
(
context
.
channel
().
id
());
databaseProtocolFrontendEngine
.
getAuthEngine
().
handshake
(
context
,
backendConnection
);
backendConnection
.
setConnectionId
(
databaseProtocolFrontendEngine
.
getAuthEngine
().
handshake
(
context
)
);
// TODO ref #7013
SingletonFacadeEngine
.
buildMetrics
().
ifPresent
(
metricsHandlerFacade
->
metricsHandlerFacade
.
gaugeIncrement
(
MetricsLabelEnum
.
CHANNEL_COUNT
.
getName
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngine.java
浏览文件 @
cfbec47a
...
...
@@ -58,11 +58,11 @@ public final class MySQLAuthenticationEngine implements AuthenticationEngine {
private
String
database
;
@Override
public
void
handshake
(
final
ChannelHandlerContext
context
,
final
BackendConnection
backendConnection
)
{
int
connectionId
=
ConnectionIdGenerator
.
getInstance
().
nextId
();
backendConnection
.
setConnectionId
(
connectionId
);
public
int
handshake
(
final
ChannelHandlerContext
context
)
{
int
result
=
ConnectionIdGenerator
.
getInstance
().
nextId
();
connectionPhase
=
MySQLConnectionPhase
.
AUTH_PHASE_FAST_PATH
;
context
.
writeAndFlush
(
new
MySQLHandshakePacket
(
connectionId
,
authenticationHandler
.
getAuthPluginData
()));
context
.
writeAndFlush
(
new
MySQLHandshakePacket
(
result
,
authenticationHandler
.
getAuthPluginData
()));
return
result
;
}
@Override
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java
浏览文件 @
cfbec47a
...
...
@@ -91,7 +91,7 @@ public final class MySQLProtocolFrontendEngineTest {
@Test
public
void
assertHandshake
()
{
mysqlProtocolFrontendEngine
.
getAuthEngine
().
handshake
(
context
,
mock
(
BackendConnection
.
class
)
);
assertTrue
(
mysqlProtocolFrontendEngine
.
getAuthEngine
().
handshake
(
context
)
>
0
);
verify
(
context
).
writeAndFlush
(
isA
(
MySQLHandshakePacket
.
class
));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngineTest.java
浏览文件 @
cfbec47a
...
...
@@ -45,8 +45,8 @@ import java.util.Properties;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyInt
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -54,31 +54,29 @@ import static org.mockito.Mockito.verify;
import
static
org
.
mockito
.
Mockito
.
when
;
public
final
class
MySQLAuthenticationEngineTest
{
private
final
MySQLAuthenticationHandler
authenticationHandler
=
mock
(
MySQLAuthenticationHandler
.
class
);
private
final
MySQLAuthenticationEngine
authenticationEngine
=
new
MySQLAuthenticationEngine
();
private
final
byte
[]
authResponse
=
{-
27
,
89
,
-
20
,
-
27
,
65
,
-
120
,
-
64
,
-
101
,
86
,
-
100
,
-
108
,
-
100
,
6
,
-
125
,
-
37
,
117
,
14
,
-
43
,
95
,
-
113
};
@Before
public
void
setUp
()
throws
NoSuchFieldException
,
IllegalAccessException
{
initAuthenticationHandlerForAuthenticationEngine
();
}
private
void
initAuthenticationHandlerForAuthenticationEngine
()
throws
NoSuchFieldException
,
IllegalAccessException
{
Field
field
=
MySQLAuthenticationEngine
.
class
.
getDeclaredField
(
"authenticationHandler"
);
field
.
setAccessible
(
true
);
field
.
set
(
authenticationEngine
,
authenticationHandler
);
}
@Test
public
void
assertHandshake
()
{
ChannelHandlerContext
context
=
getContext
();
BackendConnection
backendConnection
=
mock
(
BackendConnection
.
class
);
authenticationEngine
.
handshake
(
context
,
backendConnection
);
assertTrue
(
authenticationEngine
.
handshake
(
context
)
>
0
);
verify
(
context
).
writeAndFlush
(
any
(
MySQLHandshakePacket
.
class
));
verify
(
backendConnection
).
setConnectionId
(
anyInt
());
}
@Test
...
...
@@ -100,7 +98,7 @@ public final class MySQLAuthenticationEngineTest {
authenticationEngine
.
auth
(
channelHandlerContext
,
payload
,
mock
(
BackendConnection
.
class
));
assertThat
(
getAuthResponse
(),
is
(
authResponse
));
}
@Test
public
void
assertAuthWithLoginFail
()
throws
NoSuchFieldException
,
IllegalAccessException
{
setConnectionPhase
(
MySQLConnectionPhase
.
AUTH_PHASE_FAST_PATH
);
...
...
@@ -110,7 +108,7 @@ public final class MySQLAuthenticationEngineTest {
authenticationEngine
.
auth
(
context
,
getPayload
(
"root"
,
"sharding_db"
,
authResponse
),
mock
(
BackendConnection
.
class
));
verify
(
context
).
writeAndFlush
(
any
(
MySQLErrPacket
.
class
));
}
@Test
public
void
assertAuthWithAbsentDatabase
()
throws
NoSuchFieldException
,
IllegalAccessException
{
ChannelHandlerContext
context
=
getContext
();
...
...
@@ -119,7 +117,7 @@ public final class MySQLAuthenticationEngineTest {
authenticationEngine
.
auth
(
context
,
getPayload
(
"root"
,
"ABSENT DATABASE"
,
authResponse
),
mock
(
BackendConnection
.
class
));
verify
(
context
).
writeAndFlush
(
any
(
MySQLErrPacket
.
class
));
}
@Test
public
void
assertAuth
()
throws
NoSuchFieldException
,
IllegalAccessException
{
setConnectionPhase
(
MySQLConnectionPhase
.
AUTH_PHASE_FAST_PATH
);
...
...
@@ -145,19 +143,19 @@ public final class MySQLAuthenticationEngineTest {
when
(
result
.
readStringNulByBytes
()).
thenReturn
(
authResponse
);
return
result
;
}
private
ChannelHandlerContext
getContext
()
{
ChannelHandlerContext
result
=
mock
(
ChannelHandlerContext
.
class
);
doReturn
(
getChannel
()).
when
(
result
).
channel
();
return
result
;
}
private
Channel
getChannel
()
{
Channel
result
=
mock
(
Channel
.
class
);
doReturn
(
getRemoteAddress
()).
when
(
result
).
remoteAddress
();
return
result
;
}
private
SocketAddress
getRemoteAddress
()
{
SocketAddress
result
=
mock
(
SocketAddress
.
class
);
when
(
result
.
toString
()).
thenReturn
(
"127.0.0.1"
);
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java
浏览文件 @
cfbec47a
...
...
@@ -57,10 +57,10 @@ public final class PostgreSQLAuthenticationEngine implements AuthenticationEngin
private
volatile
byte
[]
md5Salt
;
@Override
public
void
handshake
(
final
ChannelHandlerContext
context
,
final
BackendConnection
backendConnection
)
{
int
connectionId
=
ConnectionIdGenerator
.
getInstance
().
nextId
();
backendConnection
.
setConnectionId
(
connectionId
);
BinaryStatementRegistry
.
getInstance
().
register
(
connectionId
)
;
public
int
handshake
(
final
ChannelHandlerContext
context
)
{
int
result
=
ConnectionIdGenerator
.
getInstance
().
nextId
();
BinaryStatementRegistry
.
getInstance
().
register
(
result
);
return
result
;
}
@Override
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/engine/AuthenticationEngine.java
浏览文件 @
cfbec47a
...
...
@@ -30,9 +30,9 @@ public interface AuthenticationEngine {
* Handshake.
*
* @param context channel handler context
* @
param backendConnection backend connection
* @
return connection ID
*/
void
handshake
(
ChannelHandlerContext
context
,
BackendConnection
backendConnection
);
int
handshake
(
ChannelHandlerContext
context
);
/**
* Authentication.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录