You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Philipp Brügger (JIRA)" <ji...@apache.org> on 2015/04/10 09:54:12 UTC

[jira] [Commented] (VFS-236) SmbFileObject throws NPE when used without authentication

    [ https://issues.apache.org/jira/browse/VFS-236?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14489118#comment-14489118 ] 

Philipp Brügger commented on VFS-236:
-------------------------------------

The difference of above solutions is finally just the different call of the constructor of the jcifs SmbFile class when the authentication is null:

Solution A) new SmbFile(path);
Solution B) new SmbFile(path,  NtlmPasswordAuthentication.ANONYMOUS);

While solution A) does not change the semantic of the SmbFile usage, just fixes the NullPointerException, solution B) does modify the usage of SmbFile. 

I would recommend to implement solution A) for fixing the NPE. If Solution B) is a change of the usage. SmbFile class offers the Constructor without auth.


> SmbFileObject throws NPE when used without authentication
> ---------------------------------------------------------
>
>                 Key: VFS-236
>                 URL: https://issues.apache.org/jira/browse/VFS-236
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: Nightly Builds
>            Reporter: Matt Casters
>             Fix For: 2.1
>
>
> If you have a shared folder without authentication, SmbFileObject throws an NPE in method createSmbFile().
> Here is what I changed to get it to run:
>     private SmbFile createSmbFile(FileName fileName) throws MalformedURLException, SmbException, FileSystemException
>     {
>         SmbFileName smbFileName = (SmbFileName) fileName;
>         String path = smbFileName.getUriWithoutAuth();
> 		UserAuthenticationData authData = null;
> 		SmbFile file;
> 		NtlmPasswordAuthentication auth;
> 		try
> 		{
> 			authData = UserAuthenticatorUtils.authenticate(getFileSystem().getFileSystemOptions(), SmbFileProvider.AUTHENTICATOR_TYPES);
> 			if (authData!=null) {
> 				auth = new NtlmPasswordAuthentication(
> 					UserAuthenticatorUtils.toString(
> 						UserAuthenticatorUtils.getData(
> 							authData,
> 							UserAuthenticationData.DOMAIN,
> 							UserAuthenticatorUtils.toChar(smbFileName.getDomain()))),
> 					UserAuthenticatorUtils.toString(
> 						UserAuthenticatorUtils.getData(
> 							authData,
> 							UserAuthenticationData.USERNAME,
> 							UserAuthenticatorUtils.toChar(smbFileName.getUserName()))),
> 					UserAuthenticatorUtils.toString(
> 						UserAuthenticatorUtils.getData(
> 							authData,
> 							UserAuthenticationData.PASSWORD,
> 							UserAuthenticatorUtils.toChar(smbFileName.getPassword()))));
> 				file = new SmbFile(path, auth);
> 			} else {
> 				auth=null;
> 				file = new SmbFile(path);
> 			}
> 		}
> 		finally
> 		{
> 			UserAuthenticatorUtils.cleanup(authData);
> 		}
> 		if (file.isDirectory() && !file.toString().endsWith("/"))
> 		{
> 			if (auth!=null) {
> 				file = new SmbFile(path + "/", auth);
> 			} else {
> 				file = new SmbFile(path + "/");
> 			}
> 		}
> 		return file;
>     }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)