diff --git a/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITAuthentication.java b/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITAuthentication.java index 49766fc5..c80544e6 100644 --- a/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITAuthentication.java +++ b/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITAuthentication.java @@ -20,12 +20,14 @@ package org.nuxeo.client; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; import org.nuxeo.client.objects.user.User; +import org.nuxeo.client.objects.user.UserManager; import org.nuxeo.client.spi.NuxeoClientRemoteException; /** @@ -72,4 +74,24 @@ public void itCanChangeAuthMethod() { assertEquals("Administrator", currentUser.getUserName()); } + @Test + public void itCanLoginWithLongCredentials() { + UserManager userManager = ITBase.createClientBuilder().connect().userManager(); + + String email = "verylongmailaddress0123456789@nuxeo.com"; + String password = "verylongpassword0123456789"; + // first create user + User user = new User(); + user.setUserName(email); + user.setEmail(email); + user.setPassword(password); + userManager.createUser(user); + // now test + User currentUser = ITBase.createClient(email, password).getCurrentUser(); + assertEquals(email, currentUser.getUserName()); + assertFalse(currentUser.isAdministrator()); + // delete it + userManager.deleteUser(email); + } + } diff --git a/nuxeo-java-client/src/main/java/org/nuxeo/client/spi/auth/BasicAuthInterceptor.java b/nuxeo-java-client/src/main/java/org/nuxeo/client/spi/auth/BasicAuthInterceptor.java index 7237f5bb..32c33b7d 100644 --- a/nuxeo-java-client/src/main/java/org/nuxeo/client/spi/auth/BasicAuthInterceptor.java +++ b/nuxeo-java-client/src/main/java/org/nuxeo/client/spi/auth/BasicAuthInterceptor.java @@ -42,7 +42,7 @@ public BasicAuthInterceptor(String username, String password) { throw new NuxeoClientException("'username' and 'password' must be set"); } String info = username + ":" + password; - token = "Basic " + Base64.encode(info); + token = "Basic " + Base64.encode(info, Base64.DONT_BREAK_LINES); } @Override diff --git a/nuxeo-java-client/src/main/java/org/nuxeo/client/util/Base64.java b/nuxeo-java-client/src/main/java/org/nuxeo/client/util/Base64.java index af5b117c..3f81fcad 100644 --- a/nuxeo-java-client/src/main/java/org/nuxeo/client/util/Base64.java +++ b/nuxeo-java-client/src/main/java/org/nuxeo/client/util/Base64.java @@ -216,6 +216,15 @@ public static String encode(String content) { return encodeBytes(content.getBytes()); } + /** + * @param options encoding options provided by {@link Base64}. + * @since 3.0. + * @see Base64#DONT_BREAK_LINES + */ + public static String encode(String content, int options) { + return encodeBytes(content.getBytes(), options); + } + public static String encode(String content, String charset) throws UnsupportedEncodingException { return encodeBytes(content.getBytes(charset)); }