|
|
|
@ -5,6 +5,7 @@ import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
import io.netty.handler.codec.http.HttpHeaderNames; |
|
|
|
|
import org.fengfei.lanproxy.common.JsonUtil; |
|
|
|
|
import org.fengfei.lanproxy.server.ProxyChannelManager; |
|
|
|
|
import org.fengfei.lanproxy.server.config.ProxyConfig; |
|
|
|
@ -50,7 +51,7 @@ public class RouteConfig { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void preRequest(FullHttpRequest request) { |
|
|
|
|
String cookieHeader = request.headers().get(HttpHeaders.Names.COOKIE); |
|
|
|
|
String cookieHeader = request.headers().get(HttpHeaderNames.COOKIE); |
|
|
|
|
boolean authenticated = false; |
|
|
|
|
if (cookieHeader != null) { |
|
|
|
|
String[] cookies = cookieHeader.split(";"); |
|
|
|
@ -64,7 +65,7 @@ public class RouteConfig { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String auth = request.headers().get(HttpHeaders.Names.AUTHORIZATION); |
|
|
|
|
String auth = request.headers().get(HttpHeaderNames.AUTHORIZATION); |
|
|
|
|
if (!authenticated && auth != null) { |
|
|
|
|
String[] authArr = auth.split(" "); |
|
|
|
|
if (authArr.length == 2 && authArr[0].equals(ProxyConfig.getInstance().getConfigAdminUsername()) && authArr[1].equals(ProxyConfig.getInstance().getConfigAdminPassword())) { |
|
|
|
@ -72,11 +73,11 @@ public class RouteConfig { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!LOGIN_URL.equals(request.getUri()) && !authenticated) { |
|
|
|
|
if (!LOGIN_URL.equals(request.uri()) && !authenticated) { |
|
|
|
|
throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
logger.info("handle request for api {}", request.getUri()); |
|
|
|
|
logger.info("handle request for api {}", request.uri()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|