Merge branch 'stable' into stable-cxf

This commit is contained in:
Brian Long 2025-02-28 10:25:03 -05:00
commit 24fbe5f5ed

View File

@ -0,0 +1,58 @@
/*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.inteligr8.rs;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map.Entry;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import jakarta.ws.rs.client.ClientRequestContext;
/**
* This class implements a header-based authorization filter.
*
* @author brian@inteligr8.com
*/
public class HeaderAuthorizationFilter implements AuthorizationFilter {
private final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
/**
* @param headers An array of header name/value pairs.
*/
public HeaderAuthorizationFilter(String headerName, String headerValue) {
this.headers.add(headerName, headerValue);
}
public HeaderAuthorizationFilter add(String headerName, String headerValue) {
this.headers.add(headerName, headerValue);
return this;
}
/**
* This method applies the 'Authorization' header to the {@link ClientRequestContext}.
*
* @param requestContext A request context.
*/
@Override
public void filter(ClientRequestContext requestContext) throws UnsupportedEncodingException {
for (Entry<String, List<String>> header : this.headers.entrySet())
requestContext.getHeaders().addAll(header.getKey(), header.getValue());
}
}