Element writeSecurityTokenReference( W3CDOMStreamWriter writer, String id, String refValueType ) { Reference ref = new Reference(writer.getDocument()); ref.setURI(id); if (refValueType != null) { ref.setValueType(refValueType); } SecurityTokenReference str = new SecurityTokenReference(writer.getDocument()); str.addWSSENamespace(); str.setReference(ref); writer.getCurrentNode().appendChild(str.getElement()); return str.getElement(); }
@Override public int hashCode() { int result = 17; String uri = getURI(); if (uri != null) { result = 31 * result + uri.hashCode(); } String valueType = getValueType(); if (valueType != null) { result = 31 * result + valueType.hashCode(); } return result; }
@Override public boolean equals(Object object) { if (!(object instanceof Reference)) { return false; } Reference reference = (Reference)object; if (!compare(getURI(), reference.getURI())) { return false; } if (!compare(getValueType(), reference.getValueType())) { return false; } return true; }
/** * Constructor. * * @param elem The Reference element * @throws WSSecurityException */ public Reference(Element elem) throws WSSecurityException { if (elem == null) { throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, "noReference"); } element = elem; QName el = new QName(element.getNamespaceURI(), element.getLocalName()); if (!el.equals(TOKEN)) { throw new WSSecurityException( WSSecurityException.ErrorCode.FAILURE, "badElement", new Object[] {TOKEN, el} ); } String uri = getURI(); // Reference URI cannot be null or empty if (uri == null || "".equals(uri)) { throw new WSSecurityException( WSSecurityException.ErrorCode.INVALID_SECURITY, "badReferenceURI" ); } }
if (secRef.containsReference()) { String valueType = secRef.getReference().getValueType(); if (token instanceof X509Security && !X509Security.X509_V3_TYPE.equals(valueType) || token instanceof PKIPathSecurity && !PKIPathSecurity.PKI_TYPE.equals(valueType)
/** * Constructor. * * @param elem A SecurityTokenReference element * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules * @throws WSSecurityException */ public SecurityTokenReference(Element elem, BSPEnforcer bspEnforcer) throws WSSecurityException { element = elem; QName el = new QName(element.getNamespaceURI(), element.getLocalName()); if (!STR_QNAME.equals(el)) { throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "badElement", new Object[] {STR_QNAME, el}); } checkBSPCompliance(bspEnforcer); if (containsReference()) { Node node = element.getFirstChild(); while (node != null) { if (Node.ELEMENT_NODE == node.getNodeType() && WSS4JConstants.WSSE_NS.equals(node.getNamespaceURI()) && "Reference".equals(node.getLocalName())) { reference = new Reference((Element)node); break; } node = node.getNextSibling(); } } }
/** * set the reference. * * @param ref */ public void setReference(Reference ref) { Element elem = getFirstElement(); if (elem != null) { element.replaceChild(ref.getElement(), elem); } else { element.appendChild(ref.getElement()); } this.reference = ref; }
Reference reference = getReference(); if (reference != null) { result = 31 * result + reference.hashCode();
if (!getReference().equals(tokenReference.getReference())) { return false;
private SecurityToken findCancelOrRenewToken(Exchange exchange, Element el) throws WSSecurityException { Element childElement = DOMUtils.getFirstElement(el); String uri = ""; if ("SecurityContextToken".equals(childElement.getLocalName())) { SecurityContextToken sct = new SecurityContextToken(childElement); uri = sct.getIdentifier(); } else { SecurityTokenReference ref = new SecurityTokenReference(childElement, new BSPEnforcer()); uri = ref.getReference().getURI(); } TokenStore store = (TokenStore)exchange.getEndpoint().getEndpointInfo() .getProperty(TokenStore.class.getName()); return store.getToken(uri); }
/** * Check that the Username token referenced by the SecurityTokenReference argument * is BSP compliant. * @param secRef The SecurityTokenReference to the Username token * @param bspEnforcer a BSPEnforcer instance to enforce BSP rules * @throws WSSecurityException */ public static void checkUsernameTokenBSPCompliance( SecurityTokenReference secRef, BSPEnforcer bspEnforcer ) throws WSSecurityException { if (!secRef.containsReference()) { // BSP does not permit using a KeyIdentifier to refer to a U/T bspEnforcer.handleBSPRule(BSPRule.R4215); } if (secRef.getReference() != null) { String valueType = secRef.getReference().getValueType(); if (!WSConstants.WSS_USERNAME_TOKEN_VALUE_TYPE.equals(valueType)) { bspEnforcer.handleBSPRule(BSPRule.R4214); } } }
Element writeSecurityTokenReference( W3CDOMStreamWriter writer, String id, String refValueType ) { Reference ref = new Reference(writer.getDocument()); ref.setURI(id); if (refValueType != null) { ref.setValueType(refValueType); } SecurityTokenReference str = new SecurityTokenReference(writer.getDocument()); str.addWSSENamespace(); str.setReference(ref); writer.getCurrentNode().appendChild(str.getElement()); return str.getElement(); }
return STRParserUtil.getTokenElement(doc, wsDocInfo, null, reference.getURI(), reference.getValueType()); } else if (secRef.containsX509Data() || secRef.containsX509IssuerSerial()) {
private SecurityToken findCancelOrRenewToken(Exchange exchange, Element el) throws WSSecurityException { Element childElement = DOMUtils.getFirstElement(el); String uri = ""; if ("SecurityContextToken".equals(childElement.getLocalName())) { SecurityContextToken sct = new SecurityContextToken(childElement); uri = sct.getIdentifier(); } else { SecurityTokenReference ref = new SecurityTokenReference(childElement, new BSPEnforcer()); uri = ref.getReference().getURI(); } TokenStore store = (TokenStore)exchange.getEndpoint().getEndpointInfo() .getProperty(TokenStore.class.getName()); return store.getToken(uri); }
String valueType = secRef.getReference().getValueType(); if (valueType != null && !"".equals(valueType)) { bspEnforcer.handleBSPRule(BSPRule.R6614);
new org.apache.wss4j.common.token.Reference(doc); ref.setURI("#" + id); if (saml1) { ref.setValueType(WSS4JConstants.WSS_SAML_KI_VALUE_TYPE); secRefSaml.addTokenType(WSS4JConstants.WSS_SAML_TOKEN_TYPE); } else {
Element bstElement = STRParserUtil.getTokenElement(strElement.getOwnerDocument(), wsDocInfo, data.getCallbackHandler(), reference.getURI(), reference.getValueType());
/** * Create a WSDerivedKeyTokenPrincipal from this DerivedKeyToken object */ public Principal createPrincipal() throws WSSecurityException { WSDerivedKeyTokenPrincipal principal = new WSDerivedKeyTokenPrincipal(getID()); principal.setNonce(getNonce()); principal.setLabel(getLabel()); principal.setLength(getLength()); principal.setOffset(getOffset()); principal.setAlgorithm(getAlgorithm()); String basetokenId = null; SecurityTokenReference securityTokenReference = getSecurityTokenReference(); if (securityTokenReference != null && securityTokenReference.getReference() != null) { basetokenId = securityTokenReference.getReference().getURI(); basetokenId = XMLUtils.getIDFromReference(basetokenId); } else if (securityTokenReference != null) { // KeyIdentifier basetokenId = securityTokenReference.getKeyIdentifierValue(); } principal.setBasetokenId(basetokenId); return principal; }
STRParserUtil.getSecretKeyFromToken(uri, reference.getValueType(), WSPasswordCallback.SECRET_KEY, data); if (secretKey == null) { Element token = STRParserUtil.getTokenElement(strElement.getOwnerDocument(), wsDocInfo, data.getCallbackHandler(), uri, reference.getValueType()); QName el = new QName(token.getNamespaceURI(), token.getLocalName()); if (el.equals(WSConstants.BINARY_TOKEN)) {
new org.apache.wss4j.common.token.Reference(doc); ref.setURI("#" + id); if (saml1) { ref.setValueType(WSS4JConstants.WSS_SAML_KI_VALUE_TYPE); secRefSaml.addTokenType(WSS4JConstants.WSS_SAML_TOKEN_TYPE); } else {