-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CXF-8236] add support of signature challenges in the STSClient #651
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,23 @@ | |
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import javax.xml.transform.dom.DOMSource; | ||
|
||
import org.w3c.dom.Element; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.attachment.AttachmentUtil; | ||
import org.apache.cxf.binding.soap.SoapBindingConstants; | ||
import org.apache.cxf.common.logging.LogUtils; | ||
import org.apache.cxf.helpers.DOMUtils; | ||
import org.apache.cxf.interceptor.Fault; | ||
import org.apache.cxf.message.Attachment; | ||
import org.apache.cxf.message.Message; | ||
import org.apache.cxf.phase.PhaseInterceptorChain; | ||
import org.apache.cxf.service.model.BindingOperationInfo; | ||
import org.apache.cxf.staxutils.W3CDOMStreamWriter; | ||
import org.apache.cxf.ws.security.tokenstore.SecurityToken; | ||
import org.apache.cxf.ws.security.trust.AbstractSTSClient.STSResponse; | ||
import org.apache.cxf.ws.security.wss4j.AttachmentCallbackHandler; | ||
import org.apache.wss4j.common.ext.WSSecurityException; | ||
import org.apache.wss4j.common.util.XMLUtils; | ||
|
@@ -87,6 +93,76 @@ public SecurityToken requestSecurityToken( | |
} | ||
return token; | ||
} | ||
|
||
/** | ||
* see WS-Trust 1.4 chapter 8: | ||
* http://docs.oasis-open.org/ws-sx/ws-trust/v1.4/errata01/os/ws-trust-1.4-errata01-os-complete.html#_Toc325658962 | ||
* | ||
* Creating of (manually triggered second) request with a | ||
* RequestSecurityTokenResponse Object | ||
* <wst:RequestSecurityTokenResponse xmlns:wst= | ||
* "http://docs.oasis-open.org/ws-sx/ws-trust/200512" Context= | ||
* "d956dafc-1da5-4661-bab7-834640e659ec"> <wst:SignChallengeResponse> | ||
* <wst:Challenge>4451658898</wst:Challenge> </wst:SignChallengeResponse> | ||
* </wst:RequestSecurityTokenResponse> | ||
* | ||
* @param action | ||
* @param challengeValue the challenge value that was received by first | ||
* issue-response | ||
* @return SecurityToken | ||
* @throws Exception | ||
*/ | ||
public SecurityToken requestSecurityTokenResponse(String action, String challengeValue) throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd prefer to remove this method altogether. Instead, refactor "issue" so that it can work for both cases. The only difference should be "RequestSecurityTokenResponse" instead of "RequestSecurityToken" for the normal issue case. Maybe the writing out of the Challenge itself could be delegated to the Challenge class itself. Then in SecurityToken.requestSecurityToken, I think we could handle the SignChallenge case automatically. If the SecurityToken that is returned from the STS contains a SignChallenge then invoke again on the STS with the challenge. |
||
//mostly copied from issue() and requestSecurityToken() methods => needs bigger refactoring | ||
createClient(); | ||
BindingOperationInfo boi = findOperation("/RSTR/Issue"); | ||
|
||
//we need only /RSTR/Issue | ||
client.getRequestContext().putAll(ctx); | ||
if (action != null) { | ||
client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, action); | ||
// nothing found about this in WS-Trust spec: | ||
// } else if (isSecureConv) { | ||
// client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, | ||
// namespace + "/RST/SCT"); | ||
} else { | ||
client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, | ||
namespace + "/RSTR/Issue"); | ||
} | ||
|
||
//deviation from issue: first element must be RequestSecurityTokenResponse | ||
W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); | ||
writer.writeStartElement("wst", "RequestSecurityTokenResponse", namespace); | ||
writer.writeNamespace("wst", namespace); | ||
if (context != null) { | ||
writer.writeAttribute(null, "Context", context); | ||
} | ||
|
||
writer.writeStartElement("wst", "SignChallengeResponse", namespace); | ||
|
||
writer.writeStartElement("wst", "Challenge", namespace); | ||
writer.writeCharacters(challengeValue); | ||
writer.writeEndElement(); | ||
|
||
writer.writeEndElement(); | ||
writer.writeEndElement(); | ||
|
||
Object[] obj = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement())); | ||
|
||
@SuppressWarnings("unchecked") | ||
Collection<Attachment> attachments = | ||
(Collection<Attachment>)client.getResponseContext().get(Message.ATTACHMENTS); | ||
STSResponse stsResponse = new STSResponse((DOMSource)obj[0], null, null, null, attachments); | ||
|
||
SecurityToken token = | ||
createSecurityToken(getDocumentElement(stsResponse.getResponse()), stsResponse.getEntropy()); | ||
inlineAttachments(token, stsResponse.getAttachments()); | ||
|
||
if (stsResponse.getCert() != null) { | ||
token.setX509Certificate(stsResponse.getCert(), stsResponse.getCrypto()); | ||
} | ||
return token; | ||
} | ||
|
||
public SecurityToken renewSecurityToken(SecurityToken tok) throws Exception { | ||
STSResponse response = renew(tok); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could have a new Challenge class which is referenced in SecurityToken. Challenge could have an enum describing the type, maybe just SIGNATURE for now.