Search in sources :

Example 1 with AuthenticationInternal

use of org.gradle.internal.authentication.AuthenticationInternal in project gradle by gradle.

the class RepositoryTransportFactory method validateConnectorFactoryCredentials.

private void validateConnectorFactoryCredentials(Set<String> schemes, ResourceConnectorFactory factory, Collection<Authentication> authentications) {
    Set<Class<? extends Authentication>> configuredAuthenticationTypes = Sets.newHashSet();
    for (Authentication authentication : authentications) {
        AuthenticationInternal authenticationInternal = (AuthenticationInternal) authentication;
        boolean isAuthenticationSupported = false;
        Credentials credentials = authenticationInternal.getCredentials();
        boolean needCredentials = authenticationInternal.requiresCredentials();
        for (Class<?> authenticationType : factory.getSupportedAuthentication()) {
            if (authenticationType.isAssignableFrom(authentication.getClass())) {
                isAuthenticationSupported = true;
                break;
            }
        }
        if (!isAuthenticationSupported) {
            throw new InvalidUserDataException(String.format("Authentication scheme %s is not supported by protocol '%s'", authentication, schemes.iterator().next()));
        }
        if (credentials != null) {
            if (!((AuthenticationInternal) authentication).supports(credentials)) {
                throw new InvalidUserDataException(String.format("Credentials type of '%s' is not supported by authentication scheme %s", credentials.getClass().getSimpleName(), authentication));
            }
        } else {
            if (needCredentials) {
                throw new InvalidUserDataException("You cannot configure authentication schemes for this repository type if no credentials are provided.");
            }
        }
        if (!configuredAuthenticationTypes.add(authenticationInternal.getType())) {
            throw new InvalidUserDataException(String.format("You cannot configure multiple authentication schemes of the same type.  The duplicate one is %s.", authentication));
        }
    }
}
Also used : Authentication(org.gradle.authentication.Authentication) InvalidUserDataException(org.gradle.api.InvalidUserDataException) AuthenticationInternal(org.gradle.internal.authentication.AuthenticationInternal) Credentials(org.gradle.api.credentials.Credentials)

Aggregations

InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Credentials (org.gradle.api.credentials.Credentials)1 Authentication (org.gradle.authentication.Authentication)1 AuthenticationInternal (org.gradle.internal.authentication.AuthenticationInternal)1