Commit 3b9e5073 authored by terrymanu's avatar terrymanu
Browse files

remove AuthType

parent 3659d607
Loading
Loading
Loading
Loading
+0 −28
Original line number Diff line number Diff line
/*
 * 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
}
+7 −17
Original line number Diff line number Diff line
@@ -29,26 +29,18 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
 */
public abstract class ResponseHandler extends ChannelInboundHandlerAdapter {
    
    private AuthType authType = AuthType.UN_AUTH;
    private boolean authorized;
    
    @Override
    public void channelRead(final ChannelHandlerContext context, final Object message) {
        ByteBuf byteBuf = (ByteBuf) message;
        int header = getHeader(byteBuf);
        switch (authType) {
            case UN_AUTH:
        
        if (!authorized) {
            auth(context, byteBuf);
                authType = AuthType.AUTHING;
                break;
            case AUTHING:
                authing(context, byteBuf, header);
                authType = AuthType.AUTH_FIN;
                break;
            case AUTH_FIN:
            authorized = true;
        } else {
            executeCommand(context, byteBuf, header);
                break;
            default:
                throw new UnsupportedOperationException(authType.name());
        }
    }
    
@@ -56,8 +48,6 @@ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter {
    
    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);
    
    @Override
+0 −9
Original line number Diff line number Diff line
@@ -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
    protected void executeCommand(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) {
        switch (header) {