本文整理汇总了Java中org.opensaml.saml2.core.Attribute.setNameFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.setNameFormat方法的具体用法?Java Attribute.setNameFormat怎么用?Java Attribute.setNameFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensaml.saml2.core.Attribute
的用法示例。
在下文中一共展示了Attribute.setNameFormat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processAttribute
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
Attribute attrib = (Attribute) samlObject;
if (attribute.getLocalName().equals(Attribute.NAME_ATTTRIB_NAME)) {
attrib.setName(attribute.getValue());
} else if (attribute.getLocalName().equals(Attribute.NAME_FORMAT_ATTRIB_NAME)) {
attrib.setNameFormat(attribute.getValue());
} else if (attribute.getLocalName().equals(Attribute.FRIENDLY_NAME_ATTRIB_NAME)) {
attrib.setFriendlyName(attribute.getValue());
} else {
QName attribQName = XMLHelper.getNodeQName(attribute);
if (attribute.isId()) {
attrib.getUnknownAttributes().registerID(attribQName);
}
attrib.getUnknownAttributes().put(attribQName, attribute.getValue());
}
}
示例2: createAttributeStatement
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
private static AttributeStatement createAttributeStatement() {
AttributeStatement attributeStatement = create(AttributeStatement.DEFAULT_ELEMENT_NAME);
for (AttributeData attributeData : samlResponseData.getAttributes()) {
Attribute attribute = create(Attribute.DEFAULT_ELEMENT_NAME);
attribute.setFriendlyName(attributeData.getFriendlyName());
attribute.setName(attributeData.getName());
attribute.setNameFormat(attributeData.getNameFormat());
XMLObjectBuilder<XSAny> builder = getXMLObjectBuilder(XSAny.TYPE_NAME);
for (String values : attributeData.getValue().split(";", -1)) {
XSAny value = builder
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
value.setTextContent(values);
attribute.getAttributeValues().add(value);
}
attributeStatement.getAttributes().add(attribute);
}
return attributeStatement;
}
示例3: testTransliteratedAttribute
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
* Test creating and marshalling/unmarshalling an attribute with a name represented in two ways.
*
* @throws Exception
* for errors
*/
@Test
public void testTransliteratedAttribute() throws Exception {
Attribute attribute = OpenSAMLTestBase.createSamlObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME);
attribute.setName(AttributeConstants.EIDAS_CURRENT_FAMILY_NAME_ATTRIBUTE_NAME);
attribute.setNameFormat(Attribute.URI_REFERENCE);
XMLObjectBuilder<CurrentFamilyNameType> builder = OpenSAMLTestBase.getBuilder(CurrentFamilyNameType.TYPE_NAME);
CurrentFamilyNameType name1 = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, CurrentFamilyNameType.TYPE_NAME);
name1.setValue("Onasis");
CurrentFamilyNameType name2 = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, CurrentFamilyNameType.TYPE_NAME);
name2.setValue("Ωνασης");
name2.setLatinScript(false);
attribute.getAttributeValues().add(name1);
attribute.getAttributeValues().add(name2);
Element xml = OpenSAMLTestBase.marshall(attribute);
Attribute attribute2 = OpenSAMLTestBase.unmarshall(xml, Attribute.class);
Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(0)).getValue(), ((CurrentFamilyNameType) attribute2
.getAttributeValues().get(0)).getValue());
Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(1)).getValue(), ((CurrentFamilyNameType) attribute2
.getAttributeValues().get(1)).getValue());
// Unmarshall again, but this time from the XML string ...
String xmlString = XMLHelper.prettyPrintXML(xml);
Attribute attribute3 = (Attribute) OpenSAMLTestBase.unmarshallFromInputStream(Configuration.getParserPool(),
new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(0)).getValue(), ((CurrentFamilyNameType) attribute3
.getAttributeValues().get(0)).getValue());
Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(1)).getValue(), ((CurrentFamilyNameType) attribute3
.getAttributeValues().get(1)).getValue());
}
示例4: testAttributeCreate
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
* Test that creates an attribute and places a CurrentAddessType as a value.
*
* @throws Exception
* for errors
*/
@Test
public void testAttributeCreate() throws Exception {
Attribute attribute = OpenSAMLTestBase.createSamlObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME);
attribute.getNamespaceManager().registerNamespaceDeclaration(new Namespace(EidasConstants.EIDAS_NP_NS, "eidas"));
attribute.setName(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_NAME);
attribute.setFriendlyName(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_FRIENDLY_NAME);
attribute.setNameFormat(Attribute.URI_REFERENCE);
XMLObjectBuilder<CurrentAddressType> builder = OpenSAMLTestBase.getBuilder(CurrentAddressType.TYPE_NAME);
CurrentAddressType address = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME,
new QName(EidasConstants.EIDAS_NP_NS, CurrentAddressType.TYPE_NAME.getLocalPart(), "eidas"));
fill(address);
attribute.getAttributeValues().add(address);
Element attrElement = OpenSAMLTestBase.marshall(attribute);
System.out.println(XMLHelper.prettyPrintXML(attrElement));
// Make sure we inserted the correct namespace prefix while marshalling the CurrentAddressType
Assert.assertTrue((new String(Base64.decode(attrElement.getFirstChild().getFirstChild().getNodeValue()))).startsWith("<eidas:"));
// Unmarshall
Attribute attribute2 = OpenSAMLTestBase.unmarshall(attrElement, Attribute.class);
Assert.assertNotNull(attribute2);
Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_NAME, attribute2.getName());
Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_FRIENDLY_NAME, attribute2.getFriendlyName());
List<XMLObject> values = attribute.getAttributeValues();
Assert.assertTrue(values.size() == 1);
Assert.assertTrue(values.get(0) instanceof CurrentAddressType);
CurrentAddressType address2 = (CurrentAddressType) values.get(0);
verify(address, address2);
}
示例5: createAttribute
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/** QName for the attribute resource */
public static Attribute createAttribute(String name, String friendlyName,
String nameFormat) {
Attribute attribute = new AttributeBuilder().buildObject();
attribute.setName(name);
attribute.setFriendlyName(friendlyName);
attribute.setNameFormat(nameFormat);
return attribute;
}
示例6: testSingleElementOptionalAttributesMarshall
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesMarshall() {
QName qname = new QName(SAMLConstants.SAML20_NS, Attribute.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
Attribute attribute = (Attribute) buildXMLObject(qname);
attribute.setName(expectedName);
attribute.setNameFormat(expectedNameFormat);
attribute.setFriendlyName(expectedFriendlyName);
assertEquals(expectedOptionalAttributesDOM, attribute);
}
示例7: addAttribute
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
public void addAttribute(String name, String format) {
Attribute a = SAMLUtil.buildXMLObject(Attribute.class);
a.setName(name);
a.setNameFormat(format);
request.getAttributes().add(a);
}
示例8: createStatement
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
@Override
public void createStatement(GenericIdentityProviderData ipData, RahasData rahasData)
throws IdentityProviderException {
if (log.isDebugEnabled()) {
log.debug("Begin SAML statement creation.");
}
attributeStmt = (AttributeStatement) buildXMLObject(AttributeStatement.DEFAULT_ELEMENT_NAME);
Map<String, RequestedClaimData> mapClaims = ipData.getRequestedClaims();
if (rahasData.getAppliesToAddress() != null) {
appilesTo = rahasData.getAppliesToAddress();
}
Iterator<RequestedClaimData> ite = mapClaims.values().iterator();
while (ite.hasNext()) {
RequestedClaimData claim = ite.next();
String uri = claim.getUri();
int index = uri.lastIndexOf("/");
String attrName = uri.substring(index + 1, uri.length());
String attrNamespace = uri.substring(0, index);
Attribute attribute = (Attribute) buildXMLObject(Attribute.DEFAULT_ELEMENT_NAME);
attribute.setName(attrName);
attribute.setNameFormat(attrNamespace);
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
// TODO remove this else if condition after WSO2 IS supports claim
// types properly
if (claim.getUri().equals(IdentityConstants.CLAIM_PPID)) {
XSBase64BinaryBuilder ppidValueBuilder = (XSBase64BinaryBuilder) builderFactory
.getBuilder(XSBase64Binary.TYPE_NAME);
XSBase64Binary ppidValue = ppidValueBuilder.buildObject(
AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME);
ppidValue.setValue(claim.getValue());
attribute.getAttributeValues().add(ppidValue);
} else {
XSStringBuilder attributeValueBuilder = (XSStringBuilder) builderFactory
.getBuilder(XSString.TYPE_NAME);
XSString stringValue = attributeValueBuilder.buildObject(
AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
stringValue.setValue(claim.getValue());
attribute.getAttributeValues().add(stringValue);
}
attributeStmt.getAttributes().add(attribute);
}
}
示例9: buildAttributeStatement
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
private AttributeStatement buildAttributeStatement(Map<String, String> claims) {
String claimSeparator = claims.get(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
if (StringUtils.isNotBlank(claimSeparator)) {
userAttributeSeparator = claimSeparator;
}
claims.remove(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR);
AttributeStatement attStmt = new AttributeStatementBuilder().buildObject();
Iterator<Map.Entry<String, String>> iterator = claims.entrySet().iterator();
boolean atLeastOneNotEmpty = false;
for (int i = 0; i < claims.size(); i++) {
Map.Entry<String, String> claimEntry = iterator.next();
String claimUri = claimEntry.getKey();
String claimValue = claimEntry.getValue();
if (claimUri != null && !claimUri.trim().isEmpty() && claimValue != null && !claimValue.trim().isEmpty()) {
atLeastOneNotEmpty = true;
Attribute attribute = new AttributeBuilder().buildObject();
attribute.setName(claimUri);
//setting NAMEFORMAT attribute value to basic attribute profile
attribute.setNameFormat(SAMLSSOConstants.NAME_FORMAT_BASIC);
// look
// https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes
XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory().
getBuilder(XSString.TYPE_NAME);
XSString stringValue;
//Need to check if the claim has multiple values
if (userAttributeSeparator != null && claimValue.contains(userAttributeSeparator)) {
StringTokenizer st = new StringTokenizer(claimValue, userAttributeSeparator);
while (st.hasMoreElements()) {
String attValue = st.nextElement().toString();
if (attValue != null && attValue.trim().length() > 0) {
stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
stringValue.setValue(attValue);
attribute.getAttributeValues().add(stringValue);
}
}
} else {
stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
stringValue.setValue(claimValue);
attribute.getAttributeValues().add(stringValue);
}
attStmt.getAttributes().add(attribute);
}
}
if (atLeastOneNotEmpty) {
return attStmt;
} else {
return null;
}
}
示例10: createAttribute
import org.opensaml.saml2.core.Attribute; //导入方法依赖的package包/类
/**
* Utility method that creates an {@code Attribute} given its name, friendly name and name format.
*
* @param name
* the attribute name
* @param friendlyName
* the attribute friendly name (may be {@code null})
* @param nameFormat
* the name format
* @return an {@code Attribute} object
*/
public static Attribute createAttribute(String name, String friendlyName, String nameFormat) {
Attribute attribute = attributeBuilder.buildObject();
attribute.setName(name);
attribute.setFriendlyName(friendlyName);
attribute.setNameFormat(nameFormat);
return attribute;
}