@@ -0,0 +1,3575 @@
+/*%0A * JBoss, Home of Professional Open Source.%0A * Copyright 2020 Red Hat, Inc., and individual contributors%0A * as indicated by the @author tags.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.wildfly.security.http.util;%0A%0Aimport static org.wildfly.common.Assert.checkNotNullParam;%0A%0Aimport java.io.IOException;%0Aimport java.net.InetSocketAddress;%0Aimport java.util.Map;%0A%0Aimport javax.security.auth.callback.Callback;%0Aimport javax.security.auth.callback.CallbackHandler;%0Aimport javax.security.auth.callback.UnsupportedCallbackException;%0A%0Aimport org.wildfly.security.auth.callback.SocketAddressCallback;%0Aimport org.wildfly.security.http.HttpAuthenticationException;%0Aimport org.wildfly.security.http.HttpServerAuthenticationMechanism;%0Aimport org.wildfly.security.http.HttpServerAuthenticationMechanismFactory;%0Aimport org.wildfly.security.http.HttpServerRequest;%0A%0A/**%0A * A wrapper %7B@link HttpServerAuthenticationMechanismFactory%7D that sets the peer address using the current%0A * authentication request.%0A *%0A * @author %3Ca href=%22mailto:fjuma@redhat.com%22%3EFarah Juma%3C/a%3E%0A */%0Apublic final class SocketAddressCallbackServerMechanismFactory implements HttpServerAuthenticationMechanismFactory %7B%0A%0A    private final HttpServerAuthenticationMechanismFactory delegate;%0A%0A    /**%0A     * Construct a wrapping mechanism factory instance.%0A     *%0A     * @param delegate the wrapped mechanism factory%0A     */%0A    public SocketAddressCallbackServerMechanismFactory(final HttpServerAuthenticationMechanismFactory delegate) %7B%0A        this.delegate = checkNotNullParam(%22delegate%22, delegate);%0A    %7D%0A%0A    @Override%0A    public String%5B%5D getMechanismNames(Map%3CString, ?%3E properties) %7B%0A        return delegate.getMechanismNames(properties);%0A    %7D%0A%0A    @Override%0A    public HttpServerAuthenticationMechanism createAuthenticationMechanism(String mechanismName, Map%3CString, ?%3E properties, CallbackHandler callbackHandler) throws HttpAuthenticationException %7B%0A        final HttpServerAuthenticationMechanism mechanism = delegate.createAuthenticationMechanism(mechanismName, properties, callbackHandler);%0A        return mechanism != null ? new HttpServerAuthenticationMechanism() %7B%0A%0A            @Override%0A            public String getMechanismName() %7B%0A                return mechanism.getMechanismName();%0A            %7D%0A%0A            @Override%0A            public void evaluateRequest(HttpServerRequest request) throws HttpAuthenticationException %7B%0A                final InetSocketAddress peerAddress = request.getSourceAddress();%0A                if (peerAddress != null) %7B%0A                    final SocketAddressCallback peerCallback = new SocketAddressCallback(peerAddress, SocketAddressCallback.Kind.PEER);%0A                    try %7B%0A                        callbackHandler.handle(new Callback%5B%5D %7B peerCallback %7D);%0A                    %7D catch (IOException %7C UnsupportedCallbackException e) %7B%0A                        throw new HttpAuthenticationException(e);%0A                    %7D%0A                %7D%0A%0A                mechanism.evaluateRequest(request);%0A            %7D%0A        %7D : null;%0A    %7D%0A%7D%0A%0A

Add a wrapper HttpServerAuthenticationMechanismFactory that sets the peer address using the current authentication request