}
if (refList.getPendingReferenceList().isEmpty()) {
pendingElement = null;
} else {
String uri = refList.getPendingReferenceList().get(0);
throw new XWSSecurityException("Reference with ID " + uri + " was not found in the message");
}
}
} catch (XMLStreamException e) {
// TODO need to throw more meaningful exception
throw new WebServiceException(e);
} catch (XWSSecurityException xse) {
throw new WebServiceException(xse);
}
}
ArrayList clonedBufferedHeaders = (ArrayList) bufferedHeaders.clone();
if (clonedBufferedHeaders.size() > 0) {
for (int i = 0; i < clonedBufferedHeaders.size(); i++) {
SecurityHeaderElement she = (SecurityHeaderElement) clonedBufferedHeaders.get(i);
processSecurityHeader(she);
}
}
if (processedHeaders.size() > 0) {
for (int i = 0; i < processedHeaders.size(); i++) {
SecurityHeaderElement she = (SecurityHeaderElement) processedHeaders.get(i);
processProcessedHeaders(she);
}
}
try {
if (message == null) {
message = getEmptyBody();
}
} catch (XMLStreamException xse) {
throw new XWSSecurityException(xse);
}
Message streamMsg = null;
AttachmentSet as = securityContext.getDecryptedAttachmentSet();
if (as == null || as.isEmpty()) {
as = securityContext.getAttachmentSet();
}
if (!context.getDisablePayloadBuffering() && (!context.isSecure() || "Fault".equals(message.getLocalName()))) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Buffering Payload from incomming message");
}
VerifiedMessageXMLStreamReader verifiedReader = new VerifiedMessageXMLStreamReader(message, bodyENVNS);
streamMsg = new VerifiedStreamMessage(envelopeTag, headerTag, as, headers, bodyTag, verifiedReader, soapVersion, this.bodyENVNS);
} else {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Not Buffering Payload from incomming message");
}
// FIXME: RJE -- remove cast once StreamMessage constr can take MessageHeaders
streamMsg = new StreamMessage(envelopeTag, headerTag, as, (HeaderList) headers, bodyTag, message, soapVersion);
}
context.setMessage(streamMsg);
boolean scCancel = false;
/*if(streamMsg.isFault())
return streamMsg;*/
if (context.getAddressingVersion() != null) {
String action = AddressingUtils.getAction(streamMsg.getHeaders(), context.getAddressingVersion(), context.getSOAPVersion());
if (MessageConstants.MEX_GET.equals(action)) {
return streamMsg;
}
if (MessageConstants.CANCEL_SECURITY_CONTEXT_TOKEN_ACTION.equals(action) ||
MessageConstants.CANCEL_SECURITY_CONTEXT_TOKEN_RESPONSE_ACTION.equals(action)) {
scCancel = true;
}
}
SecurityPolicy msgPolicy = context.getSecurityPolicy();
//boolean isTrust = context.isTrustMessage();
if (PolicyUtils.isEmpty(msgPolicy)) {
PolicyResolver opResolver =
(PolicyResolver) context.getExtraneousProperty(context.OPERATION_RESOLVER);
if (opResolver != null) {
msgPolicy = opResolver.resolvePolicy(context);
}
}
if (context.isSecure() && context.getInferredSecurityPolicy().isEmpty()) {
if (PolicyUtils.isEmpty(msgPolicy) || context.isMissingTimestampAllowed()) {
return streamMsg;
} else {
throw new XWSSecurityException("Security Requirements not met - No Security header in message");
}
}
// for policy verification, replace target uris with qnames for signature and encryption targets
try {
MessagePolicy inferredMessagePolicy = context.getInferredSecurityPolicy();
for (int i = 0; i < inferredMessagePolicy.size(); i++) {
WSSPolicy wssPolicy = (WSSPolicy) inferredMessagePolicy.get(i);
if (PolicyTypeUtil.signaturePolicy(wssPolicy)) {
SignaturePolicy.FeatureBinding fb = (SignaturePolicy.FeatureBinding) wssPolicy.getFeatureBinding();
ArrayList targets = fb.getTargetBindings();
// replace uri target types with qname target types
modifyTargets(targets);
} else if (PolicyTypeUtil.encryptionPolicy(wssPolicy)) {
EncryptionPolicy.FeatureBinding fb = (EncryptionPolicy.FeatureBinding) wssPolicy.getFeatureBinding();
ArrayList targets = fb.getTargetBindings();
// replace uri target types with qname target types
modifyTargets(targets);
}
}
} catch (Exception ex) {
throw new XWSSecurityException(ex);
}
if (scCancel) {
boolean securedBody = false;
boolean allHeaders = false;
try {
MessagePolicy mp = context.getInferredSecurityPolicy();
for (int i = 0; i < mp.size(); i++) {
WSSPolicy wp = (WSSPolicy) mp.get(i);
if (PolicyTypeUtil.encryptionPolicy(wp)) {
EncryptionPolicy ep = (EncryptionPolicy) wp;
ArrayList list = ((EncryptionPolicy.FeatureBinding) ep.getFeatureBinding()).getTargetBindings();
for (int ei = 0; ei < list.size(); ei++) {
EncryptionTarget et = (EncryptionTarget) list.get(ei);
if (et.getValue().equals(Target.BODY)) {
securedBody = true;
}
}
} else if (PolicyTypeUtil.signaturePolicy(wp)) {
SignaturePolicy sp = (SignaturePolicy) wp;
ArrayList list = ((SignaturePolicy.FeatureBinding) sp.getFeatureBinding()).getTargetBindings();
for (int ei = 0; ei < list.size(); ei++) {
SignatureTarget st = (SignatureTarget) list.get(ei);
//if(st.getValue() == Target.BODY){
if (st.getValue().equals(Target.BODY)) {
securedBody = true;
}
}
if (!allHeaders) {
allHeaders = areHeadersSecured(sp);
}
}
}
} catch (Exception ex) {
throw new XWSSecurityException(ex);
}
if (!context.isSecure() && (!securedBody || !allHeaders)) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1602_SCCANCEL_SECURITY_UNCONFIGURED());
throw new XWSSecurityException("Security Requirements not met");
}
return streamMsg;
}
if (context.getInferredSecurityPolicy() == null || context.getInferredSecurityPolicy().isEmpty()) {