Ignore:
Timestamp:
2011-12-21T23:12:59+01:00 (13 years ago)
Author:
stoecker
Message:

see #7086 - fix passing auth information to wrong server

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java

    r4264 r4690  
    88import org.openstreetmap.josm.data.oauth.OAuthToken;
    99import org.openstreetmap.josm.gui.JosmUserIdentityManager;
     10import org.openstreetmap.josm.io.OsmApi;
    1011import org.openstreetmap.josm.tools.Utils;
    1112
     
    6667
    6768    public String getUsername() {
     69        return getUsername(OsmApi.getOsmApi().getHost());
     70    }
     71
     72    public String getUsername(String host) {
    6873        String username = null;
    6974        try {
    70             PasswordAuthentication auth = lookup(RequestorType.SERVER);
     75            PasswordAuthentication auth = lookup(RequestorType.SERVER, host);
    7176            if (auth != null) {
    7277                username = auth.getUserName();
     
    8186
    8287    @Override
    83     public PasswordAuthentication lookup(RequestorType requestorType) throws CredentialsAgentException {
    84         return delegate.lookup(requestorType);
     88    public PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException {
     89        return delegate.lookup(requestorType, host);
    8590    }
    8691
    8792    @Override
    88     public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsAgentException {
    89         if (requestorType == RequestorType.SERVER && credentials.getUserName() != null && !credentials.getUserName().trim().isEmpty()) {
    90             JosmUserIdentityManager.getInstance().setPartiallyIdentified(credentials.getUserName());
     93    public void store(RequestorType requestorType, String host, PasswordAuthentication credentials) throws CredentialsAgentException {
     94        if (requestorType == RequestorType.SERVER && OsmApi.getOsmApi().getHost().equals(host)) {
     95            String username = credentials.getUserName();
     96            if(username != null && !username.trim().isEmpty()) {
     97                JosmUserIdentityManager.getInstance().setPartiallyIdentified(username);
     98            }
    9199        }
    92         delegate.store(requestorType, credentials);
     100        delegate.store(requestorType, host, credentials);
    93101    }
    94102
    95103    @Override
    96     public CredentialsAgentResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsAgentException {
    97         return delegate.getCredentials(requestorType, noSuccessWithLastResponse);
     104    public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException {
     105        return delegate.getCredentials(requestorType, host, noSuccessWithLastResponse);
    98106    }
    99107
Note: See TracChangeset for help on using the changeset viewer.