How to Cancel a Token in a STS

import java.net.URL;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.Service.Mode;
import javax.xml.ws.soap.AddressingFeature;

import org.oasis_open.docs.ws_sx.ws_trust._200512.RequestSecurityTokenResponseCollectionType;
import org.oasis_open.docs.ws_sx.ws_trust._200512.RequestSecurityTokenType;

public final class WsTrustSample {

  public static void main(final String[] args) throws Exception {
    final Service service = Service.create(new URL("http://localhost/wstrustsample/SampleSecurityTokenService?WSDL"), new QName("http://fernandoribeiro.eti.br/sample/wstrust", "SampleSecurityTokenService"));

    final Dispatch dispatch = service.createDispatch(new QName("http://fernandoribeiro.eti.br/sample/wstrust", "SamplePort"), JAXBContext.newInstance("org.oasis_open.docs.ws_sx.ws_trust._200512"), Mode.PAYLOAD, new AddressingFeature());

    final BindingProvider provider = (BindingProvider) dispatch;

    final Map<String, Object> requestContext = provider.getRequestContext();

    requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Cancel");

    final RequestSecurityTokenType request = new RequestSecurityTokenType();

    dispatch.invoke(new JAXBElement<RequestSecurityTokenType>(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "RequestSecurityToken"), RequestSecurityTokenType.class, request)));
  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s