FileDocCategorySizeDatePackage
SecurityServerPipe.javaAPI DocExample35011Mon Jun 04 22:45:56 BST 2007com.sun.xml.wss.jaxws.impl

SecurityServerPipe

public class SecurityServerPipe extends SecurityPipeBase
author
K.Venugopal@sun.com
author
Vbkumar.Jayanti@Sun.COM

Fields Summary
private com.sun.xml.ws.runtime.util.SessionManager
sessionManager
private Set
trustConfig
private CallbackHandler
handler
Constructors Summary
public SecurityServerPipe(com.sun.xml.ws.assembler.ServerPipeConfiguration config, com.sun.xml.ws.api.pipe.Pipe nextPipe)

    
    // Creates a new instance of SecurityServerPipe
        
        super(config,nextPipe);
        
        try {
            Iterator it = inMessagePolicyMap.values().iterator();
            SecurityPolicyHolder holder = (SecurityPolicyHolder)it.next();
            Set configAssertions = holder.getConfigAssertions(SUN_WSS_SECURITY_SERVER_POLICY_NS);
            trustConfig = holder.getConfigAssertions(Constants.SUN_TRUST_SERVER_SECURITY_POLICY_NS);
            Properties props = new Properties();
            handler = configureServerHandler(configAssertions, props);
            secEnv = new DefaultSecurityEnvironmentImpl(handler, props);
        } catch (Exception e) {            
            log.log(Level.SEVERE, 
                    LogStringsMessages.WSSPIPE_0028_ERROR_CREATING_NEW_INSTANCE_SEC_SERVER_PIPE(), e);            
            throw new RuntimeException(
                    LogStringsMessages.WSSPIPE_0028_ERROR_CREATING_NEW_INSTANCE_SEC_SERVER_PIPE(), e);            
        }
    
protected SecurityServerPipe(SecurityServerPipe that)

        super(that);
        sessionManager = that.sessionManager;
        trustConfig = that.trustConfig;
        handler = that.handler;
    
Methods Summary
private com.sun.xml.ws.api.message.PacketaddAddressingHeaders(com.sun.xml.ws.api.message.Packet packet, com.sun.xml.ws.api.message.Message retMsg, java.lang.String action)

        Packet retPacket = packet.createServerResponse(retMsg, addVer, soapVersion, action);
        
        retPacket.proxy = packet.proxy;
        retPacket.invocationProperties.putAll(packet.invocationProperties);
        
        return retPacket;
    
protected voidaddIncomingFaultPolicy(com.sun.xml.ws.policy.Policy effectivePolicy, com.sun.xml.ws.security.impl.policyconv.SecurityPolicyHolder sph, com.sun.xml.ws.api.model.wsdl.WSDLFault fault)

        SecurityPolicyHolder faultPH = constructPolicyHolder(effectivePolicy,true,false);
        sph.addFaultPolicy(fault,faultPH);
    
protected com.sun.xml.ws.security.impl.policyconv.SecurityPolicyHolderaddIncomingMP(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation operation, com.sun.xml.ws.policy.Policy policy)


        SecurityPolicyHolder sph = constructPolicyHolder(policy,true,false);
        outMessagePolicyMap.put(operation,sph);
        return sph;
    
protected voidaddIncomingProtocolPolicy(com.sun.xml.ws.policy.Policy effectivePolicy, java.lang.String protocol)

        outProtocolPM.put(protocol,constructPolicyHolder(effectivePolicy,true,false,true));
    
protected voidaddOutgoingFaultPolicy(com.sun.xml.ws.policy.Policy effectivePolicy, com.sun.xml.ws.security.impl.policyconv.SecurityPolicyHolder sph, com.sun.xml.ws.api.model.wsdl.WSDLFault fault)

        SecurityPolicyHolder faultPH = constructPolicyHolder(effectivePolicy,true,true);
        sph.addFaultPolicy(fault,faultPH);
    
protected com.sun.xml.ws.security.impl.policyconv.SecurityPolicyHolderaddOutgoingMP(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation operation, com.sun.xml.ws.policy.Policy policy)
private Packet addAddressingHeaders(Packet packet, String relatesTo, String action){ AddressingBuilder builder = AddressingBuilder.newInstance(); AddressingProperties ap = builder.newAddressingProperties(); try{ // Action ap.setAction(builder.newURI(new URI(action))); // RelatesTo Relationship[] rs = new Relationship[]{builder.newRelationship(new URI(relatesTo))}; ap.setRelatesTo(rs); // To ap.setTo(builder.newURI(new URI(builder.newAddressingConstants().getAnonymousURI()))); } catch (URISyntaxException e) { throw new RuntimeException("Exception when adding Addressing Headers"); } WsaRuntimeFactory fac = WsaRuntimeFactory.newInstance(ap.getNamespaceURI(), pipeConfig.getWSDLModel(), pipeConfig.getBinding()); fac.writeHeaders(packet, ap); packet.invocationProperties .put(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND, ap); return packet; }


        SecurityPolicyHolder sph = constructPolicyHolder(policy,true,true);
        inMessagePolicyMap.put(operation,sph);
        return sph;
    
protected voidaddOutgoingProtocolPolicy(com.sun.xml.ws.policy.Policy effectivePolicy, java.lang.String protocol)

        inProtocolPM.put(protocol,constructPolicyHolder(effectivePolicy,true,true,true));
    
private javax.security.auth.callback.CallbackHandlerconfigureServerHandler(java.util.Set configAssertions, java.util.Properties props)

        //Properties props = new Properties();
        String ret = populateConfigProperties(configAssertions, props);
        try {
            if (ret != null) {
                Class handler = loadClass(ret);
                Object obj = handler.newInstance();
                if (!(obj instanceof CallbackHandler)) {
                    log.log(Level.SEVERE, 
                            LogStringsMessages.WSSPIPE_0033_INVALID_CALLBACK_HANDLER_CLASS(ret));
                    throw new RuntimeException(
                            LogStringsMessages.WSSPIPE_0033_INVALID_CALLBACK_HANDLER_CLASS(ret));                                        
                }
                return (CallbackHandler)obj;
            }
            // ServletContext context =
            //         ((ServerPipeConfiguration)pipeConfig).getEndpoint().getContainer().getSPI(ServletContext.class);
            RealmAuthenticationAdapter adapter = getRealmAuthenticationAdapter(((ServerPipeConfiguration)pipeConfig).getEndpoint());
            return new DefaultCallbackHandler("server", props, adapter);
            //return new DefaultCallbackHandler("server", props);
        } catch (Exception e) {
            log.log(Level.SEVERE, 
                    LogStringsMessages.WSSPIPE_0032_ERROR_CONFIGURE_SERVER_HANDLER(), e);                 
            throw new RuntimeException(LogStringsMessages.WSSPIPE_0032_ERROR_CONFIGURE_SERVER_HANDLER(), e);
        }
    
public com.sun.xml.ws.api.pipe.Pipecopy(com.sun.xml.ws.api.pipe.PipeCloner cloner)

        Pipe clonedNextPipe = null;
        if (nextPipe != null) {
            clonedNextPipe = cloner.copy(nextPipe);
        }
        Pipe copied = new SecurityServerPipe(this);
        ((SecurityServerPipe)copied).setNextPipe(clonedNextPipe);
        cloner.add(this, copied);
        return copied;
    
private static voidcopySubject(javax.security.auth.Subject from, javax.security.auth.Subject to)

        if (from == null || to == null) {
            return;
        }
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                to.getPrincipals().addAll(from.getPrincipals());
                to.getPublicCredentials().addAll(from.getPublicCredentials());
                to.getPrivateCredentials().addAll(from.getPrivateCredentials());
                return null; // nothing to return
            }
        });
    
protected java.lang.StringgetAction(com.sun.xml.ws.api.model.wsdl.WSDLOperation operation, boolean inComming)

        if(inComming){
            return operation.getInput().getAction();
        }else{
            return operation.getOutput().getAction();
        }
    
protected com.sun.xml.wss.impl.policy.mls.MessagePolicygetOutgoingFaultPolicy(com.sun.xml.ws.api.message.Packet packet)

        
        if(cachedOperation != null){
            WSDLOperation operation = cachedOperation.getOperation();
            try{
                SOAPBody body = packet.getMessage().readAsSOAPMessage().getSOAPBody();
                NodeList nodes = body.getElementsByTagName("detail");
                if(nodes.getLength() == 0){
                    nodes = body.getElementsByTagNameNS(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE,"Detail");
                }
                if(nodes.getLength() >0){
                    Node node = nodes.item(0);
                    Node faultNode = node.getFirstChild();
                    if(faultNode == null){
                        return null;
                    }
                    String uri = faultNode.getNamespaceURI();
                    QName faultDetail = null;
                    if(uri != null && uri.length() >0){
                        faultDetail = new QName(faultNode.getNamespaceURI(),faultNode.getLocalName());
                    }else{
                        faultDetail = new QName(faultNode.getNodeName());
                    }
                    WSDLFault fault = operation.getFault(faultDetail);
                    SecurityPolicyHolder sph = outMessagePolicyMap.get(cachedOperation);
                    SecurityPolicyHolder faultPolicyHolder = sph.getFaultPolicy(fault);
                    MessagePolicy faultPolicy = (faultPolicyHolder == null) ? new MessagePolicy() : faultPolicyHolder.getMessagePolicy();
                    return faultPolicy;
                    
                }
            }catch(SOAPException sx){
                //sx.printStackTrace();
                //log error
            }
        }
        return null;
        
    
protected com.sun.xml.wss.impl.policy.mls.MessagePolicygetOutgoingXWSSecurityPolicy(com.sun.xml.ws.api.message.Packet packet, boolean isSCMessage)

        if (isSCMessage) {
            Token scToken = (Token)packet.invocationProperties.get(SC_ASSERTION);
            return getOutgoingXWSBootstrapPolicy(scToken);
        }
       
        MessagePolicy mp = null;
     
        if (outMessagePolicyMap == null) {
            //empty message policy
            return new MessagePolicy();
        }
        
        if(isTrustMessage(packet)){
            cachedOperation = getWSDLOpFromAction(packet,false);
        }
        
        SecurityPolicyHolder sph = (SecurityPolicyHolder) outMessagePolicyMap.get(cachedOperation);
        if(sph == null){
            return new MessagePolicy();
        }
        mp = sph.getMessagePolicy();
        return mp;
    
private com.sun.xml.wss.RealmAuthenticationAdaptergetRealmAuthenticationAdapter(com.sun.xml.ws.api.server.WSEndpoint wSEndpoint)

        String className = "javax.servlet.ServletContext";
        Class ret = null;
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader != null) {
            try {
                ret = loader.loadClass(className);
            } catch (ClassNotFoundException e) {
                return null;
            }
        }
        if (ret == null) {
            // if context classloader didnt work, try this
            loader = this.getClass().getClassLoader();
            try {
                ret = loader.loadClass(className);
            } catch (ClassNotFoundException e) {
                return null;
            }
        }
        if (ret != null) {
            Object obj = wSEndpoint.getContainer().getSPI(ret);
            if (obj != null) {
                return RealmAuthenticationAdapter.newInstance(obj);
            }
        }
        return null;
    
protected com.sun.xml.wss.ProcessingContextinitializeOutgoingProcessingContext(com.sun.xml.ws.api.message.Packet packet, boolean isSCMessage, boolean isTrustMessage)

        ProcessingContext ctx = initializeOutgoingProcessingContext(packet, isSCMessage/*, thereWasAFault*/);
        return ctx;
    
protected com.sun.xml.wss.ProcessingContextinitializeOutgoingProcessingContext(com.sun.xml.ws.api.message.Packet packet, boolean isSCMessage)

        
        ProcessingContextImpl ctx = null;
        if(optimized){
            ctx = new JAXBFilterProcessingContext(packet.invocationProperties);
            ((JAXBFilterProcessingContext)ctx).setAddressingVersion(addVer);
            ((JAXBFilterProcessingContext)ctx).setSOAPVersion(soapVersion);
            ((JAXBFilterProcessingContext)ctx).setBSP(bsp10);
        }else{
            ctx = new ProcessingContextImpl( packet.invocationProperties);
        }
        
        try {
            MessagePolicy policy = null;
            if (packet.getMessage().isFault()) {
                policy =  getOutgoingFaultPolicy(packet);
                if(optimized){
                    ctx = new ProcessingContextImpl( packet.invocationProperties);
                }
            } else if (isRMMessage(packet)) {
                SecurityPolicyHolder holder = outProtocolPM.get("RM");
                policy = holder.getMessagePolicy();
            } else if(isSCCancel(packet)){
                SecurityPolicyHolder holder = outProtocolPM.get("SC");
                policy = holder.getMessagePolicy();
            }else {
                policy = getOutgoingXWSSecurityPolicy(packet, isSCMessage);
            }
            
            if (debug && policy != null) {
                policy.dumpMessages(true);
            }
            //this might mislead if there is a bug in code above
            //but we are doing this check for cases such as no-fault-security-policy
            if (policy != null) {
                ctx.setSecurityPolicy(policy);
            }
            // set the policy, issued-token-map, and extraneous properties
            ctx.setIssuedTokenContextMap(issuedTokenContextMap);
            ctx.setAlgorithmSuite(getAlgoSuite(getBindingAlgorithmSuite(packet)));
            ctx.setSecurityEnvironment(secEnv);
            ctx.isInboundMessage(false);
        } catch (XWSSecurityException e) {
            log.log(
                    Level.SEVERE, LogStringsMessages.WSSPIPE_0006_PROBLEM_INIT_OUT_PROC_CONTEXT(), e);
            throw new RuntimeException(
                    LogStringsMessages.WSSPIPE_0006_PROBLEM_INIT_OUT_PROC_CONTEXT(), e);
        }
        return ctx;
    
private com.sun.xml.ws.api.message.PacketinvokeSecureConversationContract(com.sun.xml.ws.api.message.Packet packet, com.sun.xml.wss.ProcessingContext ctx, boolean isSCTIssue, java.lang.String action)

        
        IssuedTokenContext ictx = new IssuedTokenContextImpl();
        
        Message msg = packet.getMessage();
        Message retMsg = null;
        String retAction = null;
        
        try {
            // Set the requestor authenticated Subject in the IssuedTokenContext
            Subject subject = SubjectAccessor.getRequesterSubject(ctx);
            
            ictx.setRequestorSubject(subject);
            
            WSSCElementFactory eleFac = WSSCElementFactory.newInstance();
            JAXBElement rstEle = msg.readPayloadAsJAXB(jaxbContext.createUnmarshaller());
            RequestSecurityToken rst = eleFac.createRSTFrom(rstEle);
            URI requestType = rst.getRequestType();
            RequestSecurityTokenResponse rstr = null;
            WSSCContract scContract = WSSCFactory.newWSSCContract(null);
            if (requestType.toString().equals(WSTrustConstants.ISSUE_REQUEST)) {
                List<PolicyAssertion> policies = getOutBoundSCP(packet.getMessage());
                rstr =  scContract.issue(rst, ictx, (SecureConversationToken)policies.get(0));
                retAction = WSSCConstants.REQUEST_SECURITY_CONTEXT_TOKEN_RESPONSE_ACTION;
                SecurityContextToken sct = (SecurityContextToken)ictx.getSecurityToken();
                String sctId = sct.getIdentifier().toString();
                
                Session session = sessionManager.getSession(sctId);
                if (session == null) {
                    log.log(Level.SEVERE, LogStringsMessages.WSSPIPE_0029_ERROR_SESSION_CREATION());                   
                    throw new WSSecureConversationException(
                            LogStringsMessages.WSSPIPE_0029_ERROR_SESSION_CREATION());
                }
                
                // Put it here for RM to pick up
                packet.invocationProperties.put(
                        Session.SESSION_ID_KEY, sctId);
                
                packet.invocationProperties.put(
                        Session.SESSION_KEY, session.getUserData());
           
                ((ProcessingContextImpl)ctx).getIssuedTokenContextMap().put(sctId, ictx);
                
            } else if (requestType.toString().equals(WSTrustConstants.CANCEL_REQUEST)) {
                retAction = WSSCConstants.CANCEL_SECURITY_CONTEXT_TOKEN_RESPONSE_ACTION;
                rstr =  scContract.cancel(rst, ictx, issuedTokenContextMap);
            } else {
                log.log(Level.SEVERE, 
                        LogStringsMessages.WSSPIPE_0030_UNSUPPORTED_OPERATION_EXCEPTION(requestType));                
                throw new UnsupportedOperationException(
                        LogStringsMessages.WSSPIPE_0030_UNSUPPORTED_OPERATION_EXCEPTION(requestType)); 
            }
            
            // construct the complete message here containing the RSTR and the
            // correct Action headers if any and return the message.
            retMsg = Messages.create(jaxbContext.createMarshaller(), eleFac.toJAXBElement(rstr), soapVersion);
        } catch (com.sun.xml.wss.XWSSecurityException ex) {
            log.log(Level.SEVERE, LogStringsMessages.WSSPIPE_0031_ERROR_INVOKE_SC_CONTRACT(), ex);  
            throw new RuntimeException(LogStringsMessages.WSSPIPE_0031_ERROR_INVOKE_SC_CONTRACT(), ex);
        } catch (javax.xml.bind.JAXBException ex) {
            log.log(Level.SEVERE, LogStringsMessages.WSSPIPE_0001_PROBLEM_MAR_UNMAR(), ex);
            throw new RuntimeException(LogStringsMessages.WSSPIPE_0001_PROBLEM_MAR_UNMAR(), ex);
        } catch (WSSecureConversationException ex){
            log.log(Level.SEVERE, LogStringsMessages.WSSPIPE_0031_ERROR_INVOKE_SC_CONTRACT(), ex);
            throw new RuntimeException(LogStringsMessages.WSSPIPE_0031_ERROR_INVOKE_SC_CONTRACT(), ex);
        }
        
      
        Packet retPacket = addAddressingHeaders(packet, retMsg, retAction);
        if (isSCTIssue){
            List<PolicyAssertion> policies = getOutBoundSCP(packet.getMessage());
            
            if(!policies.isEmpty()) {
                retPacket.invocationProperties.put(SC_ASSERTION, (PolicyAssertion)policies.get(0));
            }
        }
        
        return retPacket;
    
public voidpreDestroy()

        if (nextPipe != null) {
            nextPipe.preDestroy();
        }
        issuedTokenContextMap.clear();
    
public com.sun.xml.ws.api.message.Packetprocess(com.sun.xml.ws.api.message.Packet packet)

        
        if (!optimized) {
            cacheMessage(packet);
        }
        
        Message msg = packet.getMessage();
        
        boolean isSCIssueMessage = false;
        boolean isSCCancelMessage = false;
        boolean isTrustMessage = false;
        String msgId = null;
        String action = null;
        
        boolean thereWasAFault = false;
        
        //Do Security Processing for Incoming Message
        //---------------INBOUND SECURITY VERIFICATION----------
        ProcessingContext ctx = initializeInboundProcessingContext(packet/*, isSCIssueMessage, isTrustMessage*/);
        ctx.setExtraneousProperty(ctx.OPERATION_RESOLVER, new PolicyResolverImpl(inMessagePolicyMap,inProtocolPM,cachedOperation,pipeConfig,addVer,false));
        try{
            if(!optimized) {
                SOAPMessage soapMessage = msg.readAsSOAPMessage();
                soapMessage = verifyInboundMessage(soapMessage, ctx);
                msg = Messages.create(soapMessage);
            }else{
                msg = verifyInboundMessage(msg, ctx);
            }
        } catch (WssSoapFaultException ex) {
            thereWasAFault = true;            
            msg = Messages.create(ex, pipeConfig.getBinding().getSOAPVersion());
        } catch (XWSSecurityException xwse) {
            thereWasAFault = true;            
            msg = Messages.create(xwse, pipeConfig.getBinding().getSOAPVersion());
            
        } catch (WebServiceException xwse) {
            thereWasAFault = true;            
            msg = Messages.create(xwse, pipeConfig.getBinding().getSOAPVersion());
          
        } catch(SOAPException se){
            // internal error
            // Log here because this catch is an internal error not logger by the callee
            log.log(Level.SEVERE, 
                    LogStringsMessages.WSSPIPE_0025_ERROR_VERIFY_INBOUND_MSG(), se);
            thereWasAFault = true;            
            msg = Messages.create(se, pipeConfig.getBinding().getSOAPVersion());
            //throw new WebServiceException(LogStringsMessages.WSSPIPE_0025_ERROR_VERIFY_INBOUND_MSG(), se);
        }
        
        Packet retPacket = null;
         if (thereWasAFault) {
            //retPacket = packet;
            if (this.isAddressingEnabled()) {
                if (optimized) {
                    packet.setMessage(((JAXBFilterProcessingContext)ctx).getPVMessage());
                }
                retPacket = packet.createServerResponse(
                        msg, this.addVer, this.soapVersion, this.addVer.getDefaultFaultAction());
            } else {
                packet.setMessage(msg);
                retPacket = packet;
            }
        }
        
        packet.setMessage(msg);
        
        if (isAddressingEnabled()) {
            action = getAction(packet);
            if (WSSCConstants.REQUEST_SECURITY_CONTEXT_TOKEN_ACTION.equals(action)) {
                isSCIssueMessage = true;
            } else if (WSSCConstants.CANCEL_SECURITY_CONTEXT_TOKEN_ACTION.equals(action)) {
                isSCCancelMessage = true;
            } else if (WSTrustConstants.REQUEST_SECURITY_TOKEN_ISSUE_ACTION.equals(action)) {
                isTrustMessage = true;
                packet.getMessage().getHeaders().getTo(addVer, pipeConfig.getBinding().getSOAPVersion());
                
                if(trustConfig != null){
                    packet.invocationProperties.put(Constants.SUN_TRUST_SERVER_SECURITY_POLICY_NS,trustConfig.iterator());

                }
                
                //set the callbackhandler
                packet.invocationProperties.put(WSTrustConstants.SECURITY_ENVIRONMENT, secEnv);

            }
            
            if (isSCIssueMessage){
                List<PolicyAssertion> policies = getInBoundSCP(packet.getMessage());
                if(!policies.isEmpty()) {
                    packet.invocationProperties.put(SC_ASSERTION, (PolicyAssertion)policies.get(0));
                }
            }
        }
        
        if(!isSCIssueMessage ){
            cachedOperation = msg.getOperation(pipeConfig.getWSDLModel());
            if(cachedOperation == null){
                if(addVer != null)
                    cachedOperation = getWSDLOpFromAction(packet, true);
            }
        }
        
        
        
        if (!thereWasAFault) {
            
            if (isSCIssueMessage || isSCCancelMessage) {
                //-------put application message on hold and invoke SC contract--------
                
                retPacket = invokeSecureConversationContract(
                        packet, ctx, isSCIssueMessage, action);
                
            } else {
                //--------INVOKE NEXT PIPE------------
                // Put the addressing headers as unread
                // packet.invocationProperties.put(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND, null);
                updateSCBootstrapCredentials(packet, ctx);
                if (nextPipe != null) {
                    retPacket = nextPipe.process(packet);
                    
                    // Add addrsssing headers to trust message
                    if (isTrustMessage){
                        retPacket = addAddressingHeaders(packet, retPacket.getMessage(), WSTrustConstants.REQUEST_SECURITY_TOKEN_RESPONSE_ISSUE_ACTION);
                    }
                }else {
                    retPacket = packet;
                }
                
             
            }
        }
        
        if(retPacket.getMessage() == null){
            return retPacket;
        }
        /* TODO:this piece of code present since payload should be read once*/
        if (!optimized) {
            try{
                SOAPMessage sm = retPacket.getMessage().readAsSOAPMessage();
                Message newMsg = Messages.create(sm);
                retPacket.setMessage(newMsg);
            }catch(SOAPException ex){
                log.log(Level.SEVERE, 
                        LogStringsMessages.WSSPIPE_0005_PROBLEM_PROC_SOAP_MESSAGE(), ex);                
                throw new WebServiceException(
                        LogStringsMessages.WSSPIPE_0005_PROBLEM_PROC_SOAP_MESSAGE(), ex);                
            }
        }
        
        //---------------OUTBOUND SECURITY PROCESSING----------
        ctx = initializeOutgoingProcessingContext(retPacket, isSCIssueMessage, isTrustMessage /*, thereWasAFault*/);
        
        try{
            msg = retPacket.getMessage();
            if (ctx.getSecurityPolicy() != null && ((MessagePolicy)ctx.getSecurityPolicy()).size() >0) {
                if(!optimized || msg.isFault()) {
                    SOAPMessage soapMessage = msg.readAsSOAPMessage();
                    soapMessage = secureOutboundMessage(soapMessage, ctx);
                    msg = Messages.create(soapMessage);
                }else{
                    msg = secureOutboundMessage(msg, ctx);
                }
            }
        } catch (WssSoapFaultException ex) {
            msg = Messages.create(getSOAPFault(ex));
        } catch(SOAPException se) {
            // internal error
            log.log(Level.SEVERE, 
                    LogStringsMessages.WSSPIPE_0024_ERROR_SECURING_OUTBOUND_MSG(), se);                        
            throw new WebServiceException(
                    LogStringsMessages.WSSPIPE_0024_ERROR_SECURING_OUTBOUND_MSG(), se);
        } finally{
            if (isSCCancel(retPacket)){
                removeContext(packet);
            }
        }
        resetCachedOperation();
        retPacket.setMessage(msg);
        return retPacket;
        
    
