Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping @ isn't working? #320

Open
jjashinskyMC opened this issue Oct 25, 2022 · 1 comment
Open

Escaping @ isn't working? #320

jjashinskyMC opened this issue Oct 25, 2022 · 1 comment

Comments

@jjashinskyMC
Copy link

We have a project that's been using jcifs-ng for a while, currently on 2.1.5.
We have some unit tests that started failing and we've narrowed it down to being a password with "@" in it. I added code to escape it to "%40", but it still fails all the same.
I think I'm at the end of my rope trying to figure this out.

@mbechler
Copy link
Contributor

How are you specifying the password?

 try ( SmbFile f = new SmbFile("smb://foo:b%[email protected]/") ) {
    Assert.assertEquals("foo:b%40r", f.getLocator().getURL().getUserInfo());
    NtlmPasswordAuthenticator na = f.getContext().getCredentials().unwrap(NtlmPasswordAuthenticator.class);
    Assert.assertEquals("b@r", na.getPassword());
}

try ( SmbFile f = new SmbFile(new URL("smb://foo:b%[email protected]/")) ) {
    Assert.assertEquals("foo:b%40r", f.getLocator().getURL().getUserInfo());
    NtlmPasswordAuthenticator na = f.getContext().getCredentials().unwrap(NtlmPasswordAuthenticator.class);
    Assert.assertEquals("b@r", na.getPassword());
}

appears to work as expected for me.

I would generally recommend switching to Context-based credential configuration e.g. something like

CIFSContext authed = SingletonContext.getInstance().withCredentials(new NtlmPasswordAuthenticator("DOMAIN", "user", "p@ssword"));
SmbFile f = new SmbFile("smb://x.y.z/share/....", authed)

no escaping should be required in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants