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 {
public BasicAuthOutInterceptor() {
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage(Message message) throws Fault {
String token = "basic auth token";
@SuppressWarnings("unchecked")
Map> headers = (Map>) message
.get(Message.PROTOCOL_HEADERS);
if (headers == null) {
headers = new TreeMap>(
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.