Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
2a8061ad
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
2a8061ad
编写于
5月 22, 2020
作者:
J
Juan Pan(Trista)
提交者:
GitHub
5月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace authentication of ShardingSphereProxyContext (#5752)
上级
8ffb18e9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
25 addition
and
28 deletion
+25
-28
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandler.java
...proxy/frontend/mysql/auth/MySQLAuthenticationHandler.java
+4
-4
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
...nd/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
+1
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
...and/query/binary/execute/MySQLComStmtExecuteExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
...command/query/text/query/MySQLComQueryPacketExecutor.java
+3
-3
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
+5
-6
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
...y/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
+5
-6
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
.../command/query/binary/bind/PostgreSQLComBindExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
...gresql/command/query/text/PostgreSQLComQueryExecutor.java
+3
-3
未找到文件。
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandler.java
浏览文件 @
2a8061ad
...
...
@@ -21,10 +21,10 @@ import com.google.common.base.Strings;
import
lombok.Getter
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData
;
import
org.apache.shardingsphere.proxy.context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts
;
import
java.util.Arrays
;
import
java.util.Collection
;
...
...
@@ -37,7 +37,7 @@ import java.util.Optional;
@Getter
public
final
class
MySQLAuthenticationHandler
{
private
static
final
ShardingSphereProxyContext
SHARDING_PROXY_CONTEXT
=
ShardingSphereProxyContext
.
getInstance
();
private
static
final
ProxySchemaContexts
PROXY_SCHEMA_CONTEXTS
=
ProxySchemaContexts
.
getInstance
();
private
final
MySQLAuthPluginData
authPluginData
=
new
MySQLAuthPluginData
();
...
...
@@ -61,7 +61,7 @@ public final class MySQLAuthenticationHandler {
}
private
Optional
<
ProxyUser
>
getUser
(
final
String
username
)
{
for
(
Entry
<
String
,
ProxyUser
>
entry
:
SHARDING_PROXY_CONTEXT
.
getAuthentication
().
getUsers
().
entrySet
())
{
for
(
Entry
<
String
,
ProxyUser
>
entry
:
PROXY_SCHEMA_CONTEXTS
.
getSchemaContexts
()
.
getAuthentication
().
getUsers
().
entrySet
())
{
if
(
entry
.
getKey
().
equals
(
username
))
{
return
Optional
.
of
(
entry
.
getValue
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
浏览文件 @
2a8061ad
...
...
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket;
import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts
;
import
org.apache.shardingsphere.proxy.context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.proxy.frontend.api.CommandExecutor
;
import
org.apache.shardingsphere.sql.parser.sql.util.SQLUtil
;
...
...
@@ -53,7 +52,7 @@ public final class MySQLComInitDbExecutor implements CommandExecutor {
}
private
boolean
isAuthorizedSchema
(
final
String
schema
)
{
Collection
<
String
>
authorizedSchemas
=
ShardingSphereProxyContext
.
getInstance
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUserName
()).
getAuthorizedSchemas
();
Collection
<
String
>
authorizedSchemas
=
ProxySchemaContexts
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUserName
()).
getAuthorizedSchemas
();
return
authorizedSchemas
.
isEmpty
()
||
authorizedSchemas
.
contains
(
schema
);
}
}
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
浏览文件 @
2a8061ad
...
...
@@ -38,7 +38,7 @@ import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryHeader
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.
context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.proxy.
backend.schema.ProxySchemaContexts
;
import
org.apache.shardingsphere.proxy.frontend.api.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.mysql.MySQLErrPacketFactory
;
...
...
@@ -73,7 +73,7 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
>
execute
()
{
if
(
ShardingSphereProxyContext
.
getInstance
().
isCircuitBreak
())
{
if
(
ProxySchemaContexts
.
getInstance
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
MySQLErrPacket
(
1
,
CommonErrorCode
.
CIRCUIT_BREAK_MODE
));
}
BackendResponse
backendResponse
=
databaseCommunicationEngine
.
execute
();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
浏览文件 @
2a8061ad
...
...
@@ -30,18 +30,18 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLEofPacket
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket
;
import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket
;
import
org.apache.shardingsphere.infra.database.type.DatabaseTypes
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryHeader
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory
;
import
org.apache.shardingsphere.proxy.context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.proxy.frontend.api.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.mysql.MySQLErrPacketFactory
;
import
org.apache.shardingsphere.infra.database.type.DatabaseTypes
;
import
java.sql.SQLException
;
import
java.util.Collection
;
...
...
@@ -72,7 +72,7 @@ public final class MySQLComQueryPacketExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
>
execute
()
throws
SQLException
{
if
(
ShardingSphereProxyContext
.
getInstance
().
isCircuitBreak
())
{
if
(
ProxySchemaContexts
.
getInstance
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
MySQLErrPacket
(
1
,
CommonErrorCode
.
CIRCUIT_BREAK_MODE
));
}
BackendResponse
backendResponse
=
textProtocolBackendHandler
.
execute
();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java
浏览文件 @
2a8061ad
...
...
@@ -20,15 +20,16 @@ package org.apache.shardingsphere.proxy.frontend.mysql;
import
io.netty.channel.Channel
;
import
io.netty.channel.ChannelHandlerContext
;
import
lombok.SneakyThrows
;
import
org.apache.shardingsphere.infra.auth.Authentication
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConnectionPhase
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLHandshakePacket
;
import
org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload
;
import
org.apache.shardingsphere.infra.auth.Authentication
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.orchestration.core.common.event.AuthenticationChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.eventbus.ShardingOrchestrationEventBus
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.proxy.frontend.ConnectionIdGenerator
;
import
org.apache.shardingsphere.proxy.frontend.mysql.auth.MySQLAuthenticationEngine
;
import
org.junit.Before
;
...
...
@@ -121,9 +122,7 @@ public final class MySQLProtocolFrontendEngineTest {
private
void
setAuthentication
(
final
ProxyUser
proxyUser
)
{
Authentication
authentication
=
new
Authentication
();
authentication
.
getUsers
().
put
(
"root"
,
proxyUser
);
Field
field
=
ShardingSphereProxyContext
.
class
.
getDeclaredField
(
"authentication"
);
field
.
setAccessible
(
true
);
field
.
set
(
ShardingSphereProxyContext
.
getInstance
(),
authentication
);
ShardingOrchestrationEventBus
.
getInstance
().
post
(
new
AuthenticationChangedEvent
(
authentication
));
}
@SneakyThrows
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
浏览文件 @
2a8061ad
...
...
@@ -19,11 +19,12 @@ package org.apache.shardingsphere.proxy.frontend.mysql.auth;
import
com.google.common.primitives.Bytes
;
import
lombok.SneakyThrows
;
import
org.apache.shardingsphere.infra.auth.Authentication
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData
;
import
org.apache.shardingsphere.proxy.context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.infra.auth.Authentication
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.orchestration.core.common.event.AuthenticationChangedEvent
;
import
org.apache.shardingsphere.orchestration.core.common.eventbus.ShardingOrchestrationEventBus
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -94,9 +95,7 @@ public final class MySQLAuthenticationHandlerTest {
private
void
setAuthentication
(
final
ProxyUser
proxyUser
)
{
Authentication
authentication
=
new
Authentication
();
authentication
.
getUsers
().
put
(
"root"
,
proxyUser
);
Field
field
=
ShardingSphereProxyContext
.
class
.
getDeclaredField
(
"authentication"
);
field
.
setAccessible
(
true
);
field
.
set
(
ShardingSphereProxyContext
.
getInstance
(),
authentication
);
ShardingOrchestrationEventBus
.
getInstance
().
post
(
new
AuthenticationChangedEvent
(
authentication
));
}
@Test
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
浏览文件 @
2a8061ad
...
...
@@ -38,7 +38,7 @@ import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryHeader
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.
context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.proxy.
backend.schema.ProxySchemaContexts
;
import
org.apache.shardingsphere.proxy.frontend.api.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.postgresql.PostgreSQLErrPacketFactory
;
...
...
@@ -75,7 +75,7 @@ public final class PostgreSQLComBindExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
>
execute
()
{
if
(
ShardingSphereProxyContext
.
getInstance
().
isCircuitBreak
())
{
if
(
ProxySchemaContexts
.
getInstance
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
PostgreSQLErrorResponsePacket
());
}
List
<
DatabasePacket
>
result
=
new
LinkedList
<>();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
浏览文件 @
2a8061ad
...
...
@@ -26,18 +26,18 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.tex
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.text.PostgreSQLDataRowPacket
;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket
;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLErrorResponsePacket
;
import
org.apache.shardingsphere.infra.database.type.DatabaseTypes
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryHeader
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory
;
import
org.apache.shardingsphere.proxy.context.ShardingSphereProxyContext
;
import
org.apache.shardingsphere.proxy.frontend.api.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.postgresql.PostgreSQLErrPacketFactory
;
import
org.apache.shardingsphere.infra.database.type.DatabaseTypes
;
import
java.sql.SQLException
;
import
java.util.Collection
;
...
...
@@ -67,7 +67,7 @@ public final class PostgreSQLComQueryExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
>
execute
()
throws
SQLException
{
if
(
ShardingSphereProxyContext
.
getInstance
().
isCircuitBreak
())
{
if
(
ProxySchemaContexts
.
getInstance
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
PostgreSQLErrorResponsePacket
());
}
BackendResponse
backendResponse
=
textProtocolBackendHandler
.
execute
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录