I have recently written a SAML extension using opensaml. It works nice
and fine. However recently I realized extension that it creates has
md:Extensions not saml2P:Extensions.
I thought default buildObject method ExtensionBuilder is creating
md:Extensions.
I did following:
1)
ExtensionsBuilder extBuilder = new ExtensionsBuilder();
Extensions extensions =
extBuilder.buildObject(SAMLConstants.SAML20_NS, Extensions.LOCAL_NAME,
SAMLConstants.SAML20_PREFIX);
It builds the object but when marshaling it it gives:
java.lang.ClassCastException:
org.opensaml.saml2.common.impl.ExtensionsImpl cannot be cast to
org.opensaml.xml.schema.XSAny
I see my self registering all custom object using
org.opensaml.DefaultBootstrap.bootstrap()
Configuration.registerObjectProvider(.........)
Just to try my another way:
2)
But it does not build extBuilder.
QName extQName = new QName(SAMLConstants.SAML20_NS,
Extensions.LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
ExtensionsBuilder extBuilder =
(ExtensionsBuilder)builderFactory.getBuilder(extQName);
Extensions extensions =
extBuilder.buildObject(SAMLConstants.SAML20_NS, Extensions.LOCAL_NAME,
SAMLConstants.SAML20_PREFIX);
I believe i am missing something based on the fact that everything
runs when I just use default (i.e md:Extension).
Any insight will be highly appreciated.
Thank you.
rn
Then you're probably using the wrong Extensions classes, I'm sure there
are parallel objects in the other package.
-- Scott
I like to differ with you.
I am using,
import org.opensaml.saml2.common.Extensions;
import org.opensaml.saml2.common.impl.ExtensionsBuilder;
ExtensionBuilder looks like following. Thus creating md:Extensions is
obvious if I use default buildObject() method.
I hope I am not missing something that you are pointing at. If yes,
please guide me.
Thank you.
rn
public class ExtensionsBuilder extends AbstractSAMLObjectBuilder<Extensions> {
/**
* {@inheritDoc}
*/
public Extensions buildObject() {
return buildObject(SAMLConstants.SAML20MD_NS,
Extensions.LOCAL_NAME, SAMLConstants.SAML20MD_PREFIX);
}
/**
* {@inheritDoc}
*/
public Extensions buildObject(String namespaceURI, String
localName, String namespacePrefix) {
return new ExtensionsImpl(namespaceURI, localName, namespacePrefix);
If there's not a separate one in the metadata package, then perhaps
there's a bug.
>I hope I am not missing something that you are pointing at. If yes,
>please guide me.
I don't use the Java code, I was just making a possible suggestion.
-- Scott
[rn@smallmouth ]$ locate ExtensionsBuilder.java
/java-opensaml2-main/java-opensaml2/src/main/java/org/opensaml/saml2/common/impl/ExtensionsBuilder.java
I am not sure if there is different name of the class in Metadata
package structure. On a positive note, since Metadata also has
extension, it may be a shared code.
However still puzzling to me is why I am getting exception when I put
proper prefix,localname..etc as described in my first post.
Thank you.
rn.
On 5/19/11 7:52 AM, rangeli nepal wrote:
> Good Morning Everybody,
>
> Extensions extensions =
> extBuilder.buildObject(SAMLConstants.SAML20_NS, Extensions.LOCAL_NAME,
> SAMLConstants.SAML20_PREFIX);
>
> It builds the object but when marshaling it it gives:
>
> java.lang.ClassCastException:
> org.opensaml.saml2.common.impl.ExtensionsImpl cannot be cast to
> org.opensaml.xml.schema.XSAny
>
Yeah, your problem above is just a typo, the Extensions element is in
the protocols namespace, not the assertion namespace, so you are missing
the "P" in the constant names above, e.g. SAML20P_NS.
It's failing to find a provider with the requested non-existant QName,
so it's returning to you the default XSAny impl, and naturally you can't
cast that to an Extensions object.
This works correctly, for example.
QName name = new QName(SAMLConstants.SAML20P_NS, Extensions.LOCAL_NAME,
SAMLConstants.SAML20P_PREFIX);
Extensions ext = (Extensions)
Configuration.getBuilderFactory().getBuilder(name).buildObject(name);
On 5/19/11 10:20 AM, Cantor, Scott E. wrote:
>
>
> Then you're probably using the wrong Extensions classes, I'm sure there
> are parallel objects in the other package.
Actually there isn't. For reasons obscured by history, whoever
implemented that originally chose to have just a common Extensions
provider, which is used for both the metadata and protocols Extensions
elements (other than the namespace, they have the same schema). I
personally wouldn't have chosen to do it that way b/c I think it's
confusing, but that's the way it is.
On 5/19/11 10:54 AM, rangeli nepal wrote:
> Good Morning Scott,
>
> I like to differ with you.
>
> I am using,
>
> import org.opensaml.saml2.common.Extensions;
> import org.opensaml.saml2.common.impl.ExtensionsBuilder;
>
>
> ExtensionBuilder looks like following. Thus creating md:Extensions is
> obvious if I use default buildObject() method.
Even though it's supposed to be a "common" class, it has a buildObject()
that defaults to building the metadata one. That probably increases the
confusion. If this had come up a few days earlier, I probably would
have just gone in and fixed all this up. But since the just-released
2.5.0 is likely to be the last release of 2.x, there's probably not much
point. We should fix for 3.x, I think.