pl.edu.icm.unity.oauth.as.DefaultOAuthAttributeMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unity-server-oauth Show documentation
Show all versions of unity-server-oauth Show documentation
Client and server OAuth support
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