提交 3b9e5073 编写于 作者: T terrymanu

remove AuthType

上级 3659d607
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* 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.
* </p>
*/
package io.shardingsphere.proxy.backend.netty.client.response;
/**
* Auth Type.
*
* @author linjiaqi
*/
public enum AuthType {
UN_AUTH, AUTHING, AUTH_FIN
}
...@@ -29,26 +29,18 @@ import io.netty.channel.ChannelInboundHandlerAdapter; ...@@ -29,26 +29,18 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
*/ */
public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { public abstract class ResponseHandler extends ChannelInboundHandlerAdapter {
private AuthType authType = AuthType.UN_AUTH; private boolean authorized;
@Override @Override
public void channelRead(final ChannelHandlerContext context, final Object message) { public void channelRead(final ChannelHandlerContext context, final Object message) {
ByteBuf byteBuf = (ByteBuf) message; ByteBuf byteBuf = (ByteBuf) message;
int header = getHeader(byteBuf); int header = getHeader(byteBuf);
switch (authType) {
case UN_AUTH: if (!authorized) {
auth(context, byteBuf); auth(context, byteBuf);
authType = AuthType.AUTHING; authorized = true;
break; } else {
case AUTHING: executeCommand(context, byteBuf, header);
authing(context, byteBuf, header);
authType = AuthType.AUTH_FIN;
break;
case AUTH_FIN:
executeCommand(context, byteBuf, header);
break;
default:
throw new UnsupportedOperationException(authType.name());
} }
} }
...@@ -56,8 +48,6 @@ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { ...@@ -56,8 +48,6 @@ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter {
protected abstract void auth(ChannelHandlerContext context, ByteBuf byteBuf); protected abstract void auth(ChannelHandlerContext context, ByteBuf byteBuf);
protected abstract void authing(ChannelHandlerContext context, ByteBuf byteBuf, int header);
protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf byteBuf, int header); protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf byteBuf, int header);
@Override @Override
......
...@@ -108,15 +108,6 @@ public final class MySQLResponseHandler extends ResponseHandler { ...@@ -108,15 +108,6 @@ public final class MySQLResponseHandler extends ResponseHandler {
} }
} }
@Override
protected void authing(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) {
if (OKPacket.HEADER == header) {
okPacket(context, byteBuf);
} else {
errPacket(context, byteBuf);
}
}
@Override @Override
protected void executeCommand(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { protected void executeCommand(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) {
switch (header) { switch (header) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册