DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Composing Custom Annotations in Spring
  • 10 Ways To Keep Your Java Application Safe and Secure
  • Using Swagger for Creating a PingFederate Admin API Java Wrapper
  • Build a Java Backend That Connects With Salesforce

Trending

  • Connect to RabbitMQ Using Scala, Play and Akka
  • Going Stateless: Scaling MCP Servers to Cloud-Native Java and HTTP
  • The Twelve-Factor Agents: Building Production-Ready LLM Applications
  • Engineering Complexity: Implied vs. Induced Complexity
  1. DZone
  2. Coding
  3. Java
  4. CXF SOAP Header Basic Authentication Interceptors Java Without Spring

CXF SOAP Header Basic Authentication Interceptors Java Without Spring

Here's a great guide to authentication interceptors in Java without using Spring!

By 
Bosco Ferrao user avatar
Bosco Ferrao
·
Feb. 16, 16 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
17.4K Views

Join the DZone community and get the full member experience.

Join For Free

If you have used the tool:

org.apache.cxf.tools.wsdlto.WSDLToJava

to create your SOAP CXF stubs.

Create a Basic Authentication Interceptor as follows:

package com.bos.services.cxf.interceptors;

import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.ws.security.SecurityConstants;

public abstract class CxfBasicAuthInterceptor extends AbstractOutDatabindingInterceptor {

public CxfBasicAuthInterceptor() {
super(Phase.WRITE);
}

@Override
public void handleMessage(Message outMessage) throws Fault {
outMessage.setContextualProperty(SecurityConstants.USERNAME, getUsername());
outMessage.setContextualProperty(SecurityConstants.PASSWORD, getPassword());
}

public abstract String getUsername();

public abstract String getPassword();
}

To use the Basic Authetication Interceptor:

QName serviceName = new QName("http://bos.asoap.service.com/v1.0/ServiceApi", "BosWS");
URL wsdlURL = BosWS.WSDL_LOCATION;

BosWS ss = new BosWS(wsdlURL, serviceName);
IBosWS service = ss.getBasicHttpBindingIBosWS();
Client client = ClientProxy.getClient(service);

client.getOutInterceptors().add(new CxfBasicAuthInterceptor() {
@Override
public String getUsername() {
return configService.getWSUserName();
}

@Override
public String getPassword() {
return configService.getWSPassword();
}
});
SOAP Web Protocols authentication Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Composing Custom Annotations in Spring
  • 10 Ways To Keep Your Java Application Safe and Secure
  • Using Swagger for Creating a PingFederate Admin API Java Wrapper
  • Build a Java Backend That Connects With Salesforce

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook