FileDocCategorySizeDatePackage
PolicyResolverImpl.javaAPI DocExample13152Tue May 29 16:57:22 BST 2007com.sun.xml.wss.jaxws.impl

PolicyResolverImpl

public class PolicyResolverImpl extends Object implements com.sun.xml.wss.impl.PolicyResolver
author
Ashutosh.Shahi@sun.com

Fields Summary
private com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation
cachedOperation
private HashMap
inMessagePolicyMap
private HashMap
inProtocolPM
private AddressingVersion
addVer
private com.sun.xml.ws.assembler.PipeConfiguration
pipeConfig
private boolean
isClient
private boolean
isSCMessage
private String
action
Constructors Summary
public PolicyResolverImpl(HashMap inMessagePolicyMap, HashMap ip, com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation cachedOperation, com.sun.xml.ws.assembler.PipeConfiguration pipeConfig, AddressingVersion addVer, boolean isClient)
Creates a new instance of OperationResolverImpl

               
    
             
        this.inMessagePolicyMap = inMessagePolicyMap;
        this.inProtocolPM = ip;
        this.cachedOperation = cachedOperation;
        this.pipeConfig = pipeConfig;
        this.addVer = addVer;
        this.isClient = isClient;
    
Methods Summary
private java.lang.StringgetAction(com.sun.xml.ws.api.model.wsdl.WSDLOperation operation)

        if(!isClient){
            return operation.getInput().getAction();
        }else{
            return operation.getOutput().getAction();
        }
    
private java.lang.StringgetAction(com.sun.xml.ws.api.message.Message msg)

        if(addVer != null){
            HeaderList hl = msg.getHeaders();
            String action =  hl.getAction(addVer, pipeConfig.getBinding().getSOAPVersion());
            return action;
        }
        return "";
        
    
protected com.sun.xml.ws.policy.PolicyAssertiongetInBoundSCP()

        
        SecurityPolicyHolder sph = null;
        Collection coll = inMessagePolicyMap.values();
        Iterator itr = coll.iterator();
        
        while(itr.hasNext()){
            SecurityPolicyHolder ph = (SecurityPolicyHolder) itr.next();
            if(ph != null){
                sph = ph;
                break;
            }
        }
        if(sph == null){
            return null;
        }
        List<PolicyAssertion> policies = sph.getSecureConversationTokens();
        if(!policies.isEmpty()) {
            return (PolicyAssertion)policies.get(0);
        }
        return null;
    
