1 package org.eclipse.aether.util.repository; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.HashMap; 23 import java.util.Map; 24 25 import org.eclipse.aether.repository.Authentication; 26 import org.eclipse.aether.repository.AuthenticationSelector; 27 import org.eclipse.aether.repository.RemoteRepository; 28 29 /** 30 * A simple authentication selector that selects authentication based on repository identifiers. 31 */ 32 public final class DefaultAuthenticationSelector 33 implements AuthenticationSelector 34 { 35 36 private final Map<String, Authentication> repos = new HashMap<>(); 37 38 /** 39 * Adds the specified authentication info for the given repository identifier. 40 * 41 * @param id The identifier of the repository to add the authentication for, must not be {@code null}. 42 * @param auth The authentication to add, may be {@code null}. 43 * @return This selector for chaining, never {@code null}. 44 */ 45 public DefaultAuthenticationSelector add( String id, Authentication auth ) 46 { 47 if ( auth != null ) 48 { 49 repos.put( id, auth ); 50 } 51 else 52 { 53 repos.remove( id ); 54 } 55 56 return this; 57 } 58 59 public Authentication getAuthentication( RemoteRepository repository ) 60 { 61 return repos.get( repository.getId() ); 62 } 63 64 }