In Camel (2.15.0) call to the SFTP (docs) as such:
String uri = "sftp://foo.co.uk?username=Me+Admin&privateKeyFile=/my/id_rsa&knownHostsFile=/my/known_hosts&preferredAuthentications=publickey"
producerTemplate.sendBodyAndHeader(uri, fileContents, "CamelFileName", fullFilePath);
Results in SFTP attempt for user Me Admin. Clearly the + is replaced by a space.
I tried to url-encode this (Me%2DAdmin), still replaced by space (Me Admin).
Tried to encode it twice, now the SFTP attempt is for username Me%2DAdmin.
Anyone has an idea how do I get Camel to SFTP for a user with a + in the username? Thanks.
It’s always good to surround the username/password with RAW() tag. For example sftp:user#hostname?password=RAW(password#123)
Ok to answer my own question, changing the request url from sftp://host?username=user to sftp://user#host fixes the problem. The username still has to be encoded once:
String uri = "sftp://Me%2DAdmin#foo.co.uk?privateKeyFile=/my/id_rsa&knownHostsFile=/my/known_hosts&preferredAuthentications=publickey"
producerTemplate.sendBodyAndHeader(uri, fileContents, "CamelFileName", fullFilePath);
Related
I have an url in my app like "zoommtg://us04.zoom.com". I want to open it in browser by Intent. As it is not http or https, it can't be parsed by Uri.parse(url). Again if I try url="http://"+url; it works but deletes the ":" from "zoommtg://" resulting wrong url! I am using the solution of this Question
if it is working for https but not other requests, then you can try setting cleartexttraffic to true in your AndroidManifest.xml file.
Do tell if that fixes it. :)
zoommtg seems to be "custom protocol" declaration, which isn't resolveable by web browser, but if you are shure, that http(s) url version will work then just replace scheme
String url = "zoommtg://us04.zoom.com";
url = url.replaceFirst("zoommtg", "https")
if you really need to use unsecure http then you have to allow app to do such requests, see how to
btw. you still can use Uri class, it isn't limited to web protocols... check out some description of this structure
URI = scheme:[//authority]path[?query][#fragment]
you can parse your String to Uri and just replace scheme part
Uri.Builder builder = Uri.parse(url).buildUpon();
url = builder.scheme("https").build().toString();
I need to test a login process with the beta server and the security policy was updated so that all users have a unique email address.
So I thought for testing the app I would just use this type of email address
"myemailaddr+a#gmail.com"
where the +a allows for a unique address. Then on each subsequent test I would use "+B" etc to ensure I have a unique email address.
All good with the server but when I try and place the URL into my android webView it wont allow me to log in. Another genuine email address works just fine.
SO, how do I replace a "+" in a url string with its Unicode value of "%2B" and is it possible to do so in a URL.
Here is the URL template:
https://team.mycompany.com/teambeta/Login.aspx?username=myemailaddr+a#gmail.com&password=xxxxxxxx&mobile=1&offSetHours=11&appDevice=AndroidAndroid
Is what I am hoping to acheive possible or do I need to go and create multiple unique email addresses for testing?
Use URLEncoder.encode(). See the documentation at https://developer.android.com/reference/java/net/URLEncoder.html
After struggling with the URL ideas and other suggestions on the net I simply replaced all instances of "+" with "%2B" as follows.
webURL = webURLBefore.replace("+", "%2B");
Works well. And I did not have to encode it as when I did I was strunggling to encode just the "+" and the whole URL was encoded and would not work.
Hope this helps someone.
I am trying to stream content of a URL that is secure. The URL is accessible only after you login with username or password. When you are not logged in, you will be redirected to login.jsp. How can I stream such a URL? Is there a way to maintain session? I want to stream and store that content in file system. I cannot even provide password using Apache httpClient authentication because the passwords are one-way encrypted.
Thanks in advance
By setting the Cookie as David Conrad suggested, I got it working using the following code sample.
urlConnection.setRequestProperty("Cookie", "JSESSIONID=" + request.getSession().getId() + "; rememberMe=false")
I am using org.springframework.integration.mail.ImapMailReceiver from spring integration to read some emails from IMAP server.
Like many other IMAP servers, the IMAP server I am connecting to uses emails addresses as usernames.
So I am creating new instance of ImapMailReceiver this way
new ImapMailReceiver(“imap://user#mail.XXXX.com.au:password#mail.XXXX.com.au:143/INBOX”);
I believe ImapMailReceiver uses URLName class to parse the given string into protocol, user and etc.
However since the url string contains 2 '#' characters, URLName class is getting confused and failing to parse the username and password.
Have anybody else had similar problems before? How did you get around this problem?
Any comments will be appretiated!!
Thanks.
The "#" in the user name needs to be URL encoded. If you use the URLName constructor that takes separate username, password, etc. parameters, it will do that for you. If you're writing it by hand, you need to write it correctly, with the proper encoding for any special characters.
I've try to get mails from GMAIL that's why I use imaps
`imapMailReceiver = new ImapMailReceiver("imaps://" + URLEncoder.encode(USERNAME, "UTF-8") + ":" + PASSWORD + "#imap.gmail.com:993/INBOX");`
No, it works well
I'm using basic auth. If my password contains a colon, I seem to get a failure to authenticate. Are colons not allowed in a password? How I'm authenticating:
DefaultHttpClient client = new DefaultHttpClient();
HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() {
...
};
client.addRequestInterceptor(preemptiveAuth, 0);
client.getCredentialsProvider().setCredentials(
new AuthScope("example.com", 443),
new UsernamePasswordCredentials("me", "password:test"));
Passwords without a colon always work. Passwords with a colon always fail. Do I have to escape the password somehow before handing it to the UsernamePasswordCredentials class constructor? I know basicauth uses the username/password separated by a colon, then base64 encoded, is that what the problem is here?
Thanks
---- Update ------
Thanks all, yes was a problem in the server I was communicating with!
It should work. RFC2617 is the RFC around HTTP authentication. The spec does not place any restriction on the characters used within a password, only on the username;
To receive authorization, the client sends the userid and password,
separated by a single colon (":") character, within a base64 [7]
encoded string in the credentials.
basic-credentials = base64-user-pass
base64-user-pass = <base64 [4] encoding of user-pass,
except not limited to 76 char/line>
user-pass = userid ":" password
userid = *<TEXT excluding ":">
password = *TEXT
If the server has a bug in separating that Base64 "username:password", the authentication method will fail. Either check on your server (perhaps there are updates available? go with a different server?), don't use a colon in your passwords, or use a different authentication method.
Out of curiosity, what server are you trying to authenticate against?
I know this is an old post, but in case others run into the same issue:
The code in new UsernamePasswordCredentials("me", "password:test")); might split the string on every colon. Here is an example in PHP that would fail:
$bits = explode(':',$auth_string);
$user = $bits[0];
$password = $bits[1];
Here is a fix:
$bits = explode(':',$auth_string);
$user = array_shift($bits);
$password = implode(':',$bits);
Just had an issue with a colon in the password. Seems like the username and password won't be splitted correctly.
Example user:pass:word
In my case the delivered Password in PHP was just "pass" instead of "pass:word".
I've learned to avoid special chars like : (colon) and # (at) in the password. It's a bit strange, because the same logic worked correctly before we've updated to php-fpm (I don't know if this issue belongs to php-fpm).