Add a way to the STSClient to send custom content in the RST
@@ -166,6 +166,7 @@ public abstract class AbstractSTSClient implements Configurable, InterceptorProv
protected int keySize = 256;
protected boolean requiresEntropy = true;
protected Element template;
+ protected Object customContent;
protected Object claims;
protected CallbackHandler claimsCallbackHandler;
protected AlgorithmSuite algorithmSuite;
@@ -395,6 +396,10 @@ public abstract class AbstractSTSClient implements Configurable, InterceptorProv
this.actAs = actAs;
}
+ public void setCustomContent(Object customContent) {
+ this.customContent = customContent;
+ }
+
public void setKeySize(int i) {
keySize = i;
}
@@ -846,6 +851,11 @@ public abstract class AbstractSTSClient implements Configurable, InterceptorProv
// Write out renewal semantics
writeRenewalSemantics(writer);
+ Element customElement = getCustomContent();
+ if (customElement != null) {
+ StaxUtils.copy(customElement, writer);
+ }
+
writer.writeEndElement();
Object obj[] = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
@@ -867,25 +877,42 @@ public abstract class AbstractSTSClient implements Configurable, InterceptorProv
return getDelegationSecurityToken(this.actAs);
}
+ /**
+ * Get some custom Element to be inserted into the RequestSecurityToken
+ */
+ public Element getCustomContent() throws Exception {
+ if (customContent != null) {
+ // We can also support a CallbackHandler her as per getDelegationSecurityToken if required
+ final boolean isString = customContent instanceof String;
+ final boolean isElement = customContent instanceof Element;
+ if (isString) {
+ final Document doc =
+ StaxUtils.read(new StringReader((String) customContent));
+ return doc.getDocumentElement();
+ } else if (isElement) {
+ return (Element) customContent;
+ }
+ }
+ return null;
+ }
+
protected Element getDelegationSecurityToken(Object delegationObject) throws Exception {
if (delegationObject != null) {
final boolean isString = delegationObject instanceof String;
final boolean isElement = delegationObject instanceof Element;
final boolean isCallbackHandler = delegationObject instanceof CallbackHandler;
- if (isString || isElement || isCallbackHandler) {
if (isString) {
final Document doc =
StaxUtils.read(new StringReader((String) delegationObject));
return doc.getDocumentElement();
} else if (isElement) {
return (Element) delegationObject;
- } else {
+ } else if (isCallbackHandler) {
DelegationCallback callback = new DelegationCallback(message);
((CallbackHandler)delegationObject).handle(new Callback[]{callback});
return callback.getToken();
}
}
- }
return null;
}
