org.apache.ws.security.message.WSSecTimestamp Java Examples

The following examples show how to use org.apache.ws.security.message.WSSecTimestamp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SymmetricBindingHandler.java    From steady with Apache License 2.0 6 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (isRequestor()) {
        //Setup required tokens
        initializeTokens();
    }
    
    if (sbinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
    //REVIST - what to do with these policies?
    policyAsserted(SP11Constants.TRUST_10);
    policyAsserted(SP12Constants.TRUST_13);
}
 
Example #2
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected WSSecTimestamp createTimestamp() {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.INCLUDE_TIMESTAMP);
    if (ais != null) {
        Object o = message.getContextualProperty(SecurityConstants.TIMESTAMP_TTL);
        int ttl = 300;  //default is 300 seconds
        if (o instanceof Number) {
            ttl = ((Number)o).intValue();
        } else if (o instanceof String) {
            ttl = Integer.parseInt((String)o);
        }
        if (ttl <= 0) {
            ttl = 300;
        }
        timestampEl = new WSSecTimestamp(wssConfig);
        timestampEl.setTimeToLive(ttl);
        timestampEl.prepare(saaj.getSOAPPart());
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }                    
    }
    return timestampEl;
}
 
Example #3
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected WSSecTimestamp createTimestamp() {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.INCLUDE_TIMESTAMP);
    if (ais != null) {
        Object o = message.getContextualProperty(SecurityConstants.TIMESTAMP_TTL);
        int ttl = 300;  //default is 300 seconds
        if (o instanceof Number) {
            ttl = ((Number)o).intValue();
        } else if (o instanceof String) {
            ttl = Integer.parseInt((String)o);
        }
        if (ttl <= 0) {
            ttl = 300;
        }
        timestampEl = new WSSecTimestamp(wssConfig);
        timestampEl.setTimeToLive(ttl);
        timestampEl.prepare(saaj.getSOAPPart());
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }                    
    }
    return timestampEl;
}
 
Example #4
Source File: SymmetricBindingHandler.java    From steady with Apache License 2.0 6 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (isRequestor()) {
        //Setup required tokens
        initializeTokens();
    }
    
    if (sbinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
    //REVIST - what to do with these policies?
    policyAsserted(SP11Constants.TRUST_10);
    policyAsserted(SP12Constants.TRUST_13);
}
 
Example #5
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected WSSecTimestamp createTimestamp() {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.INCLUDE_TIMESTAMP);
    if (ais != null) {
        Object o = message.getContextualProperty(SecurityConstants.TIMESTAMP_TTL);
        int ttl = 300;  //default is 300 seconds
        if (o instanceof Number) {
            ttl = ((Number)o).intValue();
        } else if (o instanceof String) {
            ttl = Integer.parseInt((String)o);
        }
        if (ttl <= 0) {
            ttl = 300;
        }
        timestampEl = new WSSecTimestamp(wssConfig);
        timestampEl.setTimeToLive(ttl);
        timestampEl.prepare(saaj.getSOAPPart());
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }                    
    }
    return timestampEl;
}
 
Example #6
Source File: SymmetricBindingHandler.java    From steady with Apache License 2.0 6 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (isRequestor()) {
        //Setup required tokens
        initializeTokens();
    }
    
    if (sbinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
    //REVIST - what to do with these policies?
    policyAsserted(SP11Constants.TRUST_10);
    policyAsserted(SP12Constants.TRUST_13);
}
 
Example #7
Source File: SymmetricBindingHandler.java    From steady with Apache License 2.0 6 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (isRequestor()) {
        //Setup required tokens
        initializeTokens();
    }
    
    if (sbinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
    //REVIST - what to do with these policies?
    policyAsserted(SP11Constants.TRUST_10);
    policyAsserted(SP12Constants.TRUST_13);
}
 
Example #8
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected WSSecTimestamp createTimestamp() {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.INCLUDE_TIMESTAMP);
    if (ais != null) {
        Object o = message.getContextualProperty(SecurityConstants.TIMESTAMP_TTL);
        int ttl = 300;  //default is 300 seconds
        if (o instanceof Number) {
            ttl = ((Number)o).intValue();
        } else if (o instanceof String) {
            ttl = Integer.parseInt((String)o);
        }
        if (ttl <= 0) {
            ttl = 300;
        }
        timestampEl = new WSSecTimestamp(wssConfig);
        timestampEl.setTimeToLive(ttl);
        timestampEl.prepare(saaj.getSOAPPart());
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }                    
    }
    return timestampEl;
}
 
Example #9
Source File: AsymmetricBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (abinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
}
 
Example #10
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
protected WSSecTimestamp handleLayout(WSSecTimestamp timestamp) {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.LAYOUT);
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            Layout layout = (Layout)ai.getAssertion();
            ai.setAsserted(true);
            if (SPConstants.Layout.LaxTimestampLast == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    ai.setAsserted(true);
                    Element el = timestamp.getElement();
                    secHeader.getSecurityHeader().appendChild(el);
                    if (bottomUpElement == null) {
                        bottomUpElement = el;
                    }
                }
            } else if (SPConstants.Layout.LaxTimestampFirst == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    addTopDownElement(timestampEl.getElement());
                }
            } else if (timestampEl != null) {
                addTopDownElement(timestampEl.getElement());
            }
        }                    
    } else if (timestampEl != null) {
        addTopDownElement(timestampEl.getElement());
    }
    return timestamp;
}
 
Example #11
Source File: TransportBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    try {
        if (this.isRequestor()) {
            TransportToken transportTokenWrapper = tbinding.getTransportToken();
            if (transportTokenWrapper != null) {
                Token transportToken = transportTokenWrapper.getToken();
                if (transportToken instanceof IssuedToken) {
                    SecurityToken secToken = getSecurityToken();
                    if (secToken == null) {
                        policyNotAsserted(transportToken, "No transport token id");
                        return;
                    } else {
                        policyAsserted(transportToken);
                    }
                    if (includeToken(transportToken.getInclusion())) {
                        Element el = secToken.getToken();
                        addEncryptedKeyElement(cloneElement(el));
                    } 
                }
                
                handleNonEndorsingSupportingTokens();
                handleEndorsingSupportingTokens();
            }
        } else {
            addSignatureConfirmation(null);
        }
    } catch (Exception e) {
        LOG.log(Level.FINE, e.getMessage(), e);
        throw new Fault(e);
    }
}
 
Example #12
Source File: AsymmetricBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (abinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
}
 
Example #13
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
protected WSSecTimestamp handleLayout(WSSecTimestamp timestamp) {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.LAYOUT);
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            Layout layout = (Layout)ai.getAssertion();
            ai.setAsserted(true);
            if (SPConstants.Layout.LaxTimestampLast == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    ai.setAsserted(true);
                    Element el = timestamp.getElement();
                    secHeader.getSecurityHeader().appendChild(el);
                    if (bottomUpElement == null) {
                        bottomUpElement = el;
                    }
                }
            } else if (SPConstants.Layout.LaxTimestampFirst == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    addTopDownElement(timestampEl.getElement());
                }
            } else if (timestampEl != null) {
                addTopDownElement(timestampEl.getElement());
            }
        }                    
    } else if (timestampEl != null) {
        addTopDownElement(timestampEl.getElement());
    }
    return timestamp;
}
 
Example #14
Source File: TransportBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    try {
        if (this.isRequestor()) {
            TransportToken transportTokenWrapper = tbinding.getTransportToken();
            if (transportTokenWrapper != null) {
                Token transportToken = transportTokenWrapper.getToken();
                if (transportToken instanceof IssuedToken) {
                    SecurityToken secToken = getSecurityToken();
                    if (secToken == null) {
                        policyNotAsserted(transportToken, "No transport token id");
                        return;
                    } else {
                        policyAsserted(transportToken);
                    }
                    if (includeToken(transportToken.getInclusion())) {
                        Element el = secToken.getToken();
                        addEncryptedKeyElement(cloneElement(el));
                    } 
                }
                
                handleNonEndorsingSupportingTokens();
                handleEndorsingSupportingTokens();
            }
        } else {
            addSignatureConfirmation(null);
        }
    } catch (Exception e) {
        LOG.log(Level.FINE, e.getMessage(), e);
        throw new Fault(e);
    }
}
 
Example #15
Source File: AsymmetricBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (abinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
}
 
Example #16
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
protected WSSecTimestamp handleLayout(WSSecTimestamp timestamp) {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.LAYOUT);
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            Layout layout = (Layout)ai.getAssertion();
            ai.setAsserted(true);
            if (SPConstants.Layout.LaxTimestampLast == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    ai.setAsserted(true);
                    Element el = timestamp.getElement();
                    secHeader.getSecurityHeader().appendChild(el);
                    if (bottomUpElement == null) {
                        bottomUpElement = el;
                    }
                }
            } else if (SPConstants.Layout.LaxTimestampFirst == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    addTopDownElement(timestampEl.getElement());
                }
            } else if (timestampEl != null) {
                addTopDownElement(timestampEl.getElement());
            }
        }                    
    } else if (timestampEl != null) {
        addTopDownElement(timestampEl.getElement());
    }
    return timestamp;
}
 
Example #17
Source File: TransportBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    try {
        if (this.isRequestor()) {
            TransportToken transportTokenWrapper = tbinding.getTransportToken();
            if (transportTokenWrapper != null) {
                Token transportToken = transportTokenWrapper.getToken();
                if (transportToken instanceof IssuedToken) {
                    SecurityToken secToken = getSecurityToken();
                    if (secToken == null) {
                        policyNotAsserted(transportToken, "No transport token id");
                        return;
                    } else {
                        policyAsserted(transportToken);
                    }
                    if (includeToken(transportToken.getInclusion())) {
                        Element el = secToken.getToken();
                        addEncryptedKeyElement(cloneElement(el));
                    } 
                }
                
                handleNonEndorsingSupportingTokens();
                handleEndorsingSupportingTokens();
            }
        } else {
            addSignatureConfirmation(null);
        }
    } catch (Exception e) {
        LOG.log(Level.FINE, e.getMessage(), e);
        throw new Fault(e);
    }
}
 
Example #18
Source File: AsymmetricBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    if (abinding.getProtectionOrder() == SPConstants.ProtectionOrder.EncryptBeforeSigning) {
        doEncryptBeforeSign();
    } else {
        doSignBeforeEncrypt();
    }
}
 
Example #19
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
protected WSSecTimestamp handleLayout(WSSecTimestamp timestamp) {
    Collection<AssertionInfo> ais;
    ais = aim.get(SP12Constants.LAYOUT);
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            Layout layout = (Layout)ai.getAssertion();
            ai.setAsserted(true);
            if (SPConstants.Layout.LaxTimestampLast == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    ai.setAsserted(true);
                    Element el = timestamp.getElement();
                    secHeader.getSecurityHeader().appendChild(el);
                    if (bottomUpElement == null) {
                        bottomUpElement = el;
                    }
                }
            } else if (SPConstants.Layout.LaxTimestampFirst == layout.getValue()) {
                if (timestamp == null) {
                    ai.setNotAsserted(SPConstants.Layout.LaxTimestampLast + " requires a timestamp");
                } else {
                    addTopDownElement(timestampEl.getElement());
                }
            } else if (timestampEl != null) {
                addTopDownElement(timestampEl.getElement());
            }
        }                    
    } else if (timestampEl != null) {
        addTopDownElement(timestampEl.getElement());
    }
    return timestamp;
}
 
Example #20
Source File: TransportBindingHandler.java    From steady with Apache License 2.0 5 votes vote down vote up
public void handleBinding() {
    WSSecTimestamp timestamp = createTimestamp();
    handleLayout(timestamp);
    
    try {
        if (this.isRequestor()) {
            TransportToken transportTokenWrapper = tbinding.getTransportToken();
            if (transportTokenWrapper != null) {
                Token transportToken = transportTokenWrapper.getToken();
                if (transportToken instanceof IssuedToken) {
                    SecurityToken secToken = getSecurityToken();
                    if (secToken == null) {
                        policyNotAsserted(transportToken, "No transport token id");
                        return;
                    } else {
                        policyAsserted(transportToken);
                    }
                    if (includeToken(transportToken.getInclusion())) {
                        Element el = secToken.getToken();
                        addEncryptedKeyElement(cloneElement(el));
                    } 
                }
                
                handleNonEndorsingSupportingTokens();
                handleEndorsingSupportingTokens();
            }
        } else {
            addSignatureConfirmation(null);
        }
    } catch (Exception e) {
        LOG.log(Level.FINE, e.getMessage(), e);
        throw new Fault(e);
    }
}
 
Example #21
Source File: SoapWrapper.java    From iaf with Apache License 2.0 4 votes vote down vote up
public String signMessage(String soapMessage, String user, String password, boolean passwordDigest) {
	try {
		WSSecurityEngine secEngine = WSSecurityEngine.getInstance();
		WSSConfig config = secEngine.getWssConfig();
		config.setPrecisionInMilliSeconds(false);

		// create context
		AxisClient tmpEngine = new AxisClient(new NullProvider());
		MessageContext msgContext = new MessageContext(tmpEngine);

		InputStream in = new ByteArrayInputStream(soapMessage.getBytes(StreamUtil.DEFAULT_INPUT_STREAM_ENCODING));
		Message msg = new Message(in);
		msg.setMessageContext(msgContext);

		// create unsigned envelope
		SOAPEnvelope unsignedEnvelope = msg.getSOAPEnvelope();
		Document doc = unsignedEnvelope.getAsDocument();

		// create security header and insert it into unsigned envelope
		WSSecHeader secHeader = new WSSecHeader();
		secHeader.insertSecurityHeader(doc);

		// add a UsernameToken
		WSSecUsernameToken tokenBuilder = new WSSecUsernameToken();
		if (passwordDigest) {
			tokenBuilder.setPasswordType(WSConstants.PASSWORD_DIGEST);
		} else {
			tokenBuilder.setPasswordType(WSConstants.PASSWORD_TEXT);
		}
		tokenBuilder.setUserInfo(user, password);
		tokenBuilder.addNonce();
		tokenBuilder.addCreated();
		tokenBuilder.prepare(doc);

		WSSecSignature sign = new WSSecSignature();
		sign.setUsernameToken(tokenBuilder);
		sign.setKeyIdentifierType(WSConstants.UT_SIGNING);
		sign.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
		sign.build(doc, null, secHeader);

		tokenBuilder.prependToHeader(secHeader);

		// add a Timestamp
		WSSecTimestamp timestampBuilder = new WSSecTimestamp();
		timestampBuilder.setTimeToLive(300);
		timestampBuilder.prepare(doc);
		timestampBuilder.prependToHeader(secHeader);

		Document signedDoc = doc;

		return DOM2Writer.nodeToString(signedDoc);

	} catch (Exception e) {
		throw new RuntimeException("Could not sign message", e);
	}
}