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

io.imunity.vaadin.secured_shared_endpoint.console.WellKnownServiceEditor Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package io.imunity.vaadin.secured_shared_endpoint.console;

import com.vaadin.flow.data.binder.Binder;
import io.imunity.vaadin.auth.services.*;
import io.imunity.vaadin.auth.services.tabs.AuthenticationTab;
import io.imunity.vaadin.auth.services.tabs.GeneralTab;
import io.imunity.vaadin.endpoint.common.exceptions.FormValidationException;
import io.imunity.vaadin.secured_shared_endpoint.SecuredSharedEndpointFactory;
import pl.edu.icm.unity.base.authn.AuthenticationFlowDefinition;
import pl.edu.icm.unity.base.message.MessageSource;
import pl.edu.icm.unity.engine.api.authn.AuthenticatorInfo;

import java.util.List;
import java.util.Set;

class WellKnownServiceEditor implements ServiceEditor
{
	private final MessageSource msg;
	private final List allRealms;
	private final List flows;
	private final List authenticators;
	private final List usedEndpointsPaths;
	private final List usedNames;
	private final Set serverContextPaths;
	private WellKnownServiceEditorComponent editor;

	WellKnownServiceEditor(MessageSource msg, List allRealms,
			List flows, List authenticators, List usedPaths,
			List usedNames,
			Set serverContextPaths)
	{
		this.msg = msg;
		this.allRealms = List.copyOf(allRealms);
		this.authenticators = List.copyOf(authenticators);
		this.flows = List.copyOf(flows);
		this.usedNames = List.copyOf(usedNames);
		this.usedEndpointsPaths = List.copyOf(usedPaths);
		this.serverContextPaths = serverContextPaths;
	}

	@Override
	public ServiceEditorComponent getEditor(ServiceDefinition endpoint)
	{

		GeneralTab generalTab = new GeneralTab(msg, SecuredSharedEndpointFactory.TYPE, usedEndpointsPaths,
				usedNames, serverContextPaths);

		AuthenticationTab authenticationTab = new AuthenticationTab(msg, flows, authenticators, allRealms,
				SecuredSharedEndpointFactory.TYPE.getSupportedBinding());

		editor = new WellKnownServiceEditorComponent(msg, generalTab, authenticationTab,
				(DefaultServiceDefinition) endpoint);
		return editor;
	}

	@Override
	public ServiceDefinition getEndpointDefiniton() throws FormValidationException
	{
		return editor.getServiceDefiniton();
	}

	private static class WellKnownServiceEditorComponent extends ServiceEditorBase
	{

		private final Binder serviceBinder;

		public WellKnownServiceEditorComponent(MessageSource msg, GeneralTab generalTab, AuthenticationTab authTab,
				DefaultServiceDefinition toEdit)
		{
			super(msg);
			boolean editMode = toEdit != null;
			serviceBinder = new Binder<>(DefaultServiceDefinition.class);

			generalTab.initUI(serviceBinder, editMode);
			registerTab(generalTab);
			authTab.initUI(serviceBinder);
			registerTab(authTab);
			serviceBinder.setBean(editMode ? toEdit
					: new DefaultServiceDefinition(SecuredSharedEndpointFactory.TYPE.getName()));

		}

		public ServiceDefinition getServiceDefiniton() throws FormValidationException
		{
			boolean hasErrors = serviceBinder.validate().hasErrors();
			if (hasErrors)
			{
				setErrorInTabs();
				throw new FormValidationException();
			}

			DefaultServiceDefinition service = serviceBinder.getBean();
			service.setConfiguration("");
			return service;
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy