public NTLMCredentials(PasswordCredentials credentials) { String domain; String username = credentials.getUsername(); int slashPos = username.indexOf('\\'); slashPos = slashPos >= 0 ? slashPos : username.indexOf('/'); if (slashPos >= 0) { domain = username.substring(0, slashPos); username = username.substring(slashPos + 1); } else { domain = System.getProperty("http.auth.ntlm.domain", DEFAULT_DOMAIN); } this.domain = domain == null ? null : domain.toUpperCase(); this.username = username; this.password = credentials.getPassword(); this.workstation = determineWorkstationName(); }
private void useCredentials(CredentialsProvider credentialsProvider, String host, int port, Collection<? extends Authentication> authentications) { Credentials httpCredentials; for (Authentication authentication : authentications) { String scheme = getAuthScheme(authentication); PasswordCredentials credentials = getPasswordCredentials(authentication); if (authentication instanceof AllSchemesAuthentication) { NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials); httpCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain()); credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthSchemes.NTLM), httpCredentials); LOGGER.debug("Using {} and {} for authenticating against '{}:{}' using {}", credentials, ntlmCredentials, host, port, AuthSchemes.NTLM); } httpCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword()); credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, scheme), httpCredentials); LOGGER.debug("Using {} for authenticating against '{}:{}' using {}", credentials, host, port, scheme); } }
private ClientConfiguration createConnectionProperties() { ClientConfiguration clientConfiguration = new ClientConfiguration(); Optional<HttpProxySettings.HttpProxy> proxyOptional = s3ConnectionProperties.getProxy(); if (proxyOptional.isPresent()) { HttpProxySettings.HttpProxy proxy = s3ConnectionProperties.getProxy().get(); clientConfiguration.setProxyHost(proxy.host); clientConfiguration.setProxyPort(proxy.port); PasswordCredentials credentials = proxy.credentials; if (credentials != null) { clientConfiguration.setProxyUsername(credentials.getUsername()); clientConfiguration.setProxyPassword(credentials.getPassword()); } } Optional<Integer> maxErrorRetryCount = s3ConnectionProperties.getMaxErrorRetryCount(); if (maxErrorRetryCount.isPresent()) { clientConfiguration.setMaxErrorRetry(maxErrorRetryCount.get()); } return clientConfiguration; }
public RemoteRepository create() { RemoteRepository remoteRepository = new RemoteRepository(); remoteRepository.setUrl(artifactRepository.getUrl().toString()); PasswordCredentials credentials = artifactRepository.getCredentials(); String username = credentials.getUsername(); String password = credentials.getPassword(); if (username != null || password != null) { Authentication authentication = new Authentication(); authentication.setUserName(username); authentication.setPassword(password); remoteRepository.addAuthentication(authentication); } return remoteRepository; }
@Override public PasswordCredentials getCredentials() { if (credentials == null) { return setCredentials(PasswordCredentials.class); } else if (credentials instanceof PasswordCredentials) { return Cast.uncheckedCast(credentials); } else { throw new IllegalStateException("Can not use getCredentials() method when not using PasswordCredentials; please use getCredentials(Class)"); } }
@Override public void credentials(Action<? super PasswordCredentials> action) { if (credentials != null && !(credentials instanceof PasswordCredentials)) { throw new IllegalStateException("Can not use credentials(Action) method when not using PasswordCredentials; please use credentials(Class, Action)"); } credentials(PasswordCredentials.class, action); }
private static <T extends Credentials> Class<? extends T> getCredentialsImplType(Class<T> publicType) { if (publicType == PasswordCredentials.class) { return Cast.uncheckedCast(DefaultPasswordCredentials.class); } else if (publicType == AwsCredentials.class) { return Cast.uncheckedCast(DefaultAwsCredentials.class); } else { throw new IllegalArgumentException(String.format("Unknown credentials type: '%s' (supported types: %s and %s).", publicType.getName(), PasswordCredentials.class.getName(), AwsCredentials.class.getName())); } }
private static <T extends Credentials> Class<? super T> getCredentialsPublicType(Class<T> implType) { if (PasswordCredentials.class.isAssignableFrom(implType)) { return Cast.uncheckedCast(PasswordCredentials.class); } else if (AwsCredentials.class.isAssignableFrom(implType)) { return Cast.uncheckedCast(AwsCredentials.class); } else { throw new IllegalArgumentException(String.format("Unknown credentials implementation type: '%s' (supported types: %s and %s).", implType.getName(), DefaultPasswordCredentials.class.getName(), DefaultAwsCredentials.class.getName())); } }
@Override public ExternalResourceConnector createResourceConnector(ResourceConnectorSpecification connectionDetails) { PasswordCredentials passwordCredentials = connectionDetails.getCredentials(PasswordCredentials.class); SftpResourceAccessor accessor = new SftpResourceAccessor(sftpClientFactory, passwordCredentials); SftpResourceLister lister = new SftpResourceLister(sftpClientFactory, passwordCredentials); SftpResourceUploader uploader = new SftpResourceUploader(sftpClientFactory, passwordCredentials); return new DefaultExternalResourceConnector(accessor, lister, uploader); }
private PasswordCredentials getPasswordCredentials(Authentication authentication) { org.gradle.api.credentials.Credentials credentials = ((AuthenticationInternal) authentication).getCredentials(); if (!(credentials instanceof PasswordCredentials)) { throw new IllegalArgumentException(String.format("Credentials must be an instance of: %s", PasswordCredentials.class.getCanonicalName())); } return Cast.uncheckedCast(credentials); }
public DefaultIvyArtifactRepository(FileResolver fileResolver, PasswordCredentials credentials, RepositoryTransportFactory transportFactory, LocallyAvailableResourceFinder<ModuleComponentArtifactMetaData> locallyAvailableResourceFinder, Instantiator instantiator, ResolverStrategy resolverStrategy, FileStore<ModuleComponentArtifactMetaData> artifactFileStore) { super(credentials); this.fileResolver = fileResolver; this.transportFactory = transportFactory; this.locallyAvailableResourceFinder = locallyAvailableResourceFinder; this.resolverStrategy = resolverStrategy; this.artifactFileStore = artifactFileStore; this.additionalPatternsLayout = new AdditionalPatternsRepositoryLayout(fileResolver); this.layout = new GradleRepositoryLayout(); this.metaDataProvider = new MetaDataProvider(); this.instantiator = instantiator; }
public RepositoryTransport createTransport(Set<String> schemes, String name, PasswordCredentials credentials) { if (!WrapUtil.toSet("http", "https", "file", "sftp").containsAll(schemes)) { throw new InvalidUserDataException("You may only specify 'file', 'http', 'https' and 'sftp' URLs for a repository."); } if (WrapUtil.toSet("http", "https").containsAll(schemes)) { return createHttpTransport(name, credentials); } if (WrapUtil.toSet("file").containsAll(schemes)) { return createFileTransport(name); } if (WrapUtil.toSet("sftp").containsAll(schemes)) { return createSftpTransport(name, credentials); } throw new InvalidUserDataException("You cannot mix different URL schemes for a single repository. Please declare separate repositories."); }
public DefaultMavenArtifactRepository(FileResolver fileResolver, PasswordCredentials credentials, RepositoryTransportFactory transportFactory, LocallyAvailableResourceFinder<ModuleComponentArtifactMetaData> locallyAvailableResourceFinder, FileStore<ModuleComponentArtifactMetaData> artifactFileStore) { super(credentials); this.fileResolver = fileResolver; this.transportFactory = transportFactory; this.locallyAvailableResourceFinder = locallyAvailableResourceFinder; this.artifactFileStore = artifactFileStore; }
private void configureCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials) { if (GUtil.isTrue(credentials.getUsername())) { useCredentials(httpClient, credentials, AuthScope.ANY_HOST, AuthScope.ANY_PORT); // Use preemptive authorisation if no other authorisation has been established httpClient.addRequestInterceptor(new PreemptiveAuth(new BasicScheme()), 0); } }
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) { Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword()); httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials); NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials); Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain()); httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials); LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port}); }
public HttpTransport(String name, PasswordCredentials credentials, RepositoryArtifactCache repositoryCacheManager, ProgressLoggerFactory progressLoggerFactory, TemporaryFileProvider temporaryFileProvider, CachedExternalResourceIndex<String> cachedExternalResourceIndex, BuildCommencedTimeProvider timeProvider) { this.name = name; this.repositoryCacheManager = repositoryCacheManager; repository = createRepository(credentials, progressLoggerFactory, temporaryFileProvider, cachedExternalResourceIndex, timeProvider); }
private ExternalResourceRepository createRepository(PasswordCredentials credentials, ProgressLoggerFactory progressLoggerFactory, TemporaryFileProvider temporaryFileProvider, CachedExternalResourceIndex<String> cachedExternalResourceIndex, BuildCommencedTimeProvider timeProvider) { HttpClientHelper http = new HttpClientHelper(new DefaultHttpSettings(credentials)); HttpResourceAccessor accessor = new HttpResourceAccessor(http); HttpResourceUploader uploader = new HttpResourceUploader(http); ProgressLoggingExternalResourceAccessor loggingAccessor = new ProgressLoggingExternalResourceAccessor(accessor, progressLoggerFactory); return new DefaultExternalResourceRepository( name, accessor, new ProgressLoggingExternalResourceUploader(uploader, progressLoggerFactory), new HttpResourceLister(accessor), temporaryFileProvider, new DefaultCacheAwareExternalResourceAccessor(loggingAccessor, cachedExternalResourceIndex, timeProvider) ); }
public DefaultIvyArtifactRepository(FileResolver fileResolver, PasswordCredentials credentials, RepositoryTransportFactory transportFactory, LocallyAvailableResourceFinder<ModuleVersionArtifactMetaData> locallyAvailableResourceFinder, Instantiator instantiator, ResolverStrategy resolverStrategy) { super(credentials); this.fileResolver = fileResolver; this.transportFactory = transportFactory; this.locallyAvailableResourceFinder = locallyAvailableResourceFinder; this.resolverStrategy = resolverStrategy; this.additionalPatternsLayout = new AdditionalPatternsRepositoryLayout(fileResolver); this.layout = new GradleRepositoryLayout(); this.metaDataProvider = new MetaDataProvider(); this.instantiator = instantiator; }
public DefaultMavenArtifactRepository(FileResolver fileResolver, PasswordCredentials credentials, RepositoryTransportFactory transportFactory, LocallyAvailableResourceFinder<ModuleVersionArtifactMetaData> locallyAvailableResourceFinder, ResolverStrategy resolverStrategy) { super(credentials); this.fileResolver = fileResolver; this.transportFactory = transportFactory; this.locallyAvailableResourceFinder = locallyAvailableResourceFinder; this.resolverStrategy = resolverStrategy; }
@Override public PasswordCredentials getCredentials() { return authenticationSupport.getCredentials(); }
@Override public void credentials(Action<? super PasswordCredentials> action) { checkMutable(); authenticationSupport.credentials(action); }
@Override public PasswordCredentials getCredentials() { return delegate.getCredentials(); }
@Override public void credentials(Action<? super PasswordCredentials> action) { delegate.credentials(action); }
public SftpResourceUploader(SftpClientFactory sftpClientFactory, PasswordCredentials credentials) { this.sftpClientFactory = sftpClientFactory; this.credentials = credentials; }
public SftpResourceAccessor(SftpClientFactory sftpClientFactory, PasswordCredentials credentials) { this.sftpClientFactory = sftpClientFactory; this.credentials = credentials; }
public SftpResource(SftpClientFactory clientFactory, ExternalResourceMetaData metaData, URI uri, PasswordCredentials credentials) { this.clientFactory = clientFactory; this.metaData = metaData; this.uri = uri; this.credentials = credentials; }
public SftpResourceLister(SftpClientFactory sftpClientFactory, PasswordCredentials credentials) { this.sftpClientFactory = sftpClientFactory; this.credentials = credentials; }
public SftpHost(URI uri, PasswordCredentials credentials) { hostname = uri.getHost(); port = uri.getPort(); username = credentials.getUsername(); password = credentials.getPassword(); }
public LockableSftpClient createSftpClient(URI uri, PasswordCredentials credentials) { synchronized (lock) { SftpHost sftpHost = new SftpHost(uri, credentials); return acquireClient(sftpHost); } }
public DefaultDigestAuthentication(String name) { super(name, DigestAuthentication.class, PasswordCredentials.class); }
public DefaultBasicAuthentication(String name) { super(name, BasicAuthentication.class, PasswordCredentials.class); }
public DefaultMavenLocalArtifactRepository(FileResolver fileResolver, PasswordCredentials credentials, RepositoryTransportFactory transportFactory, LocallyAvailableResourceFinder<ModuleComponentArtifactMetaData> locallyAvailableResourceFinder, FileStore<ModuleComponentArtifactMetaData> artifactFileStore) { super(fileResolver, credentials, transportFactory, locallyAvailableResourceFinder, artifactFileStore); }
private PasswordCredentials createPasswordCredentials() { return instantiator.newInstance(DefaultPasswordCredentials.class); }
private RepositoryTransport createHttpTransport(String name, PasswordCredentials credentials) { return new HttpTransport(name, convertPasswordCredentials(credentials), progressLoggerFactory, temporaryFileProvider, cachedExternalResourceIndex, timeProvider, cacheLockingManager); }
private RepositoryTransport createSftpTransport(String name, PasswordCredentials credentials) { return new SftpTransport(name, convertPasswordCredentials(credentials), progressLoggerFactory, temporaryFileProvider, cachedExternalResourceIndex, timeProvider, sftpClientFactory, cacheLockingManager); }
public RepositoryTransport createTransport(String scheme, String name, PasswordCredentials credentials) { Set<String> schemes = new HashSet<String>(); schemes.add(scheme); return createTransport(schemes, name, credentials); }
private org.gradle.internal.resource.PasswordCredentials convertPasswordCredentials(PasswordCredentials credentials) { return new org.gradle.internal.resource.PasswordCredentials(credentials.getUsername(), credentials.getPassword()); }
AbstractAuthenticationSupportedRepository(PasswordCredentials credentials) { this.passwordCredentials = credentials; }