private com.sun.xml.wss.impl.policy.mls.MessagePolicygetInboundFaultPolicy(javax.xml.soap.SOAPMessage msg)

        if(cachedOperation != null){
            WSDLOperation operation = cachedOperation.getOperation();
            try{
                SOAPBody body = msg.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 new MessagePolicy();
                    }
                    String uri = faultNode.getNamespaceURI();
                    QName faultDetail = null;
                    if(uri != null && uri.length() >0){
                        faultDetail = new QName(faultNode.getNamespaceURI(),faultNode.getNodeName());
                    }else{
                        faultDetail = new QName(faultNode.getNodeName());
                    }
                    WSDLFault fault = operation.getFault(faultDetail);
                    SecurityPolicyHolder sph = inMessagePolicyMap.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 new MessagePolicy();
        
    
private com.sun.xml.wss.impl.policy.mls.MessagePolicygetInboundXWSBootstrapPolicy(com.sun.xml.ws.security.policy.Token scAssertion)

        return ((SCTokenWrapper)scAssertion).getMessagePolicy();
    
private com.sun.xml.wss.impl.policy.mls.MessagePolicygetInboundXWSSecurityPolicy(com.sun.xml.ws.api.message.Message msg)

        MessagePolicy mp = null;
        
        
        
        //Review : Will this return operation name in all cases , doclit,rpclit, wrap / non wrap ?
        WSDLBoundOperation operation = null;
        if(cachedOperation != null){
            operation = cachedOperation;
        }else{
            operation = msg.getOperation(pipeConfig.getWSDLModel());
            if(operation == null)
                operation = getWSDLOpFromAction();
        }
        
        SecurityPolicyHolder sph = (SecurityPolicyHolder) inMessagePolicyMap.get(operation);
        //TODO: pass isTrustMessage Flag to this method later
        if (sph == null && (isTrustMessage() || isSCMessage)) {
            operation = getWSDLOpFromAction();
            sph = (SecurityPolicyHolder) inMessagePolicyMap.get(operation);
        }
        if(sph == null){
            return null;
        }
        
        mp = sph.getMessagePolicy();
        
        return mp;
    
private com.sun.xml.ws.api.model.wsdl.WSDLBoundOperationgetWSDLOpFromAction()

        Set <WSDLBoundOperation>keys = inMessagePolicyMap.keySet();
        for(WSDLBoundOperation wbo : keys){
            WSDLOperation wo = wbo.getOperation();
            // WsaWSDLOperationExtension extensions = wo.getExtension(WsaWSDLOperationExtension.class);
            String confAction = getAction(wo);
            if(confAction != null && confAction.equals(action)){
                return wbo;
            }
        }
        return null;
    
private booleanisRMMessage()

        if (RM_CREATE_SEQ.equals(action) || RM_CREATE_SEQ_RESP.equals(action)
        || RM_SEQ_ACK.equals(action) || RM_TERMINATE_SEQ.equals(action)
        || RM_LAST_MESSAGE.equals(action)) {
            return true;
        }
        return false;
    
private booleanisSCCancel()

        
        if(WSSCConstants.CANCEL_SECURITY_CONTEXT_TOKEN_RESPONSE_ACTION.equals(action) ||
                WSSCConstants.CANCEL_SECURITY_CONTEXT_TOKEN_ACTION .equals(action)) {
            return true;
        }
        return false;
    
private booleanisSCMessage()

        if (rstSCTURI.equals(action) || rstrSCTURI.equals(action)){
            return true;
        }
        return false;
    
private booleanisTrustMessage()

        if(WSTrustConstants.REQUEST_SECURITY_TOKEN_ISSUE_ACTION.equals(action) ||
                WSTrustConstants.REQUEST_SECURITY_TOKEN_RESPONSE_ISSUE_ACTION.equals(action)){
            return true;
        }
        return false;
        
    
public com.sun.xml.wss.impl.policy.mls.MessagePolicyresolvePolicy(com.sun.xml.wss.ProcessingContext ctx)

        Message msg = (Message)ctx.getExtraneousProperty(JAXWS_21_MESSAGE);
        Packet packet = null;
        MessagePolicy mp = null;
        SOAPMessage soapMsg = null;
        if(msg == null){
            if(ctx instanceof JAXBFilterProcessingContext){
                msg = ((JAXBFilterProcessingContext)ctx).getJAXWSMessage();
            } else{
                soapMsg = ctx.getSOAPMessage();
                msg = Messages.create(soapMsg);
            }
            ctx.setExtraneousProperty(JAXWS_21_MESSAGE,msg);
        }
        action = getAction(msg);
        if (isRMMessage()) {
            SecurityPolicyHolder holder = inProtocolPM.get("RM");
            return holder.getMessagePolicy();
            
        }
        
        if(isSCCancel()){
            SecurityPolicyHolder holder = inProtocolPM.get("SC");
            return holder.getMessagePolicy();
        }
        isSCMessage = isSCMessage();
        if (isSCMessage ) {
            Token scToken = (Token)getInBoundSCP();
            return getInboundXWSBootstrapPolicy(scToken);
        }
        
        if (msg.isFault()) {
            if(soapMsg == null){
                try {
                    soapMsg = msg.readAsSOAPMessage();
                } catch (SOAPException ex) {
                    //ex.printStackTrace();
                }
            }
            mp = getInboundFaultPolicy(soapMsg);
        }  else{
            mp =  getInboundXWSSecurityPolicy(msg);
        }
        
        if(mp == null){
            return new MessagePolicy();
        }
        return mp;