<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I would like to use OpenSAML to create a WSFed Response. Currently I am unable to create the AppliesTo Object which is part of the RequestSecurityTokenResponse.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Error:<br>
ClassCastException: class org.opensaml.soap.wspolicy.impl.AppliesToImpl cannot be cast to class org.opensaml.soap.wsfed.AppliesTo</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I use this method to create OpenSAML objects:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<blockquote style="border-color: rgb(200, 200, 200); border-left: 3px solid rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);">
<span>    public static <T> T buildSAMLObject(final Class<T> clazz) {<br>
</span>
<div>        QName defaultElementName;<br>
</div>
<div>        try {<br>
</div>
<div>            defaultElementName = (QName) clazz.getDeclaredField("DEFAULT_ELEMENT_NAME").get(null);<br>
</div>
<div>        } catch (IllegalAccessException | NoSuchFieldException ex) {<br>
</div>
<div>            throw new IllegalArgumentException("Could not create SAML object", ex);<br>
</div>
<div>        }<br>
</div>
<div><br>
</div>
<div>        XMLObjectBuilderFactory factory = XMLObjectProviderRegistrySupport.getBuilderFactory();<br>
</div>
<div>        if (factory == null) {<br>
</div>
<div>            throw new RuntimeException("Unable to get builderFactory.");<br>
</div>
<div>        }<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>        XMLObjectBuilder<?> builder = factory.getBuilder(defaultElementName);<br>
</div>
<div>        if (builder == null) {<br>
</div>
<div>            throw new RuntimeException("Unable to get builder.");<br>
</div>
<div>        }<br>
</div>
<div><br>
</div>
<div>        return (T) builder.buildObject(defaultElementName);<br>
</div>
<div><span>    }</span><br>
</div>
</blockquote>
<div><br>
</div>
<div>I think the problem is that the AppliesTo from wspolicy and wsfed have the same name.</div>
<div><br>
</div>
<div>Is this in general the right way to create this objects?</div>
<div><br>
</div>
<div>Thanks i advance.<br>
</div>
</div>
</body>
</html>