All Downloads are FREE. Search and download functionalities are using the official Maven repository.

link.jfire.socket.socketserver.interceptor.impl.AuthInterceptor Maven / Gradle / Ivy

Go to download

Jfire - socket is a server-side framework based on AIO. Users only need a simple implementation of a business logic processing interface can be the business data processing. The framework provides the client and server at the same time. Have strong connection capacity. Single server provides tens of thousands of connections.

The newest version!
package link.jfire.socket.socketserver.interceptor.impl;

import link.jfire.baseutil.simplelog.ConsoleLogFactory;
import link.jfire.baseutil.simplelog.Logger;
import link.jfire.socket.socketserver.bus.BusinessCommand;
import link.jfire.socket.socketserver.bus.Message;
import link.jfire.socket.socketserver.interceptor.MessageInterceptor;

public class AuthInterceptor implements MessageInterceptor
{
    private Logger logger = ConsoleLogFactory.getLogger();
    
    @Override
    public int getOrder()
    {
        return Integer.MIN_VALUE;
    }
    
    @Override
    public int inInterceptor(Message message)
    {
        if (message.getChannelInfo().isAuthentication())
        {
            return MessageInterceptor.next;
        }
        else
        {
            if (message.getCommand() == BusinessCommand.AUTH || message.getCommand() == BusinessCommand.SENDKEY)
            {
                return MessageInterceptor.end;
            }
            else
            {
                logger.warn("未授权异常线路,地址为{}。关闭该线路。", message.getChannelInfo().getAddress());
                message.getChannelInfo().close();
                return MessageInterceptor.interceptored;
            }
        }
    }
    
    @Override
    public int outInterceptor(Message message)
    {
        return MessageInterceptor.end;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy