/** * Create a wsse:Reference element with the given URI and the value type * * @param doc * @param refUri * @param refValueType * @return Element */ public static Element createSecurityTokenReference(Document doc, String refUri, String refValueType) { Reference ref = new Reference(doc); ref.setURI(refUri); if (refValueType != null) { ref.setValueType(refValueType); } SecurityTokenReference str = new SecurityTokenReference(doc); str.setReference(ref); 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.INVALID_SECURITY, "noReference"); } element = elem; QName el = new QName(element.getNamespaceURI(), element.getLocalName()); if (!el.equals(TOKEN)) { throw new WSSecurityException( WSSecurityException.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.INVALID_SECURITY, "badReferenceURI" ); } }
/** * Check that the Username token referenced by the SecurityTokenReference argument * is BSP compliant. * @param secRef The SecurityTokenReference to the Username token * @throws WSSecurityException */ public static void checkUsernameTokenBSPCompliance( SecurityTokenReference secRef ) throws WSSecurityException { if (!secRef.containsReference()) { // BSP does not permit using a KeyIdentifier to refer to a U/T throw new WSSecurityException( WSSecurityException.FAILED_CHECK, "unsupportedKeyId" ); } String valueType = secRef.getReference().getValueType(); if (!WSConstants.WSS_USERNAME_TOKEN_VALUE_TYPE.equals(valueType)) { // BSP says the Reference must have a ValueType of UsernameToken throw new WSSecurityException( WSSecurityException.INVALID_SECURITY, "invalidValueType", new Object[]{valueType} ); } }
/** * Constructor. * * @param elem A SecurityTokenReference element * @param bspCompliant whether the SecurityTokenReference processing complies with the * BSP spec * @throws WSSecurityException */ public SecurityTokenReference(Element elem, boolean bspCompliant) throws WSSecurityException { element = elem; QName el = new QName(element.getNamespaceURI(), element.getLocalName()); if (!STR_QNAME.equals(el)) { throw new WSSecurityException(WSSecurityException.FAILURE, "badElement", new Object[] {STR_QNAME, el}); } if (bspCompliant) { checkBSPCompliance(); } if (containsReference()) { Node node = element.getFirstChild(); while (node != null) { if (Node.ELEMENT_NODE == node.getNodeType() && WSConstants.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; }
if (!getReference().equals(tokenReference.getReference())) { return false;
Reference reference = getReference(); if (reference != null) { result = 31 * result + reference.hashCode();
/** * Constructor. * * @param elem The Reference element * @throws WSSecurityException */ public Reference(Element elem) throws WSSecurityException { if (elem == null) { throw new WSSecurityException(WSSecurityException.INVALID_SECURITY, "noReference"); } element = elem; QName el = new QName(element.getNamespaceURI(), element.getLocalName()); if (!el.equals(TOKEN)) { throw new WSSecurityException( WSSecurityException.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.INVALID_SECURITY, "badReferenceURI" ); } }
/** * Check that the Username token referenced by the SecurityTokenReference argument * is BSP compliant. * @param secRef The SecurityTokenReference to the Username token * @throws WSSecurityException */ public static void checkUsernameTokenBSPCompliance( SecurityTokenReference secRef ) throws WSSecurityException { if (!secRef.containsReference()) { // BSP does not permit using a KeyIdentifier to refer to a U/T throw new WSSecurityException( WSSecurityException.FAILED_CHECK, "unsupportedKeyId" ); } String valueType = secRef.getReference().getValueType(); if (!WSConstants.WSS_USERNAME_TOKEN_VALUE_TYPE.equals(valueType)) { // BSP says the Reference must have a ValueType of UsernameToken throw new WSSecurityException( WSSecurityException.INVALID_SECURITY, "invalidValueType", new Object[]{valueType} ); } }
/** * Constructor. * * @param elem A SecurityTokenReference element * @param bspCompliant whether the SecurityTokenReference processing complies with the * BSP spec * @throws WSSecurityException */ public SecurityTokenReference(Element elem, boolean bspCompliant) throws WSSecurityException { element = elem; QName el = new QName(element.getNamespaceURI(), element.getLocalName()); if (!STR_QNAME.equals(el)) { throw new WSSecurityException(WSSecurityException.FAILURE, "badElement", new Object[] {STR_QNAME, el}); } if (bspCompliant) { checkBSPCompliance(); } if (containsReference()) { Node node = element.getFirstChild(); while (node != null) { if (Node.ELEMENT_NODE == node.getNodeType() && WSConstants.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; }
if (!getReference().equals(tokenReference.getReference())) { return false;
Reference reference = getReference(); if (reference != null) { result = 31 * result + reference.hashCode();
/** * Create a KeyInfo object * @throws ConversationException */ private KeyInfo createKeyInfo() throws WSSecurityException, ConversationException { KeyInfo keyInfo = new KeyInfo(document); SecurityTokenReference secToken = new SecurityTokenReference(document); secToken.addWSSENamespace(); Reference ref = new Reference(document); ref.setURI("#" + dktId); String ns = ConversationConstants.getWSCNs(getWscVersion()) + ConversationConstants.TOKEN_TYPE_DERIVED_KEY_TOKEN; ref.setValueType(ns); secToken.setReference(ref); keyInfo.addUnknownElement(secToken.getElement()); Element keyInfoElement = keyInfo.getElement(); keyInfoElement.setAttributeNS( WSConstants.XMLNS_NS, "xmlns:" + WSConstants.SIG_PREFIX, WSConstants.SIG_NS ); return keyInfo; }
@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; }
private void processValidateTarget()throws TrustException{ OMElement validateTargetElem = this.rstElement .getFirstChildWithName(new QName(this.wstNs, RahasConstants.LocalNames.VALIDATE_TARGET)); if (validateTargetElem != null) { OMElement strElem = validateTargetElem.getFirstChildWithName(new QName(WSConstants.WSSE_NS, "SecurityTokenReference")); Element elem = (Element)OMXMLBuilderFactory.createStAXOMBuilder( OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory(), strElem.getXMLStreamReader()).getDocumentElement(); try { SecurityTokenReference str = new SecurityTokenReference((Element)elem); if (str.containsReference()) { tokenId = str.getReference().getURI(); } else if(str.containsKeyIdentifier()){ tokenId = str.getKeyIdentifierValue(); } } catch (WSSecurityException e) { throw new TrustException("errorExtractingTokenId",e); } } }
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))