update to xbib net 3.0.5 and use domain enums for parameter

This commit is contained in:
Jörg Prante 2023-03-24 14:14:57 +01:00
parent d1910ce5cd
commit 3b31de0fd5
7 changed files with 20 additions and 12 deletions

View file

@ -213,7 +213,7 @@ public class BaseHttpServerContext implements HttpServerContext {
.charset(charset, CodingErrorAction.REPLACE)
.path(httpRequestBuilder.getRequestURI())
.build();
ParameterBuilder formParameterBuilder = Parameter.builder().domain("FORM");
ParameterBuilder formParameterBuilder = Parameter.builder().domain(Parameter.Domain.FORM);
// https://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
if (HttpMethod.POST.equals(httpRequestBuilder.getMethod()) &&
(mimeType != null && mimeType.contains(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED))) {
@ -224,7 +224,7 @@ public class BaseHttpServerContext implements HttpServerContext {
}
}
CookieBox cookieBox = attributes.get(CookieBox.class, "incomingcookies");
ParameterBuilder cookieParameterBuilder = Parameter.builder().domain("COOKIE");
ParameterBuilder cookieParameterBuilder = Parameter.builder().domain(Parameter.Domain.COOKIE);
if (cookieBox != null) {
cookieBox.forEach(c -> cookieParameterBuilder.add(c.name(), c.value()));
}

View file

@ -88,7 +88,7 @@ public class BaseHttpService implements HttpService {
@Override
public String toString() {
return "BaseHttpService[methods=" + builder.methods + ",prefix" + builder.prefix + ",path=" + builder.pathSpec + ",handler=" + builder.handlers + "]";
return "BaseHttpService[methods=" + builder.methods + ",prefix=" + builder.prefix + ",path=" + builder.pathSpec + ",handler=" + builder.handlers + "]";
}
}

View file

@ -49,18 +49,18 @@ public class FormAuthenticationHandler extends LoginAuthenticationHandler implem
userProfile = new BaseUserProfile();
context.attributes().put("userprofile", userProfile);
Parameter parameter = context.httpRequest().getParameter();
if (!parameter.containsKey("FORM", usernameParameter)) {
if (!parameter.containsKey(usernameParameter, Parameter.Domain.FORM)) {
logger.log(Level.WARNING, "usernameParameter not set, unable to authenticate");
prepareFormAuthentication(context);
return;
}
if (!parameter.containsKey("FORM", passwordParameter)) {
if (!parameter.containsKey(passwordParameter, Parameter.Domain.FORM)) {
logger.log(Level.WARNING, "passwordParameter not set, unable to authenticate");
prepareFormAuthentication(context);
return;
}
String username = parameter.getAsString("FORM", usernameParameter);
String password = parameter.getAsString("FORM", passwordParameter);
String username = parameter.getAsString(usernameParameter, Parameter.Domain.FORM);
String password = parameter.getAsString(passwordParameter, Parameter.Domain.FORM);
logger.log(Level.FINE, "username and password found, ready for authentication");
try {
authenticate(userProfile, username, password, context.httpRequest());

View file

@ -3,6 +3,7 @@ package org.xbib.net.http.server.auth;
import java.util.Collection;
import org.xbib.net.Authenticator;
import org.xbib.net.GroupsProvider;
import org.xbib.net.Parameter;
import org.xbib.net.Request;
import org.xbib.net.SecurityRealm;
import org.xbib.net.UserDetails;
@ -42,8 +43,8 @@ public class LoginAuthenticationHandler implements HttpHandler {
userProfile = new BaseUserProfile();
try {
authenticate(userProfile,
(String) context.httpRequest().getParameter().get("DEFAULT", userParameterName),
(String) context.httpRequest().getParameter().get("DEFAULT", passwordParameterName),
(String) context.httpRequest().getParameter().get(userParameterName, Parameter.Domain.DEFAULT, Parameter.Domain.FORM),
(String) context.httpRequest().getParameter().get(passwordParameterName, Parameter.Domain.DEFAULT, Parameter.Domain.FORM),
context.httpRequest());
context.attributes().put("userprofile", userProfile);
} catch (Exception e) {

View file

@ -15,6 +15,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import static org.xbib.net.Parameter.Domain.PATH;
public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {
private static final Logger logger = Logger.getLogger(BaseHttpRouteResolver.class.getName());
@ -33,7 +35,7 @@ public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {
@Override
public void resolve(HttpRoute httpRoute, ResultListener<T> listener) {
for (Map.Entry<HttpRoute, T> entry : builder.routes) {
ParameterBuilder parameterBuilder = Parameter.builder().domain("PATH");
ParameterBuilder parameterBuilder = Parameter.builder().domain(PATH);
boolean match = entry.getKey().matches(parameterBuilder, httpRoute);
if (match && listener != null) {
String path = httpRoute.getEffectivePath();

View file

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.xbib.net.http.server.handler.UnauthorizedHandler;
import org.xbib.net.http.server.handler.VersionNotSupportedHandler;
@ -39,7 +40,11 @@ public class BaseHttpRouterBuilder implements HttpRouterBuilder {
@Override
public BaseHttpRouterBuilder setPrefix(String prefix) {
this.prefix = prefix;
Objects.requireNonNull(prefix);
// Add ending slash if missing.
// We require a prefix with ending slash. Otherwise, obscure things can happen in path parameter handling,
// if a path parameter has a common prefix with this prefix.
this.prefix = prefix.isEmpty() || prefix.endsWith("/") ? prefix : prefix + "/";
return this;
}

View file

@ -8,7 +8,7 @@ dependencyResolutionManagement {
version('netty-tcnative', '2.0.59.Final')
version('datastructures', '2.0.0')
version('config', '5.0.2')
version('net', '3.0.4')
version('net', '3.0.5')
library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit')
library('junit-jupiter-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')