Package com.sun.xml.wss.impl.policy.mls

Examples of com.sun.xml.wss.impl.policy.mls.TimestampPolicy


            QName definitionType = getQName(eachDefinitionElement);
           
            if (TIMESTAMP_ELEMENT_QNAME.equals(definitionType)) {
               
                if (!timestampFound) {
                    TimestampPolicy timestampPolicy = new TimestampPolicy();
                    readTimestampSettings(timestampPolicy, eachDefinitionElement);
                    applyDefaults(timestampPolicy, senderEnableDynamicPolicy);

                    declarations.senderSettings().append(timestampPolicy);
                    timestampFound = true;
                } else {
                    log.log(Level.SEVERE,
                            "WSS0516.duplicate.configuration.element",
                            new Object[] {
                        definitionType, configData.getLocalName()});
                        throw new IllegalStateException(
                                "Duplicate Timestamp element");
                }
               
            } else if (ENCRYPT_OPERATION_ELEMENT_QNAME.equals(definitionType)) {
               
                EncryptionPolicy encryptionPolicy = new EncryptionPolicy();
                readEncryptionSettings(encryptionPolicy, eachDefinitionElement);
                applyDefaults(encryptionPolicy, senderEnableDynamicPolicy);
                declarations.senderSettings().append(encryptionPolicy);
               
            } else if (SIGN_OPERATION_ELEMENT_QNAME.equals(definitionType)) {
                SignaturePolicy signaturePolicy = new SignaturePolicy();
                readSigningSettings(signaturePolicy, eachDefinitionElement, senderEnableDynamicPolicy);              
                //declarations.senderSettings().append(signaturePolicy);
                //added for BackwardCompatibility with XWSS1.1, the xmlsec in XWSS11 cannot
                //accept PrefixList in CanonicalizationMethod parameters
                SignaturePolicy.FeatureBinding fb =
                         (SignaturePolicy.FeatureBinding)signaturePolicy.getFeatureBinding();
                if (fb != null) {
                     fb.isBSP(senderBSPFlag);
                }
                //end of XWSS11 BC fix
               
                String includeTimeStamp =
                        eachDefinitionElement.getAttribute(INCLUDE_TIMESTAMP_ATTRIBUTE_NAME);
                boolean timeStamp = getBooleanValue(includeTimeStamp);
               
                if (timeStamp && !hasTimestampSiblingPolicy(eachDefinitionElement)) {
                    //System.out.println("Adding from SIGN");
                    TimestampPolicy t = new TimestampPolicy();
                    t.setMaxClockSkew(Timestamp.MAX_CLOCK_SKEW);
                    t.setTimestampFreshness(Timestamp.TIMESTAMP_FRESHNESS_LIMIT);
                    applyDefaults(t, senderEnableDynamicPolicy);
                    declarations.senderSettings().append(t);
                }
               
                declarations.senderSettings().append(signaturePolicy);
               
            } else if (
                    USERNAME_PASSWORD_AUTHENTICATION_ELEMENT_QNAME.
                    equals(definitionType)) {
               
                try {
                    AuthenticationTokenPolicy utBinding =
                            new AuthenticationTokenPolicy();
                    AuthenticationTokenPolicy.UsernameTokenBinding
                            featureBinding =
                            (AuthenticationTokenPolicy.UsernameTokenBinding)
                            utBinding.newUsernameTokenFeatureBinding();
                    featureBinding.newTimestampFeatureBinding();
                    readUsernamePasswordSettings(featureBinding, eachDefinitionElement);
                    applyDefaults(featureBinding, senderEnableDynamicPolicy);
                    declarations.senderSettings().append(utBinding);
                } catch (PolicyGenerationException pge) {
                    // log
                    throw new IllegalStateException(pge.getMessage());
                }
               
            } else if (SAML_ELEMENT_QNAME.equals(definitionType)) {
               
                try {
                    AuthenticationTokenPolicy samlBinding =
                            new AuthenticationTokenPolicy();
                    AuthenticationTokenPolicy.SAMLAssertionBinding
                            featureBinding =
                            (AuthenticationTokenPolicy.SAMLAssertionBinding)
                            samlBinding.newSAMLAssertionFeatureBinding();
                    readSAMLTokenSettings(
                            featureBinding, eachDefinitionElement);
                    applyDefaults(featureBinding, senderEnableDynamicPolicy);
                    declarations.senderSettings().append(samlBinding);
                } catch (PolicyGenerationException pge) {
                    // log
                    throw new IllegalStateException(pge.getMessage());
                }
            } else if (SIGNATURE_REQUIREMENT_ELEMENT_QNAME.equals(
                    definitionType)) {
                SignaturePolicy signaturePolicy = new SignaturePolicy();
                readVerifySettings(signaturePolicy, eachDefinitionElement,receiverBSPFlag, receiverEnableDynamicPolicy);
                declarations.receiverSettings().append(signaturePolicy);
               
                String requireTimeStamp =
                        eachDefinitionElement.getAttribute(TIMESTAMP_REQUIRED_ATTRIBUTE_NAME);
                boolean timeStamp = getBooleanValue(requireTimeStamp);
               
                if (timeStamp && !hasTimestampSiblingPolicy(eachDefinitionElement)) {
                    //System.out.println("Adding from RequireSignature");
                    TimestampPolicy t = new TimestampPolicy();
                    //t.setMaxClockSkew(Timestamp.MAX_CLOCK_SKEW);
                    //t.setTimestampFreshness(Timestamp.TIMESTAMP_FRESHNESS_LIMIT);
                    applyReceiverDefaults(t, receiverBSPFlag, securityHandlerClass, receiverEnableDynamicPolicy);
                    declarations.receiverSettings().append(t);
                }
               
            } else if (ENCRYPTION_REQUIREMENT_ELEMENT_QNAME.equals(
                    definitionType)) {
                EncryptionPolicy encryptionPolicy = new EncryptionPolicy();
                readDecryptionSettings(encryptionPolicy, eachDefinitionElement);
                applyReceiverDefaults(encryptionPolicy, receiverBSPFlag, receiverEnableDynamicPolicy);
                declarations.receiverSettings().append(encryptionPolicy);
               
            } else if (USERNAMETOKEN_REQUIREMENT_ELEMENT_QNAME.equals(
                    definitionType)) {
                try {
                    AuthenticationTokenPolicy utBinding =
                            new AuthenticationTokenPolicy();
                    AuthenticationTokenPolicy.UsernameTokenBinding
                            featureBinding =
                            (AuthenticationTokenPolicy.UsernameTokenBinding)
                            utBinding.newUsernameTokenFeatureBinding();
                    featureBinding.newTimestampFeatureBinding();
                    readUsernamePasswordRequirementSettings(
                            featureBinding, eachDefinitionElement);
                    applyReceiverDefaults(featureBinding, receiverBSPFlag, securityHandlerClass, receiverEnableDynamicPolicy);
                    declarations.receiverSettings().append(utBinding);
                    if (MessageConstants.debug) {
                        log.log(Level.FINEST, "Added usernameToken Requirement ...." + featureBinding);
                    }
                } catch (PolicyGenerationException pge) {
                    // log
                    throw new IllegalStateException(pge.getMessage());
                }
            } else if (TIMESTAMP_REQUIREMENT_ELEMENT_QNAME.equals(
                    definitionType)) {
               
                TimestampPolicy timestampPolicy = new TimestampPolicy();
                readTimestampRequirementSettings(
                        timestampPolicy, eachDefinitionElement);
                applyReceiverDefaults(timestampPolicy, receiverBSPFlag, securityHandlerClass, receiverEnableDynamicPolicy);
                declarations.receiverSettings().append(timestampPolicy);
               
View Full Code Here


       
        String id = getIdAttribute(authenticateUserSettings);
        utBinding.setUUID(id);
       
        //set them on the policy
        TimestampPolicy tPolicy = null;
        try {
            tPolicy = (TimestampPolicy) utBinding.newTimestampFeatureBinding();
        } catch(Exception e) {
            //log
            throw new IllegalStateException(e.getMessage());
        }
       
        NamedNodeMap authenticateUserAttributes = authenticateUserSettings.getAttributes();
        int attributeCount = authenticateUserAttributes.getLength();
        String attributeName = null;
       
        for (int index = 0; index < attributeCount; index++) {
            Attr authenticateUserAttribute = (Attr) authenticateUserAttributes.item(index);
            attributeName = authenticateUserAttribute.getName();
           
            if (ID_ATTRIBUTE_NAME.equalsIgnoreCase(attributeName)) {
                // do nothing
            else if (NONCE_REQUIRED_ATTRIBUTE_NAME
                    .equalsIgnoreCase(attributeName)) {
                utBinding.setUseNonce(
                        getBooleanValue(authenticateUserAttribute.getValue()));
            } else if (PASSWORD_DIGEST_REQUIRED_ATTRIBUTE_NAME
                    .equalsIgnoreCase(attributeName)) {
                utBinding.setDigestOn(
                        getBooleanValue(authenticateUserAttribute.getValue()));
            } else if (MAX_CLOCK_SKEW.equalsIgnoreCase(attributeName)) {
                tPolicy.setMaxClockSkew(parseLong(authenticateUserAttribute.getValue()) * 1000);
            } else if (TIMESTAMP_FRESHNESS_LIMIT.equalsIgnoreCase(attributeName)) {
                tPolicy.setTimestampFreshness(parseLong(authenticateUserAttribute.getValue()) * 1000);
            } else if (MAX_NONCE_AGE.equalsIgnoreCase(attributeName)) {
                utBinding.setMaxNonceAge(parseLong(authenticateUserAttribute.getValue()) * 1000);
            } else {
                log.log(Level.SEVERE,
                        "WSS0512.illegal.attribute.name",
View Full Code Here

            List sList = policy.getSecondaryPolicies();
            Iterator j = sList.iterator();
            while (j.hasNext()) {
                SecurityPolicy secPolicy = (SecurityPolicy) j.next();
                if(PolicyTypeUtil.timestampPolicy(secPolicy)){
                    TimestampPolicy tsPolicy = (TimestampPolicy)secPolicy;
                    IntegrityAssertionProcessor iAP = new IntegrityAssertionProcessor(scp.getAlgorithmSuite(), true);
                    SignatureTargetCreator stc = iAP.getTargetCreator();
                    SignatureTarget sigTarget = stc.newURISignatureTarget(tsPolicy.getUUID());
                    SecurityPolicyUtil.setName(sigTarget, tsPolicy);
                    spFB.addTargetBinding(sigTarget);
                    spFB.isEndorsingSignature(true);
                    addedSigTarget = true;
                    break;
View Full Code Here

             throw ex;
        }
        if (binding.getUseNonce() && unToken.getNonceValue() == null) {
            unToken.setNonce(binding.getNonce());
            String creationTime = "";
            TimestampPolicy tPolicy = (TimestampPolicy) binding.getFeatureBinding();
            if(tPolicy == null)tPolicy = (TimestampPolicy) binding.newTimestampFeatureBinding();
            creationTime = tPolicy.getCreationTime();
            unToken.setCreationTime(creationTime);
        }
        if (binding.getUseCreated() && unToken.getCreatedValue() == null) {
            String creationTime = "";
            TimestampPolicy tPolicy = (TimestampPolicy) binding.getFeatureBinding();
            if(tPolicy == null)tPolicy = (TimestampPolicy) binding.newTimestampFeatureBinding();
            creationTime = tPolicy.getCreationTime();
            unToken.setCreationTime(creationTime);
        }
        binding.setUsernameToken(unToken);
        String dataEncAlgo = null;
        if (context.getAlgorithmSuite() != null) {
View Full Code Here

                AuthenticationTokenPolicy.UsernameTokenBinding policy =
                        (AuthenticationTokenPolicy.UsernameTokenBinding)
                        authPolicy.getFeatureBinding();
               
                if (created != null) {
                    TimestampPolicy tPolicy = (TimestampPolicy) policy.getFeatureBinding();
                    maxClockSkew = tPolicy.getMaxClockSkew();
                    freshnessLmt = tPolicy.getTimestampFreshness();
                }
                maxNonceAge = policy.getMaxNonceAge();
            }
           
            if (created != null) {
View Full Code Here

                unToken.setDigestOn();
            }
           
            if ( policy.getUseNonce() || policy.getDigestOn() || policy.getUseCreated()) {
                String creationTime = "";
                TimestampPolicy tPolicy = (TimestampPolicy) policy.getFeatureBinding();
                creationTime = tPolicy.getCreationTime();
                unToken.setCreationTime(creationTime);
            }
           
           
            if(policy.hasNoPassword()){
                String creationTime = "";
                TimestampPolicy tPolicy = (TimestampPolicy) policy.getFeatureBinding();
                creationTime = tPolicy.getCreationTime();
                unToken.setCreationTime(creationTime);
            }
           
            String wsuId = policy.getUUID();
            if (wsuId != null && !wsuId.equals("")){
                unToken.setId(wsuId);
            }
            secHeader.add(unToken);
        } else {
            SecurableSoapMessage secureMessage = context.getSecurableSoapMessage();
            SOAPPart soapPart = secureMessage.getSOAPPart();
           
            AuthenticationTokenPolicy authPolicy = (AuthenticationTokenPolicy)context.getSecurityPolicy();
            UsernameToken token = new UsernameToken(soapPart, "");
           
            AuthenticationTokenPolicy.UsernameTokenBinding policy =
                    resolveUserNameTokenData(context, token, null,authPolicy);
           
            if(policy.getUseNonce()){
                token.setNonce(policy.getNonce());
            }
            if(policy.getDigestOn()){
                token.setDigestOn();
            }
           
            if ( policy.getUseNonce() || policy.getDigestOn() || policy.getUseCreated()) {
                String creationTime = "";
                TimestampPolicy tPolicy = (TimestampPolicy) policy.getFeatureBinding();
                creationTime = tPolicy.getCreationTime();
                token.setCreationTime(creationTime);
            }
           
            if(policy.hasNoPassword()){
                String creationTime = "";
                TimestampPolicy tPolicy = (TimestampPolicy) policy.getFeatureBinding();
                creationTime = tPolicy.getCreationTime();
                token.setCreationTime(creationTime);
            }
            SecurityHeader wsseSecurity = secureMessage.findOrCreateSecurityHeader();
            String wsuId = policy.getUUID();
            if (wsuId != null && !wsuId.equals("")){
View Full Code Here

       
        if(foundEncryptTargets && binding.getSignatureProtection()){
            protectPrimarySignature();
        }
        if(binding.isIncludeTimeStamp()){
            TimestampPolicy tp = new TimestampPolicy();
            tp.setUUID(pid.generateID());
            container.insert(tp);
            if(!binding.isDisableTimestampSigning()){
                protectTimestamp(tp);
            }
        }
View Full Code Here

        this.filter =  new TimestampProcessor(ctx);
        mark = new XMLStreamBufferMark(nsDecls,creator);
        XMLStreamReader tsReader = XMLStreamReaderFactory.createFilteredXMLStreamReader(reader,filter) ;
        creator.createElementFragment(tsReader,true);
       
        tsPolicy = new TimestampPolicy();
        tsPolicy.setUUID(id);
        tsPolicy.setCreationTime(filter.getCreated());
        tsPolicy.setExpirationTime(filter.getExpires());
       
        this.nsDecls = nsDecls;
View Full Code Here

            throw  ex;
        }
        if (binding.getUseNonce()&& unToken.getNonceValue() == null ) {
            unToken.setNonce(binding.getNonce());
            String creationTime = "";
            TimestampPolicy tPolicy = (TimestampPolicy) binding.getFeatureBinding();
            if(tPolicy == null)tPolicy = (TimestampPolicy) binding.newTimestampFeatureBinding();
            creationTime = tPolicy.getCreationTime();
            unToken.setCreationTime(creationTime);
        }
        if (binding.getUseCreated() && unToken.getCreatedValue() == null) {
            String creationTime = "";
            TimestampPolicy tPolicy = (TimestampPolicy) binding.getFeatureBinding();
            if(tPolicy == null)tPolicy = (TimestampPolicy) binding.newTimestampFeatureBinding();
            creationTime = tPolicy.getCreationTime();
            unToken.setCreationTime(creationTime);
        }
        binding.setUsernameToken(unToken);
        String dataEncAlgo = null;
        if (context.getAlgorithmSuite() != null) {
View Full Code Here

             //hack to prevent multiple timestamp exports
             //TODO: revisit
             if (context.timestampExported())
                 return;

             TimestampPolicy policy = (TimestampPolicy) context.getSecurityPolicy();
             long timeout = policy.getTimeout();
             String created = policy.getCreationTime();
             String id = policy.getUUID();
             if (context.getTimestampTimeout() > 0) {
                 timeout = context.getTimestampTimeout();
             }
             if (context.makeDynamicPolicyCallback()) {
                TimestampPolicy policyClone = (TimestampPolicy) policy.clone();
    try {
                      DynamicApplicationContext dynamicContext =
                          new DynamicApplicationContext (context.getPolicyContext ());

                      dynamicContext.setMessageIdentifier (context.getMessageIdentifier ());
                      dynamicContext.inBoundMessage (false);
                      // TODO: copy runtime properties into callback context
                      DynamicPolicyCallback callback =
                          new DynamicPolicyCallback (policyClone, dynamicContext);
                      ProcessingContext.copy (dynamicContext.getRuntimeProperties(), context.getExtraneousProperties());
                      HarnessUtil.makeDynamicPolicyCallback(callback,
                          context.getSecurityEnvironment().getCallbackHandler());

                 } catch (Exception e) {
                    log.log(Level.SEVERE, "Message does not conform to time stamp policy", e);
                    throw new XWSSecurityException (e);
                 }

                timeout   = policyClone.getTimeout();
                created = policyClone.getCreationTime();
             }
            
             setTimestamp(context, timeout, created, id);

             //hack to prevent multiple timestamp exports
             //TODO: revisit
             context.timestampExported(true);

         } else {    
            
             // Processing inbound messages            
             Timestamp timestamp = null;
            
             if (context.getMode() == FilterProcessingContext.ADHOC) {
                
                 if (context.makeDynamicPolicyCallback()) {
                     TimestampPolicy policyClone = (TimestampPolicy)
                         ((TimestampPolicy)context.getSecurityPolicy()).clone();
         try {
                         DynamicApplicationContext dynamicContext =
                             new DynamicApplicationContext (context.getPolicyContext ());

                         dynamicContext.setMessageIdentifier (context.getMessageIdentifier ());
                         dynamicContext.inBoundMessage (true);
                         DynamicPolicyCallback callback =
                             new DynamicPolicyCallback (policyClone, dynamicContext);
                         ProcessingContext.copy (dynamicContext.getRuntimeProperties(), context.getExtraneousProperties());
                         HarnessUtil.makeDynamicPolicyCallback(callback,
                             context.getSecurityEnvironment().getCallbackHandler());

                     } catch (Exception e) {
                    log.log(Level.SEVERE, LogStringsMessages.WSS_1436_MESSAGE_DOESNOT_CONFORM_TIMESTAMP_POLICY(), e);
                         throw new XWSSecurityException (e);
                     }
                     context.setSecurityPolicy(policyClone);
                 }
                
                 TimestampPolicy policy = (TimestampPolicy) context.getSecurityPolicy();
                 long maxClockSkew = policy.getMaxClockSkew ();
                 long timeStampFreshness = policy.getTimestampFreshness ();

                 SecurityHeader secHeader = context.getSecurableSoapMessage().findSecurityHeader();
                 if (secHeader == null) {
             log.log(Level.SEVERE, com.sun.xml.wss.logging.LogStringsMessages.WSS_0276_INVALID_POLICY_NO_TIMESTAMP_SEC_HEADER());
                         throw new XWSSecurityException(
                        "Message does not conform to Timestamp policy: " +
                  "wsu:Timestamp element not found in header");
                 }

                 SOAPElement ts = null;

                 try {
         SOAPFactory factory = SOAPFactory.newInstance();
         Name name = factory.createName(
                         MessageConstants.TIMESTAMP_LNAME,
             MessageConstants.WSU_PREFIX,
       MessageConstants.WSU_NS);
         Iterator i = secHeader.getChildElements (name);
                    
         if (i.hasNext()) {
             ts = (SOAPElement) i.next();
       if (i.hasNext()) {
                             log.log(Level.SEVERE, com.sun.xml.wss.logging.LogStringsMessages.BSP_3227_SINGLE_TIMESTAMP());
           throw new XWSSecurityException("More than one wsu:Timestamp element in the header");
       }
         } else {
        log.log(Level.SEVERE, com.sun.xml.wss.logging.LogStringsMessages.WSS_0276_INVALID_POLICY_NO_TIMESTAMP_SEC_HEADER());
       throw new XWSSecurityException(
                             "Message does not conform to Timestamp policy: " +
                 "wsu:Timestamp element not found in header");
         }
     } catch (SOAPException se) {
       // log
       throw new XWSSecurityRuntimeException (se);
     }

     try {
         timestamp = new Timestamp (ts);                    
                 } catch (XWSSecurityException xwsse) {
                     log.log(Level.SEVERE, LogStringsMessages.WSS_1429_ERROR_TIMESTAMP_INTERNALIZATION(), xwsse);
                    throw SecurableSoapMessage.newSOAPFaultException(
                         MessageConstants.WSSE_INVALID_SECURITY,
                         "Failure in Timestamp internalization.\n" +
                         "Message is: " + xwsse.getMessage(),
                         xwsse);
                 }

                 try {
                     context.getSecurityEnvironment().validateTimestamp(
                         context.getExtraneousProperties(), timestamp, maxClockSkew, timeStampFreshness);
                 } catch (XWSSecurityException xwsse) {
                     log.log(Level.SEVERE, LogStringsMessages.WSS_1430_ERROR_TIMESTAMP_VALIDATION(), xwsse);
                    throw SecurableSoapMessage.newSOAPFaultException(
                         MessageConstants.WSSE_INVALID_SECURITY,
                         "Failure in Timestamp validation.\n" +
                         "Message is: " + xwsse.getMessage(),
                         xwsse);
                 }

                 if (MessageConstants.debug) {
                     log.log(Level.FINEST, "Validated TIMESTAMP.....");
                 }
             } else {
                
                 if (context.getMode() == FilterProcessingContext.POSTHOC) {
                     throw new XWSSecurityException("Internal Error: Called TimestampFilter in POSTHOC Mode");
                 }

                 if (context.getMode() == FilterProcessingContext.WSDL_POLICY) {
                     TimestampPolicy ts =  new TimestampPolicy();
                     context.getInferredSecurityPolicy().append(ts);
                 }

                 SecurityHeader secHeader = context.getSecurableSoapMessage().findSecurityHeader();
                 try {
View Full Code Here

TOP

Related Classes of com.sun.xml.wss.impl.policy.mls.TimestampPolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.