You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Jonathan J. Vargas R." <jo...@gmail.com> on 2005/08/18 00:48:38 UTC

Modify SOAP Headers for Authentication

Greets,

I want to get and set the SOAP Headers for the messages transmited
to and from my webservice.

I saw I was able to retrieve SOAP request and response messages from
MessageContext, though, after I save headers they are not really seen 
in the response message so i wondered if this was the right procedure
or it should be done in another way?

I want to work authentication through SOAP Headers, and this is the trivial
web service implementation class that I am using:

--

public class AuthImpl {

    public boolean authenticate (String username, String password)
throws AuthServiceException {
	
	boolean isValidUser = false;
	try {
	    MessageContext mc = MessageContext.getCurrentContext ();
	    SOAPMessage req_message = mc.getRequestMessage ();
	    SOAPHeader sh = req_message.getSOAPHeader ();
	    
	    
	    // here how can i retrieve the SOAP Header element named "AuthRequest" ?
	    // ...
	    // and then i compare its elements against my user's data base
	    // ...
	    // and then set isValidUser to true if found..
	    
	} catch (SOAPException se) {
	    // ...
	}
	
	if (!isValidUser) {
	    throw new AuthServiceException (
		    "Authentication failed for supplied credentials");
	}
	
	try {
	    MessageContext mc = MessageContext.getCurrentContext ();
	    SOAPMessage resp_message = mc.getResponseMessage ();
	    SOAPHeader sh = resp_message.getSOAPHeader ();
	    
	    // and here examine SOAP header element named "AuthResponse" and
	    // set username, userid and those values retrieved from database
	    // to proper Soap header elements to be returned to caller.. how ?
	    
	} catch (SOAPException se) {
	    // ...
	}
	
	// set this object values with user info extracted from data base..
	// and then return it..

	return isValidUser;
    }
    
---


-- 
Jonathan J. Vargas Rodriguez
jonathan.j.vargas@gmail.com
"Conservar el silencio interior cuando vuelo en la tormenta me es
mejor, porque asi ya no soy otra gota de la tempestad"