Skip to content

Commit 1048388

Browse files
committed
Deprecate UserAuthenticatorUtils.toString(String).
- Use ternary expressions - Javadoc - Inline single-use local variable
1 parent 84af4ea commit 1048388

10 files changed

Lines changed: 149 additions & 154 deletions

File tree

commons-vfs2-jackrabbit1/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.commons.httpclient.HttpClient;
2424
import org.apache.commons.lang3.CharSequenceUtils;
25+
import org.apache.commons.lang3.StringUtils;
2526
import org.apache.commons.vfs2.Capability;
2627
import org.apache.commons.vfs2.FileName;
2728
import org.apache.commons.vfs2.FileObject;
@@ -90,9 +91,9 @@ protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOpt
9091

9192
httpClient = HttpClientFactory.createConnection(WebdavFileSystemConfigBuilder.getInstance(), "http",
9293
rootName.getHostName(), rootName.getPort(),
93-
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
94+
StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
9495
UserAuthenticationData.USERNAME, CharSequenceUtils.toCharArray(rootName.getUserName()))),
95-
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
96+
StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
9697
UserAuthenticationData.PASSWORD, CharSequenceUtils.toCharArray(rootName.getPassword()))),
9798
fsOpts);
9899
} finally {

commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileObject.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.tools.FileObject;
2525

2626
import org.apache.commons.lang3.CharSequenceUtils;
27+
import org.apache.commons.lang3.StringUtils;
2728
import org.apache.commons.vfs2.FileName;
2829
import org.apache.commons.vfs2.FileType;
2930
import org.apache.commons.vfs2.FileTypeHasNoContentException;
@@ -76,7 +77,7 @@ private SmbFile createSmbFile(final FileName fileName)
7677
NtlmPasswordAuthentication auth = null;
7778
if (authData != null) {
7879
auth = new NtlmPasswordAuthentication(
79-
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
80+
StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
8081
UserAuthenticationData.DOMAIN, CharSequenceUtils.toCharArray(smbFileName.getDomain()))),
8182
UserAuthenticatorUtils
8283
.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,

commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java

Lines changed: 119 additions & 119 deletions
Large diffs are not rendered by default.

commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
3737
import org.apache.commons.vfs2.FileSystemException;
3838
import org.apache.commons.vfs2.FileSystemOptions;
39-
import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
4039

4140
/**
4241
* Creates {@link FtpClient} instances.
@@ -185,8 +184,8 @@ public void flush() {
185184
throw new FileSystemException("vfs.provider.ftp/connect-rejected.error", hostname);
186185
}
187186
// Login
188-
if (!client.login(UserAuthenticatorUtils.toString(username), UserAuthenticatorUtils.toString(password))) {
189-
throw new FileSystemException("vfs.provider.ftp/login.error", hostname, UserAuthenticatorUtils.toString(username));
187+
if (!client.login(StringUtils.valueOf(username), StringUtils.valueOf(password))) {
188+
throw new FileSystemException("vfs.provider.ftp/login.error", hostname, StringUtils.valueOf(username));
190189
}
191190
FtpFileType fileType = builder.getFileType(fileSystemOptions);
192191
if (fileType == null) {

commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public static HttpClient createConnection(final HttpFileSystemConfigBuilder buil
8484

8585
if (authData != null) {
8686
final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(
87-
UserAuthenticatorUtils.toString(
87+
StringUtils.valueOf(
8888
UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)),
89-
UserAuthenticatorUtils.toString(
89+
StringUtils.valueOf(
9090
UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null)));
9191

9292
final AuthScope scope = new AuthScope(proxyHost, AuthScope.ANY_PORT);

commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.commons.httpclient.HttpClient;
2424
import org.apache.commons.lang3.CharSequenceUtils;
25+
import org.apache.commons.lang3.StringUtils;
2526
import org.apache.commons.vfs2.Capability;
2627
import org.apache.commons.vfs2.FileName;
2728
import org.apache.commons.vfs2.FileSystem;
@@ -75,9 +76,9 @@ protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOpt
7576
final String internalScheme = lastChar == 's' || lastChar == 'S' ? "https" : "http";
7677
httpClient = HttpClientFactory.createConnection(internalScheme, rootName.getHostName(),
7778
rootName.getPort(),
78-
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
79+
StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
7980
UserAuthenticationData.USERNAME, CharSequenceUtils.toCharArray(rootName.getUserName()))),
80-
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
81+
StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
8182
UserAuthenticationData.PASSWORD, CharSequenceUtils.toCharArray(rootName.getPassword()))),
8283
fileSystemOptions);
8384
} finally {

commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ protected HttpClientContext createHttpClientContext(final Http4FileSystemConfigB
241241
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
242242
clientContext.setCredentialsProvider(credsProvider);
243243

244-
final String username = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
244+
final String username = StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
245245
UserAuthenticationData.USERNAME, CharSequenceUtils.toCharArray(rootName.getUserName())));
246-
final String password = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
246+
final String password = StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
247247
UserAuthenticationData.PASSWORD, CharSequenceUtils.toCharArray(rootName.getPassword())));
248248

249249
if (!StringUtils.isEmpty(username)) {
@@ -262,9 +262,9 @@ protected HttpClientContext createHttpClientContext(final Http4FileSystemConfigB
262262

263263
if (proxyAuthData != null) {
264264
final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(
265-
UserAuthenticatorUtils.toString(
265+
StringUtils.valueOf(
266266
UserAuthenticatorUtils.getData(proxyAuthData, UserAuthenticationData.USERNAME, null)),
267-
UserAuthenticatorUtils.toString(
267+
StringUtils.valueOf(
268268
UserAuthenticatorUtils.getData(proxyAuthData, UserAuthenticationData.PASSWORD, null)));
269269

270270
credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()),

commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected HttpClientContext createHttpClientContext(final Http5FileSystemConfigB
232232
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
233233
clientContext.setCredentialsProvider(credsProvider);
234234

235-
final String username = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
235+
final String username = StringUtils.valueOf(UserAuthenticatorUtils.getData(authData,
236236
UserAuthenticationData.USERNAME, CharSequenceUtils.toCharArray(rootName.getUserName())));
237237
final char[] password = UserAuthenticatorUtils.getData(authData,
238238
UserAuthenticationData.PASSWORD, CharSequenceUtils.toCharArray(rootName.getPassword()));
@@ -254,7 +254,7 @@ protected HttpClientContext createHttpClientContext(final Http5FileSystemConfigB
254254

255255
if (proxyAuthData != null) {
256256
final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(
257-
UserAuthenticatorUtils.toString(
257+
StringUtils.valueOf(
258258
UserAuthenticatorUtils.getData(proxyAuthData, UserAuthenticationData.USERNAME, null)),
259259
UserAuthenticatorUtils.getData(proxyAuthData, UserAuthenticationData.PASSWORD, null));
260260

commons-vfs2/src/main/java/org/apache/commons/vfs2/util/UserAuthenticatorUtils.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.commons.vfs2.util;
1818

1919
import org.apache.commons.lang3.CharSequenceUtils;
20+
import org.apache.commons.lang3.StringUtils;
2021
import org.apache.commons.vfs2.FileSystemOptions;
2122
import org.apache.commons.vfs2.UserAuthenticationData;
2223
import org.apache.commons.vfs2.UserAuthenticator;
@@ -34,10 +35,8 @@ public final class UserAuthenticatorUtils {
3435
* @param authenticatorTypes An array of types describing the data to be retrieved.
3536
* @return A UserAuthenticationData object containing the data requested.
3637
*/
37-
public static UserAuthenticationData authenticate(final FileSystemOptions options,
38-
final UserAuthenticationData.Type[] authenticatorTypes) {
39-
final UserAuthenticator auth = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(options);
40-
return authenticate(auth, authenticatorTypes);
38+
public static UserAuthenticationData authenticate(final FileSystemOptions options, final UserAuthenticationData.Type[] authenticatorTypes) {
39+
return authenticate(DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(options), authenticatorTypes);
4140
}
4241

4342
/**
@@ -49,10 +48,7 @@ public static UserAuthenticationData authenticate(final FileSystemOptions option
4948
*/
5049
public static UserAuthenticationData authenticate(final UserAuthenticator auth,
5150
final UserAuthenticationData.Type[] authenticatorTypes) {
52-
if (auth == null) {
53-
return null;
54-
}
55-
return auth.requestAuthentication(authenticatorTypes);
51+
return auth != null ? auth.requestAuthentication(authenticatorTypes) : null;
5652
}
5753

5854
/**
@@ -78,18 +74,15 @@ public static char[] getData(final UserAuthenticationData data, final UserAuthen
7874
if (overriddenValue != null) {
7975
return overriddenValue;
8076
}
81-
if (data == null) {
82-
return null;
83-
}
84-
return data.getData(type);
77+
return data != null ? data.getData(type) : null;
8578
}
8679

8780
/**
8881
* Converts a string to a char array (null-safe).
8982
*
9083
* @param string The String to convert.
91-
* @return The character array.
92-
* @deprecated Use {@link CharSequenceUtils#toCharArray(CharSequence)} instead.
84+
* @return A new character array.
85+
* @deprecated Use {@link CharSequenceUtils#toCharArray(CharSequence)}.
9386
*/
9487
@Deprecated
9588
public static char[] toChar(final String string) {
@@ -100,13 +93,12 @@ public static char[] toChar(final String string) {
10093
* Converts the given data to a string (null-safe).
10194
*
10295
* @param data A character array containing the data to convert to a String.
103-
* @return The String.
96+
* @return A new String.
97+
* @deprecated Use {@link StringUtils#valueOf(char[])}.
10498
*/
99+
@Deprecated
105100
public static String toString(final char[] data) {
106-
if (data == null) {
107-
return null;
108-
}
109-
return new String(data);
101+
return StringUtils.valueOf(data);
110102
}
111103

112104
private UserAuthenticatorUtils() {

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ The <action> type attribute can be add,update,fix,remove.
6262
<action type="fix" dev="ggregory" due-to="Gary Gregory">SftpFileSystem.executeCommand(String, StringBuilder) now restores the current thread's interrupt flag when catching InterruptedException.</action>
6363
<action type="fix" dev="ggregory" due-to="Vaishnavi Kumbhar, Gary Gregory" issue="VFS-861">Http5FileProvider Basic authentication fails: UserAuthenticationData.setData(Type, char[]) should clone its array input.</action>
6464
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate UserAuthenticatorUtils.toChar(String).</action>
65+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate UserAuthenticatorUtils.toString(String).</action>
6566
<!-- ADD -->
6667
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.vfs2.provider.ftp.FTPClientWrapper.sendOptions(String, String).</action>
6768
<action type="add" dev="ggregory" due-to="Gary Gregory">Add FtpFileSystemConfigBuilder.getControlEncodingCharset(FileSystemOptions) and deprecate getControlEncoding(FileSystemOptions).</action>

0 commit comments

Comments
 (0)