/** * find the first ws-security header block <p/> * * @param doc the DOM document (SOAP request) * @param envelope the SOAP envelope * @param doCreate if true create a new WSS header block if none exists * @return the WSS header or null if none found and doCreate is false */ public static Element findWsseSecurityHeaderBlock( Document doc, Element envelope, boolean doCreate ) throws WSSecurityException { return findWsseSecurityHeaderBlock(doc, envelope, null, doCreate); }
public void removeSecurityHeader() throws WSSecurityException { if (securityHeader == null) { if (doc == null) { throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty", new Object[] {"The Document of WSSecHeader is null"}); } securityHeader = WSSecurityUtil.findWsseSecurityHeaderBlock( doc, doc.getDocumentElement(), actor, false ); } if (securityHeader != null) { Node parent = securityHeader.getParentNode(); parent.removeChild(securityHeader); } }
/** * Gets the DOM representation of <code>wsse:Security</code> element that is the WS-Security header target to the * specified role/actor. * * @param target The target of the security header which element should be retrieved * @param envelope The DOM representation of the SOAP envelope * @return The WS-Security element of the security header targeted to specified role/actor if contained * in the message,<br><code>null</code> otherwise */ public static Element getSecurityHeaderElement(final SecurityHeaderTarget target, final Document envelope) { Element wsSecHeader; try { wsSecHeader = WSSecurityUtil.findWsseSecurityHeaderBlock(envelope, envelope.getDocumentElement(), target.id(), false); } catch (WSSecurityException wse) { // Header block is not found wsSecHeader = null; } return wsSecHeader; }
/** * Returns whether the security header is empty * * @return true if empty or if there is no security header * false if non empty security header */ public boolean isEmpty() throws WSSecurityException { if (doc == null) { throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty", new Object[] {"The Document of WSSecHeader is null"}); } if (securityHeader == null) { securityHeader = WSSecurityUtil.findWsseSecurityHeaderBlock( doc, doc.getDocumentElement(), actor, false ); } if (securityHeader == null || securityHeader.getFirstChild() == null) { return true; } return false; }
WSSecurityUtil.findWsseSecurityHeaderBlock( doc, doc.getDocumentElement(), actor, true );