Changeset 12992 in josm for trunk/src/org/openstreetmap/josm/io/OsmConnection.java
- Timestamp:
- 2017-10-14T00:09:56+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r12931 r12992 31 31 */ 32 32 public class OsmConnection { 33 34 private static final String BASIC_AUTH = "Basic "; 35 33 36 protected boolean cancel; 34 37 protected HttpClient activeConnection; … … 75 78 76 79 /** 80 * Retrieves login from basic authentication header, if set. 81 * 82 * @param con the connection 83 * @return login from basic authentication header, or {@code null} 84 * @throws OsmTransferException if something went wrong. Check for nested exceptions 85 * @since 12992 86 */ 87 protected String retrieveBasicAuthorizationLogin(HttpClient con) throws OsmTransferException { 88 String auth = con.getRequestHeader("Authorization"); 89 if (auth != null && auth.startsWith(BASIC_AUTH)) { 90 try { 91 String[] token = new String(Base64.getDecoder().decode(auth.substring(BASIC_AUTH.length())), 92 StandardCharsets.UTF_8).split(":"); 93 if (token.length == 2) { 94 return token[0]; 95 } 96 } catch (IllegalArgumentException e) { 97 Logging.error(e); 98 } 99 } 100 return null; 101 } 102 103 /** 77 104 * Adds an authentication header for basic authentication 78 105 * … … 98 125 String password = response.getPassword() == null ? "" : String.valueOf(response.getPassword()); 99 126 String token = username + ':' + password; 100 con.setHeader("Authorization", "Basic "+Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8)));127 con.setHeader("Authorization", BASIC_AUTH + Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8))); 101 128 } 102 129 }
Note:
See TracChangeset
for help on using the changeset viewer.