update to xbib net 3.0.5 and use domain enums for parameter
This commit is contained in:
parent
d1910ce5cd
commit
3b31de0fd5
7 changed files with 20 additions and 12 deletions
|
@ -213,7 +213,7 @@ public class BaseHttpServerContext implements HttpServerContext {
|
||||||
.charset(charset, CodingErrorAction.REPLACE)
|
.charset(charset, CodingErrorAction.REPLACE)
|
||||||
.path(httpRequestBuilder.getRequestURI())
|
.path(httpRequestBuilder.getRequestURI())
|
||||||
.build();
|
.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
|
// https://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
|
||||||
if (HttpMethod.POST.equals(httpRequestBuilder.getMethod()) &&
|
if (HttpMethod.POST.equals(httpRequestBuilder.getMethod()) &&
|
||||||
(mimeType != null && mimeType.contains(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED))) {
|
(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");
|
CookieBox cookieBox = attributes.get(CookieBox.class, "incomingcookies");
|
||||||
ParameterBuilder cookieParameterBuilder = Parameter.builder().domain("COOKIE");
|
ParameterBuilder cookieParameterBuilder = Parameter.builder().domain(Parameter.Domain.COOKIE);
|
||||||
if (cookieBox != null) {
|
if (cookieBox != null) {
|
||||||
cookieBox.forEach(c -> cookieParameterBuilder.add(c.name(), c.value()));
|
cookieBox.forEach(c -> cookieParameterBuilder.add(c.name(), c.value()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class BaseHttpService implements HttpService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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 + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,18 +49,18 @@ public class FormAuthenticationHandler extends LoginAuthenticationHandler implem
|
||||||
userProfile = new BaseUserProfile();
|
userProfile = new BaseUserProfile();
|
||||||
context.attributes().put("userprofile", userProfile);
|
context.attributes().put("userprofile", userProfile);
|
||||||
Parameter parameter = context.httpRequest().getParameter();
|
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");
|
logger.log(Level.WARNING, "usernameParameter not set, unable to authenticate");
|
||||||
prepareFormAuthentication(context);
|
prepareFormAuthentication(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!parameter.containsKey("FORM", passwordParameter)) {
|
if (!parameter.containsKey(passwordParameter, Parameter.Domain.FORM)) {
|
||||||
logger.log(Level.WARNING, "passwordParameter not set, unable to authenticate");
|
logger.log(Level.WARNING, "passwordParameter not set, unable to authenticate");
|
||||||
prepareFormAuthentication(context);
|
prepareFormAuthentication(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String username = parameter.getAsString("FORM", usernameParameter);
|
String username = parameter.getAsString(usernameParameter, Parameter.Domain.FORM);
|
||||||
String password = parameter.getAsString("FORM", passwordParameter);
|
String password = parameter.getAsString(passwordParameter, Parameter.Domain.FORM);
|
||||||
logger.log(Level.FINE, "username and password found, ready for authentication");
|
logger.log(Level.FINE, "username and password found, ready for authentication");
|
||||||
try {
|
try {
|
||||||
authenticate(userProfile, username, password, context.httpRequest());
|
authenticate(userProfile, username, password, context.httpRequest());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.xbib.net.http.server.auth;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import org.xbib.net.Authenticator;
|
import org.xbib.net.Authenticator;
|
||||||
import org.xbib.net.GroupsProvider;
|
import org.xbib.net.GroupsProvider;
|
||||||
|
import org.xbib.net.Parameter;
|
||||||
import org.xbib.net.Request;
|
import org.xbib.net.Request;
|
||||||
import org.xbib.net.SecurityRealm;
|
import org.xbib.net.SecurityRealm;
|
||||||
import org.xbib.net.UserDetails;
|
import org.xbib.net.UserDetails;
|
||||||
|
@ -42,8 +43,8 @@ public class LoginAuthenticationHandler implements HttpHandler {
|
||||||
userProfile = new BaseUserProfile();
|
userProfile = new BaseUserProfile();
|
||||||
try {
|
try {
|
||||||
authenticate(userProfile,
|
authenticate(userProfile,
|
||||||
(String) context.httpRequest().getParameter().get("DEFAULT", userParameterName),
|
(String) context.httpRequest().getParameter().get(userParameterName, Parameter.Domain.DEFAULT, Parameter.Domain.FORM),
|
||||||
(String) context.httpRequest().getParameter().get("DEFAULT", passwordParameterName),
|
(String) context.httpRequest().getParameter().get(passwordParameterName, Parameter.Domain.DEFAULT, Parameter.Domain.FORM),
|
||||||
context.httpRequest());
|
context.httpRequest());
|
||||||
context.attributes().put("userprofile", userProfile);
|
context.attributes().put("userprofile", userProfile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -15,6 +15,8 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.xbib.net.Parameter.Domain.PATH;
|
||||||
|
|
||||||
public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {
|
public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(BaseHttpRouteResolver.class.getName());
|
private static final Logger logger = Logger.getLogger(BaseHttpRouteResolver.class.getName());
|
||||||
|
@ -33,7 +35,7 @@ public class BaseHttpRouteResolver<T> implements HttpRouteResolver<T> {
|
||||||
@Override
|
@Override
|
||||||
public void resolve(HttpRoute httpRoute, ResultListener<T> listener) {
|
public void resolve(HttpRoute httpRoute, ResultListener<T> listener) {
|
||||||
for (Map.Entry<HttpRoute, T> entry : builder.routes) {
|
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);
|
boolean match = entry.getKey().matches(parameterBuilder, httpRoute);
|
||||||
if (match && listener != null) {
|
if (match && listener != null) {
|
||||||
String path = httpRoute.getEffectivePath();
|
String path = httpRoute.getEffectivePath();
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.xbib.net.http.server.handler.UnauthorizedHandler;
|
import org.xbib.net.http.server.handler.UnauthorizedHandler;
|
||||||
import org.xbib.net.http.server.handler.VersionNotSupportedHandler;
|
import org.xbib.net.http.server.handler.VersionNotSupportedHandler;
|
||||||
|
@ -39,7 +40,11 @@ public class BaseHttpRouterBuilder implements HttpRouterBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseHttpRouterBuilder setPrefix(String prefix) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ dependencyResolutionManagement {
|
||||||
version('netty-tcnative', '2.0.59.Final')
|
version('netty-tcnative', '2.0.59.Final')
|
||||||
version('datastructures', '2.0.0')
|
version('datastructures', '2.0.0')
|
||||||
version('config', '5.0.2')
|
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-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
|
||||||
library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').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')
|
library('junit-jupiter-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
|
||||||
|
|
Loading…
Reference in a new issue