public com.sun.xml.ws.api.message.stream.InputStreamMessageprocessInputStream(com.sun.xml.ws.api.message.Packet packet)

        //TODO:Optimized security
        throw new UnsupportedOperationException("Will be supported for optimized path");
    
public com.sun.xml.ws.api.message.stream.InputStreamMessageprocessInputStream(com.sun.xml.ws.api.message.stream.XMLStreamReaderMessage msg)

        //TODO:Optimized security
        throw new UnsupportedOperationException();
    
public com.sun.xml.ws.api.message.stream.InputStreamMessageprocessInputStream(com.sun.xml.ws.api.message.Message msg)

        //TODO:Optimized security
        throw new UnsupportedOperationException();
    
public com.sun.xml.ws.api.message.PacketprocessMessage(com.sun.xml.ws.api.message.stream.XMLStreamReaderMessage msg)

        //TODO:Optimized security
        throw new UnsupportedOperationException();
    
private voidremoveContext(com.sun.xml.ws.api.message.Packet packet)

        SecurityContextToken sct = (SecurityContextToken)packet.invocationProperties.get(MessageConstants.INCOMING_SCT);
        if (sct != null){
            String strId = sct.getIdentifier().toString();
            if(strId!=null){
                issuedTokenContextMap.remove(strId);
                sessionManager.terminateSession(strId);
            }
        }
    
private voidupdateSCBootstrapCredentials(com.sun.xml.ws.api.message.Packet packet, com.sun.xml.wss.ProcessingContext ctx)

        SecurityContextToken sct =
                (SecurityContextToken)packet.invocationProperties.get(MessageConstants.INCOMING_SCT);
        if (sct != null) {
            //Session session = this.sessionManager.getSession(sct.getIdentifier().toString());
            //IssuedTokenContext ctx = session.getSecurityInfo().getIssuedTokenContext();
            IssuedTokenContext itctx = (IssuedTokenContext)((ProcessingContextImpl)ctx).getIssuedTokenContextMap().get(sct.getIdentifier().toString());
            if (itctx != null) {
                Subject from = itctx.getRequestorSubject();
                Subject to = DefaultSecurityEnvironmentImpl.getSubject(packet.invocationProperties);
                copySubject(from,to);
            }
        }
    
protected javax.xml.soap.SOAPMessageverifyInboundMessage(javax.xml.soap.SOAPMessage message, com.sun.xml.wss.ProcessingContext ctx)

        ctx.setSOAPMessage(message);
        NewSecurityRecipient.validateMessage(ctx);
        return ctx.getSOAPMessage();