All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.edu.icm.unity.saml.idp.DefaultSamlAttributesMapper Maven / Gradle / Ivy

There is a newer version: 4.0.5
Show newest version
/*
 * Copyright (c) 2013 ICM Uniwersytet Warszawski All rights reserved.
 * See LICENCE file for licensing information.
 */
package pl.edu.icm.unity.saml.idp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.xmlbeans.XmlBase64Binary;
import org.apache.xmlbeans.XmlDouble;
import org.apache.xmlbeans.XmlLong;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlString;

import pl.edu.icm.unity.base.attribute.Attribute;
import pl.edu.icm.unity.base.attribute.image.UnityImage;
import pl.edu.icm.unity.base.verifiable.VerifiableEmail;
import pl.edu.icm.unity.stdext.attr.EnumAttributeSyntax;
import pl.edu.icm.unity.stdext.attr.FloatingPointAttributeSyntax;
import pl.edu.icm.unity.stdext.attr.ImageAttributeSyntax;
import pl.edu.icm.unity.stdext.attr.IntegerAttributeSyntax;
import pl.edu.icm.unity.stdext.attr.StringAttributeSyntax;
import pl.edu.icm.unity.stdext.attr.VerifiableEmailAttributeSyntax;
import xmlbeans.org.oasis.saml2.assertion.AttributeType;

/**
 * Default mapper of attributes to/from SAML.
 * 
 * @author K. Benedyczak
 */
public class DefaultSamlAttributesMapper implements SamlAttributeMapper
{
	private static final Map VALUE_TO_SAML = 
			new HashMap();
	
	static {
		ValueToSamlConverter[] converters = new ValueToSamlConverter[] {
				new StringValueToSamlConverter(),
				new EmailValueToSamlConverter(),
				new IntegerValueToSamlConverter(),
				new FloatingValueToSamlConverter(),
				new ImageValueToSamlConverter()
		};

		for (ValueToSamlConverter conv: converters)
		{
			for (String syntax: conv.getSupportedSyntaxes())
				VALUE_TO_SAML.put(syntax, conv);
		}
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isHandled(Attribute unityAttribute)
	{
		String syntax = unityAttribute.getValueSyntax();
		return VALUE_TO_SAML.containsKey(syntax);
	}

	@Override
	public AttributeType convertToSaml(Attribute unityAttribute)
	{
		AttributeType ret = AttributeType.Factory.newInstance();
		ret.setName(unityAttribute.getName());
		String syntax = unityAttribute.getValueSyntax();
		ValueToSamlConverter converter = VALUE_TO_SAML.get(syntax);
		if (converter == null)
		{
			throw new IllegalStateException("There is no attribute type converter for " + syntax);
		}
		List unityValues = unityAttribute.getValues();
		XmlObject[] xmlValues = new XmlObject[unityValues.size()];
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy