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

pl.edu.icm.unity.oauth.as.DefaultOAuthAttributeMapper Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2014 ICM Uniwersytet Warszawski All rights reserved.
 * See LICENCE.txt file for licensing information.
 */
package pl.edu.icm.unity.oauth.as;

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

import com.nimbusds.jose.util.Base64;

import net.minidev.json.JSONArray;
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.BooleanAttributeSyntax;
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;

/**
 * Default OAuth attribute mapper, maps string, string arrays, numbers, enums and images.
 * 
 * @author K. Benedyczak
 */
public class DefaultOAuthAttributeMapper implements OAuthAttributeMapper
{
	private static final Map VALUE_TO_OAUTH = 
			new HashMap();
	
	static 
	{
		ValueToJsonConverter[] converters = new ValueToJsonConverter[] {
				new SimpleValueConverter(),
				new EmailValueConverter(),
				new ImageValueConverter(),
				new BooleanValueConverter()
		};

		for (ValueToJsonConverter conv: converters)
		{
			for (String syntax: conv.getSupportedSyntaxes())
				VALUE_TO_OAUTH.put(syntax, conv);
		}
	}

	
	@Override
	public boolean isHandled(Attribute unityAttribute)
	{
		String syntax = unityAttribute.getValueSyntax();
		return VALUE_TO_OAUTH.containsKey(syntax);
	}


	@Override
	public Object getJsonValue(Attribute unityAttribute)
	{
		int valsNum = unityAttribute.getValues().size(); 
		String syntax = unityAttribute.getValueSyntax();
		ValueToJsonConverter converter = VALUE_TO_OAUTH.get(syntax);
		
		if (valsNum > 1)
		{
			JSONArray array = new JSONArray();
			for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy