Ignore:
Timestamp:
2016-07-23T23:24:19+02:00 (8 years ago)
Author:
donvip
Message:

see #josm11390 - use java.util.Base64

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsConnection.java

    r30738 r32702  
    44import java.net.Authenticator.RequestorType;
    55import java.net.HttpURLConnection;
    6 import java.nio.ByteBuffer;
    7 import java.nio.CharBuffer;
    8 import java.nio.charset.CharacterCodingException;
    9 import java.nio.charset.Charset;
    10 import java.nio.charset.CharsetEncoder;
     6import java.nio.charset.StandardCharsets;
     7import java.util.Base64;
    118
    129import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    1310import org.openstreetmap.josm.io.auth.CredentialsAgentResponse;
    14 import org.openstreetmap.josm.tools.Base64;
    1511
    1612/**
     
    6460     */
    6561    protected void addBasicAuthorizationHeader(HttpURLConnection con) throws SdsTransferException {
    66         CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
    6762        CredentialsAgentResponse response;
    6863        String token;
    6964        try {
    70                 response = credAgent.getCredentials(RequestorType.SERVER, con.getURL().getHost(), false /* don't know yet whether the credentials will succeed */);
     65            response = credAgent.getCredentials(RequestorType.SERVER, con.getURL().getHost(), false /* don't know yet whether the credentials will succeed */);
    7166        } catch (CredentialsAgentException e) {
    7267            throw new SdsTransferException(e);
     
    8176            String password = response.getPassword() == null ? "" : String.valueOf(response.getPassword());
    8277            token = username + ":" + password;
    83             try {
    84                 ByteBuffer bytes = encoder.encode(CharBuffer.wrap(token));
    85                 con.addRequestProperty("Authorization", "Basic "+Base64.encode(bytes));
    86             } catch(CharacterCodingException e) {
    87                 throw new SdsTransferException(e);
    88             }
     78            con.addRequestProperty("Authorization", "Basic "+Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8)));
    8979        }
    9080    }
Note: See TracChangeset for help on using the changeset viewer.