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

org.finos.legend.connection.CredentialBuilder Maven / Gradle / Ivy

// Copyright 2023 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.connection;

import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.AuthenticationConfiguration;
import org.finos.legend.engine.shared.core.identity.Credential;
import org.finos.legend.engine.shared.core.identity.Identity;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Objects;

public abstract class CredentialBuilder
{
    public abstract OUTPUT_CRED makeCredential(Identity identity, CONFIG config, INPUT_CRED cred, LegendEnvironment environment) throws Exception;

    public Class getAuthenticationConfigurationType()
    {
        return (Class) actualTypeArguments()[0];
    }

    public Class getInputCredentialType()
    {
        return (Class) actualTypeArguments()[1];
    }

    public Class getOutputCredentialType()
    {
        return (Class) actualTypeArguments()[2];
    }

    protected Type[] actualTypeArguments()
    {
        Type genericSuperClass = this.getClass().getGenericSuperclass();
        ParameterizedType parameterizedType = (ParameterizedType) genericSuperClass;
        return parameterizedType.getActualTypeArguments();
    }

    public static class Key
    {
        private final Class authenticationConfigurationType;
        private final Class inputCredentialType;
        private final Class outputCredentialType;

        public Key(Class authenticationConfigurationType, Class inputCredentialType, Class outputCredentialType)
        {
            this.authenticationConfigurationType = authenticationConfigurationType;
            this.inputCredentialType = inputCredentialType;
            this.outputCredentialType = outputCredentialType;
        }

        @Override
        public boolean equals(Object o)
        {
            if (this == o)
            {
                return true;
            }
            if (o == null || getClass() != o.getClass())
            {
                return false;
            }
            CredentialBuilder.Key that = (CredentialBuilder.Key) o;
            return this.authenticationConfigurationType.equals(that.authenticationConfigurationType) &&
                    this.inputCredentialType.equals(that.inputCredentialType) &&
                    this.outputCredentialType.equals(that.outputCredentialType);
        }

        @Override
        public int hashCode()
        {
            return Objects.hash(authenticationConfigurationType, inputCredentialType, outputCredentialType);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy