CXF With UsernameToken (Interceptor)

Create a Student Object

package com.student;

public class Student {
 
private String name;
 
public String getName() {
   
return name;
 
}
 
public void setName(String name) {
   
this.name = name;
 
}
}

Create a Service Interface

This service interface will defines which methods of web service, to be invoked by the client

package com.student;

import javax.jws.WebService;

@WebService
public interface ChangeStudentDetails {
 
Student changeName(Student student);
}

Implement the Service Interface

Here we implement the service interface created on the previous step

package com.student;

import javax.jws.WebService;

@WebService(endpointInterface = "com.student.ChangeStudentDetails")
public class ChangeStudentDetailsImpl implements ChangeStudentDetails {
   
public Student changeName(Student student) {
     
student.setName("Hello "+student.getName());
     
return student;
   
}
}

Create ServerPasswordCallback

package service;

import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;

public class ServerPasswordCallback implements CallbackHandler {

   
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
       
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

       
if ("joe".equals(pc.getIdentifier())) {
           
System.out.println("pc.getPassword() " + pc.getPassword());
            pc.setPassword
("joespassword");
       
}
       
    }
}

Create a cxf.xml

Here we are adding

<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordText" />
<entry key="passwordCallbackRef">
	<ref bean="myPasswordCallback" />
</entry>

created myPasswordCallback bean in order to check the username token credentials





Previous 1 2 3 4 Next








4 Responses to "CXF With UsernameToken (Interceptor)"
  1. Kumar 2012-08-17 07:57:29.0
  1. admin 2012-08-18 07:57:29.0
  1. Sunil Gulabani 2012-08-19 07:57:29.0
  1. admin 2012-08-20 07:57:29.0

Your email address will not be published. Required fields are marked *