public Timestamp()

in ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/Timestamp.java [62:155]


    public Timestamp(Element timestampElement, BSPEnforcer bspEnforcer) throws WSSecurityException {

        element = timestampElement;

        String strExpires = null;

        for (Node currentChild = element.getFirstChild();
             currentChild != null;
             currentChild = currentChild.getNextSibling()
         ) {
            if (Node.ELEMENT_NODE == currentChild.getNodeType()) {
                Element currentChildElement = (Element) currentChild;
                if (WSConstants.CREATED_LN.equals(currentChild.getLocalName())
                    && WSConstants.WSU_NS.equals(currentChild.getNamespaceURI())) {
                    if (createdString == null) {
                        String valueType = currentChildElement.getAttributeNS(null, "ValueType");
                        if (valueType != null && valueType.length() != 0) {
                            // We can't have a ValueType attribute as per the BSP spec
                            bspEnforcer.handleBSPRule(BSPRule.R3225);
                        }
                        createdString = ((Text)currentChildElement.getFirstChild()).getData();
                    } else {
                        // Test for multiple Created elements
                        bspEnforcer.handleBSPRule(BSPRule.R3203);
                    }
                } else if (WSConstants.EXPIRES_LN.equals(currentChild.getLocalName())
                    && WSConstants.WSU_NS.equals(currentChild.getNamespaceURI())) {
                    if (createdString == null) {
                        // Created must appear before Expires
                        bspEnforcer.handleBSPRule(BSPRule.R3221);
                    }
                    if (strExpires != null) {
                        // We can't have multiple Expires elements
                        bspEnforcer.handleBSPRule(BSPRule.R3224);
                    } else {
                        String valueType = currentChildElement.getAttributeNS(null, "ValueType");
                        if (valueType != null && valueType.length() != 0) {
                            // We can't have a ValueType attribute as per the BSP spec
                            bspEnforcer.handleBSPRule(BSPRule.R3226);
                        }
                        strExpires = ((Text)currentChildElement.getFirstChild()).getData();
                    }
                } else {
                    bspEnforcer.handleBSPRule(BSPRule.R3222);
                }
            }
        }

        // We must have a Created element
        if (createdString == null) {
            bspEnforcer.handleBSPRule(BSPRule.R3203);
        }

        // Parse the dates
        if (createdString != null) {
            try {
                ZonedDateTime createdDateTime = ZonedDateTime.parse(createdString);
                if (!ZoneOffset.UTC.equals(createdDateTime.getZone())) {
                    bspEnforcer.handleBSPRule(BSPRule.R3217);
                }

                created = createdDateTime.toInstant();
            } catch (DateTimeParseException e) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
            }

            if (created.getNano() > 0) {
                int milliseconds = created.get(ChronoField.MILLI_OF_SECOND);
                if (milliseconds * 1000000 != created.getNano()) {
                    bspEnforcer.handleBSPRule(BSPRule.R3220);
                }
            }
        }

        if (strExpires != null) {
            try {
                ZonedDateTime expiresDateTime = ZonedDateTime.parse(strExpires);
                if (!ZoneOffset.UTC.equals(expiresDateTime.getZone())) {
                    bspEnforcer.handleBSPRule(BSPRule.R3223);
                }

                expires = expiresDateTime.toInstant();
            } catch (DateTimeParseException e) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
            }

            if (expires.getNano() > 0) {
                int milliseconds = expires.get(ChronoField.MILLI_OF_SECOND);
                if (milliseconds * 1000000 != expires.getNano()) {
                    bspEnforcer.handleBSPRule(BSPRule.R3229);
                }
            }
        }
    }