Skip to Content.
Sympa Menu

mace-opensaml-users - Re: SAML 2.0 metadata

Subject: OpenSAML user discussion

List archive

Re: SAML 2.0 metadata


Chronological Thread 
  • From: Chad La Joie <>
  • To:
  • Subject: Re: SAML 2.0 metadata
  • Date: Tue, 16 May 2006 08:45:19 -0400

Works fine for me. Here's what I did. I took your xml snippet and added a namespace declaration for "saml" (so that it's valid XML), then unmarshalled it with the attached unit test. Here's the output I got.

Attribute Name: eduPersonAffiliation
AttributeValue class type: org.opensaml.xml.ElementProxy
AttributeValue value: member
AttributeValue class type: org.opensaml.xml.ElementProxy
AttributeValue value: student
AttributeValue class type: org.opensaml.xml.ElementProxy
AttributeValue value: faculty
AttributeValue class type: org.opensaml.xml.ElementProxy
AttributeValue value: employee
AttributeValue class type: org.opensaml.xml.ElementProxy
AttributeValue value: staff

Manuela Stanica wrote:
Hi Chad,
Given the error you've encountered I'd guess that the attribute value you're trying to read does not have a schema instance type attribute and that AttributeValue isn't registered or is specifically registered to use the ElementProxy element.

The metadata document example that I'm using for testing is taken out of the OASIS specification for SAML 2 metadata, here is the concerned section:
<saml:Attribute
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.1"
FriendlyName="eduPersonAffiliation">
<saml:AttributeValue>member</saml:AttributeValue>
<saml:AttributeValue>student</saml:AttributeValue>
<saml:AttributeValue>faculty</saml:AttributeValue>
<saml:AttributeValue>employee</saml:AttributeValue>
<saml:AttributeValue>staff</saml:AttributeValue>
</saml:Attribute>

Could you please give me a hint on how to read these values?

Thanks,
Manuela



Manuela Stanica wrote:
Hi,

I noticed that the openSAML2 and XMLTooling code compiles again, great!
I still have a question though concerning AttributeValues. I haven't found out yet how I can read the value of an <AttributeValue>. It looks like there have been some changes made around this, are they documented somewhere? I've looked into the code and found an example of how I could read this value and tried to do the same in my code, but it doesn't seem to work.
I have something like:
List<XMLObject> attrValList = idpDescr.getAttributes().get(i).getAttributeValues();
for(int n=0; n<attrValList.size(); n++){
XSString value = (XSString) attrValList.get(n);
String val = value.getValue();
.............................
}
Here I get a java.lang.ClassCastException: org.opensaml.xml.ElementProxy when trying to do the casting to XSString.
So how can I get to my AttributeValues..?

Cheers,
Manuela






--
Chad La Joie 2052-C Harris Bldg
OIS-Middleware 202.687.0124
/*
* Copyright [2006] [University Corporation for Advanced Internet
Development, Inc.]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opensaml.saml2.core.impl;

import java.io.InputStream;
import java.util.List;

import org.opensaml.common.SAMLObjectTestCaseConfigInitializer;
import org.opensaml.common.xml.ParserPoolManager;
import org.opensaml.saml2.core.Attribute;
import org.opensaml.xml.Configuration;
import org.opensaml.xml.ElementProxy;
import org.opensaml.xml.XMLObject;
import org.opensaml.xml.io.Unmarshaller;
import org.opensaml.xml.io.UnmarshallingException;
import org.w3c.dom.Document;

public class AttributeValueTest extends SAMLObjectTestCaseConfigInitializer {

private String dataFile =
"/data/org/opensaml/saml2/core/impl/AttributeValue.xml";

private Document samlDom;

protected void setUp() throws Exception {
super.setUp();

ParserPoolManager ppMgr = ParserPoolManager.getInstance();

InputStream dataIn =
AttributeValueTest.class.getResourceAsStream(dataFile);
samlDom = ppMgr.parse(dataIn);
}

public void testUnmarshall(){
//Get the unmarshaller for the document root element, Attribute
Unmarshaller unmarshaller =
Configuration.getUnmarshallerFactory().getUnmarshaller(samlDom.getDocumentElement());

try {
Attribute attribute = (Attribute)
unmarshaller.unmarshall(samlDom.getDocumentElement());
System.out.println("Attribute Name: " +
attribute.getFriendlyName());

List<XMLObject> attributeValues = attribute.getAttributeValues();
for(XMLObject attributeValue : attributeValues){
System.out.println("AttributeValue class type: " +
attributeValue.getClass().getName());
System.out.println("AttributeValue value: " +
((ElementProxy)attributeValue).getTextContent());
}
} catch (UnmarshallingException e) {
fail("Unable to unmarshall document: " + e);
e.printStackTrace();
}
}
}


Archive powered by MHonArc 2.6.16.

Top of Page