Example usage for io.netty.handler.codec.socksx.v5 Socks5PasswordAuthRequest password

List of usage examples for io.netty.handler.codec.socksx.v5 Socks5PasswordAuthRequest password

Introduction

In this page you can find the example usage for io.netty.handler.codec.socksx.v5 Socks5PasswordAuthRequest password.

Prototype

String password();

Source Link

Document

Returns the password of this request.

Usage

From source file:com.github.sinsinpub.pero.manual.proxyhandler.Socks5ProxyServer.java

License:Apache License

boolean authenticate(ChannelHandlerContext ctx, Object msg) {
    if (username == null) {
        ctx.pipeline().replace(DECODER, DECODER, new Socks5CommandRequestDecoder());
        ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH));
        return true;
    }/*from  ww w. j  ava 2s  . c o m*/

    if (msg instanceof Socks5InitialRequest) {
        ctx.pipeline().replace(DECODER, DECODER, new Socks5PasswordAuthRequestDecoder());
        ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.PASSWORD));
        return false;
    }

    Socks5PasswordAuthRequest req = (Socks5PasswordAuthRequest) msg;
    if (req.username().equals(username) && req.password().equals(password)) {
        ctx.pipeline().replace(DECODER, DECODER, new Socks5CommandRequestDecoder());
        ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS));
        return true;
    }

    ctx.pipeline().replace(DECODER, DECODER, new Socks5PasswordAuthRequestDecoder());
    ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE));
    return false;
}