- Timestamp:
- 2025-03-10T17:38:42+01:00 (2 weeks ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r19101 r19345 825 825 case HttpURLConnection.HTTP_UNAUTHORIZED: 826 826 case HttpURLConnection.HTTP_FORBIDDEN: 827 CredentialsManager.getInstance().purgeCredentialsCache(RequestorType.SERVER); 827 CredentialsManager.getInstance().purgeCredentialsCache(RequestorType.SERVER, getHost()); 828 828 throw new OsmApiException(retCode, errorHeader, errorBody, activeConnection.getURL().toString(), 829 829 doAuthenticate ? retrieveBasicAuthorizationLogin(client) : null, response.getContentType()); -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r18650 r19345 208 208 try { 209 209 if (response.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { 210 CredentialsManager.getInstance().purgeCredentialsCache(RequestorType.SERVER); 210 CredentialsManager.getInstance().purgeCredentialsCache(RequestorType.SERVER, OsmApi.getOsmApi().getHost()); 211 211 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, null, null); 212 212 } -
trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java
r12992 r19345 4 4 import java.net.Authenticator.RequestorType; 5 5 import java.net.PasswordAuthentication; 6 import java.util. EnumMap;6 import java.util.HashMap; 7 7 import java.util.Map; 8 8 import java.util.Objects; 9 9 10 10 import org.openstreetmap.josm.tools.Logging; 11 import org.openstreetmap.josm.tools.Pair; 11 12 12 13 /** … … 48 49 } 49 50 50 protected Map<RequestorType, PasswordAuthentication> memoryCredentialsCache = new EnumMap<>(RequestorType.class);51 protected Map<Pair<RequestorType, String>, PasswordAuthentication> memoryCredentialsCache = new HashMap<>(); 51 52 52 53 @Override … … 65 66 * -> Try to recall credentials that have been entered manually in this session. 66 67 */ 67 if (!noSuccessWithLastResponse && memoryCredentialsCache.containsKey(requestorType) && 68 Pair<RequestorType, String> mccKey = Pair.create(requestorType, host); 69 if (!noSuccessWithLastResponse && memoryCredentialsCache.containsKey(mccKey) && 68 70 (credentials == null || credentials.getPassword() == null || credentials.getPassword().length == 0)) { 69 PasswordAuthentication pa = memoryCredentialsCache.get( requestorType);71 PasswordAuthentication pa = memoryCredentialsCache.get(mccKey); 70 72 response.setUsername(pa.getUserName()); 71 73 response.setPassword(pa.getPassword()); … … 89 91 } else { 90 92 // User decides not to save credentials to file. Keep it in memory so we don't have to ask over and over again. 91 memoryCredentialsCache.put( requestorType, new PasswordAuthentication(response.getUsername(), response.getPassword()));93 memoryCredentialsCache.put(mccKey, new PasswordAuthentication(response.getUsername(), response.getPassword())); 92 94 } 93 95 } else { … … 102 104 @Override 103 105 public final void purgeCredentialsCache(RequestorType requestorType) { 104 memoryCredentialsCache.remove(requestorType); 106 memoryCredentialsCache.keySet().removeIf(pair -> pair.a == requestorType); 107 } 108 109 @Override 110 public void purgeCredentialsCache(RequestorType requestorType, String host) { 111 memoryCredentialsCache.remove(Pair.create(requestorType, host)); 105 112 } 106 113 -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgent.java
r19320 r19345 84 84 * Purges the internal credentials cache for the given requestor type. 85 85 * @param requestorType the type of service. 86 * {@link RequestorType# SERVER} for the OSM APIserver, {@link RequestorType#PROXY} for a proxyserver86 * {@link RequestorType#PROXY} for a proxy server, {@link RequestorType#SERVER} for other servers. 87 87 * @since 12992 88 88 */ 89 89 void purgeCredentialsCache(RequestorType requestorType); 90 91 /** 92 * Purges the internal credentials cache for the given requestor type and host. 93 * @param requestorType the type of service. 94 * @param host the host. 95 * {@link RequestorType#PROXY} for a proxy server, {@link RequestorType#SERVER} for other servers. 96 */ 97 default void purgeCredentialsCache(RequestorType requestorType, String host) { 98 purgeCredentialsCache(requestorType); 99 } 90 100 91 101 /** -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r19080 r19345 134 134 } 135 135 // see #11914: clear cache before we store new value 136 purgeCredentialsCache(requestorType); 136 purgeCredentialsCache(requestorType, host); 137 137 delegate.store(requestorType, host, credentials); 138 138 } … … 142 142 throws CredentialsAgentException { 143 143 CredentialsAgentResponse credentials = delegate.getCredentials(requestorType, host, noSuccessWithLastResponse); 144 if (requestorType == RequestorType.SERVER) { 144 if (requestorType == RequestorType.SERVER && Objects.equals(OsmApi.getOsmApi().getHost(), host)) { 145 145 // see #11914 : Keep UserIdentityManager up to date 146 146 String userName = credentials.getUsername(); … … 175 175 delegate.purgeCredentialsCache(requestorType); 176 176 } 177 178 @Override 179 public void purgeCredentialsCache(RequestorType requestorType, String host) { 180 delegate.purgeCredentialsCache(requestorType, host); 181 } 177 182 }
Note:
See TracChangeset
for help on using the changeset viewer.