I have been working on developing CXF web services that sit behind a security proxy which asks for HTTP basic authentication prior service invocation. These services communi
One approach would be creating a CXF interceptor.
public class BasicAuthOutInterceptor extends AbstractPhaseInterceptor<Message> {
public BasicAuthOutInterceptor() {
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage(Message message) throws Fault {
String token = "basic auth token";
@SuppressWarnings("unchecked")
Map<String, List<String>> headers = (Map<String, List<String>>) message
.get(Message.PROTOCOL_HEADERS);
if (headers == null) {
headers = new TreeMap<String, List<String>>(
String.CASE_INSENSITIVE_ORDER);
message.put(Message.PROTOCOL_HEADERS, headers);
}
headers.put("Authentication", Arrays.asList("Basic "+ token));
}
}
and registering it as an out and outFault interceptor.
<bean id="basicAuthOutInterceptor class="BasicAuthOutInterceptor" />
<cxf:bus>
<cxf:outInterceptors>
<ref bean="basicAuthOutInterceptor"/>
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
<ref bean="basicAuthOutInterceptor"/>
</cxf:outFaultInterceptors>
</cxf:bus>