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

io.imunity.console.views.signup_and_enquiry.RemoteAuthnProvidersMultiSelection 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.console.views.signup_and_enquiry;

import com.vaadin.flow.component.combobox.MultiSelectComboBox;
import com.vaadin.flow.component.combobox.dataview.ComboBoxListDataView;
import io.imunity.vaadin.auth.VaadinAuthentication;
import pl.edu.icm.unity.base.authn.AuthenticationOptionsSelector;
import pl.edu.icm.unity.base.exceptions.EngineException;
import pl.edu.icm.unity.base.message.MessageSource;
import pl.edu.icm.unity.engine.api.authn.AuthenticatorInstance;
import pl.edu.icm.unity.engine.api.authn.AuthenticatorSupportService;

import java.util.*;


public class RemoteAuthnProvidersMultiSelection extends MultiSelectComboBox
{
	private final MessageSource msg;
	private List selectors;

	public RemoteAuthnProvidersMultiSelection(MessageSource msg, AuthenticatorSupportService authenticatorSupport) throws EngineException
	{
		this(msg);
		init(authenticatorSupport);
	}
	
	public RemoteAuthnProvidersMultiSelection(MessageSource msg)
	{
		this.msg = msg;
		setItemLabelGenerator(s -> s.getRepresentationFallbackToConfigKey(msg));
		setWidthFull();
	}
	
	private void init(AuthenticatorSupportService authenticatorSupport) throws EngineException
	{
		List remoteAuthenticators = authenticatorSupport
				.getRemoteAuthenticators(VaadinAuthentication.NAME);

		List authnOptions = new ArrayList<>();
		for (AuthenticatorInstance authenticator : remoteAuthenticators)
		{
			authnOptions.addAll(authenticator.getAuthnOptionSelectors());
		}
		setItems(authnOptions);
	}

	@Override
	public ComboBoxListDataView setItems(
			Collection authenticationOptionsSelectors)
	{
		selectors = authenticationOptionsSelectors
				.stream()
				.sorted(Comparator.comparing(selector -> selector.getRepresentationFallbackToConfigKey(msg)))
				.toList();
		return super.setItems(selectors);
	}

	@Override
	public void setValue(Collection items)
	{
		super.setValue(selectors.stream().filter(items::contains).toList());
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy