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

org.beifengtz.jvmm.server.handler.HttpServerHandler Maven / Gradle / Ivy

Go to download

Provides access to operating system, process, thread and other information during Java runtime.

There is a newer version: 2.4.3
Show newest version
package org.beifengtz.jvmm.server.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import org.beifengtz.jvmm.common.factory.LoggerFactory;
import org.beifengtz.jvmm.common.util.StringUtil;
import org.beifengtz.jvmm.convey.handler.HttpChannelHandler;
import org.beifengtz.jvmm.server.entity.conf.AuthOptionConf;
import org.beifengtz.jvmm.server.entity.conf.HttpServerConf;
import org.beifengtz.jvmm.server.ServerContext;
import org.slf4j.Logger;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Objects;

/**
 * 

* Description: TODO *

*

* Created in 18:37 2022/9/7 * * @author beifengtz */ public class HttpServerHandler extends HttpChannelHandler { @Override public Logger logger() { return LoggerFactory.logger(HttpServerHandler.class); } @Override protected boolean handleBefore(ChannelHandlerContext ctx, String uri, FullHttpRequest msg) { HttpServerConf conf = ServerContext.getConfiguration().getServer().getHttp(); AuthOptionConf auth = conf.getAuth(); if (auth.isEnable()) { String authStr = msg.headers().get("Authorization"); if (StringUtil.isEmpty(authStr) || !authStr.startsWith("Basic")) { response401(ctx); return false; } try { String[] up = new String(Base64.getDecoder().decode(authStr.split("\\s")[1]), StandardCharsets.UTF_8).split(":"); if (!Objects.equals(auth.getUsername(), up[0]) || !Objects.equals(auth.getPassword(), up[1])) { response401(ctx); return false; } } catch (Exception e) { response401(ctx); return false; } } return true; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy