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

io.imunity.scim.user.mapping.evaluation.DataArrayResolver Maven / Gradle / Ivy

There is a newer version: 4.0.3
Show newest version
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package io.imunity.scim.user.mapping.evaluation;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import io.imunity.scim.config.DataArray;
import pl.edu.icm.unity.base.attribute.AttributeExt;
import pl.edu.icm.unity.base.attribute.IllegalAttributeValueException;
import pl.edu.icm.unity.engine.api.AttributeValueConverter;

@Component
class DataArrayResolver
{
	private final AttributeValueConverter attrValueConverter;

	@Autowired
	DataArrayResolver(AttributeValueConverter attrValueConverter)
	{
		this.attrValueConverter = attrValueConverter;
	}

	List resolve(DataArray dataArray, EvaluatorContext context) throws IllegalAttributeValueException
	{
		if (dataArray == null || dataArray.type == null)
		{
			return Collections.emptyList();
		}

		switch (dataArray.type)
		{
		case ATTRIBUTE:
			Optional attribute = context.user.attributes.stream()
					.filter(a -> a.getName().equals(dataArray.value.get())).findAny();
			if (attribute.isEmpty())
				return Collections.emptyList();
			return attrValueConverter.internalValuesToObjectValues(attribute.get().getName(),
					attribute.get().getValues());

		case IDENTITY:
			return context.user.identities.stream().filter(a -> a.getTypeId().equals(dataArray.value.get()))
					.map(i -> i.getValue()).collect(Collectors.toList());

		case MEMBERSHIP:
			return context.user.groups.stream().map(g -> context.groupProvider.get(g.getPathEncoded()))
					.collect(Collectors.toList());

		default:

			return Collections.emptyList();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy