Open aishuhaon opened 4 years ago
I think you can just url_encode it using https://www.urlencoder.org/
I set the url property like “http://${ELASTIC_NAME}:${ELASTIC_PASSWORD}@${ELASTIC_URL}/_bulk”,used System's environment variable to configure es's parameters Dynamically,my password contains '@' too, how to deal with this kind of problem,I would appreciate it if you could answer。
Hi,
To fix that I made an URL encoding as yoesoff said, but there was still an issue because Elasticsearch rejects the authentication with 401 error.
Reason is that in class com.internetitem.logback.elasticsearch.config.BasicAuthentication, login/password is read from URL and passed to basic auth header without decoding the password.
So my solution was to implement a custom BasicAuthentication class to decode the password before encoding it in base64 and putting it in Authorization header.
This custom BasicAuthentication class can be changed in logback configuration, by changing value of :
<authentication class="com.internetitem.logback.elasticsearch.config.BasicAuthentication" /><authentication class="com.internetitem.logback.elasticsearch.config.BasicAuthentication" />
Thx to frdrolland. This is my code and it works for me.
elastic:abc%40123@127.0.0.1:9200
<authentication class="com.xxx.config.BasicAuthentication" />
package com.xxx.config;
import com.internetitem.logback.elasticsearch.config.Authentication; import com.internetitem.logback.elasticsearch.util.Base64; import org.yaml.snakeyaml.util.UriEncoder;
import java.net.HttpURLConnection;
public class BasicAuthentication implements Authentication { public BasicAuthentication() { }
public void addAuth(HttpURLConnection urlConnection, String body) {
String userInfo = urlConnection.getURL().getUserInfo();
if (userInfo != null) {
String basicAuth = "Basic " + Base64.encode(UriEncoder.decode(userInfo).getBytes());
urlConnection.setRequestProperty("Authorization", basicAuth);
}
}
}
There you go ~
How to solve the problem if es password contains
@
elastic:abc@123@127.0.0.1:9200