Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 685567e

Browse files
author
Emmanuel Hugonnet
committed
Updating code to use UTF-8 encoding
Fixing bug #974 partially : Error 401 whith special chars in username. git-svn-id: https://www.silverpeas.org/svn/silverpeas/services/office-online/trunk@2278 a8e77078-a1c7-4fa5-b8fc-53c5178a176c
1 parent d3886bf commit 685567e

File tree

6 files changed

+28
-40
lines changed

6 files changed

+28
-40
lines changed

pom.xml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.silverpeas</groupId>
66
<artifactId>parent</artifactId>
7-
<version>6.0</version>
7+
<version>14</version>
88
</parent>
99

1010
<scm>
@@ -134,12 +134,4 @@
134134
</properties>
135135

136136

137-
</project>
138-
139-
140-
141-
142-
143-
144-
145-
137+
</project>

src/main/java/com/silverpeas/openoffice/Launcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static void main(final String[] args) throws OfficeNotFoundException {
6464
logger.log(Level.INFO, "{0}{1}", new Object[] { MessageUtil.getMessage("info.url.decoded"),
6565
url });
6666
if (args[1] != null && !"".equals(args[1].trim())) {
67-
logger.log(Level.INFO, "{0} {2}", new Object[] {
67+
logger.log(Level.INFO, "{0} {1}", new Object[] {
6868
MessageUtil.getMessage("info.default.path"), UrlExtractor.decodePath(args[1]) });
6969
MsOfficePathFinder.basePath = UrlExtractor.decodePath(args[1]);
7070
}

src/main/java/com/silverpeas/openoffice/util/PasswordManager.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.silverpeas.openoffice.Launcher;
3333
import java.io.UnsupportedEncodingException;
3434
import java.math.BigInteger;
35+
import java.net.URLDecoder;
3536
import java.security.GeneralSecurityException;
3637
import java.security.Key;
3738
import java.util.logging.Level;
@@ -59,8 +60,7 @@ public static String decodePassword(String encodedPassword) throws
5960
Cipher cipher = Cipher.getInstance("DES");
6061
cipher.init(Cipher.DECRYPT_MODE, decryptionKey);
6162
byte[] bytes = new BigInteger(encodedPassword, 16).toByteArray();
62-
Logger.getLogger(Launcher.class.getName()).log(Level.INFO,
63-
"decrypted password byte array length : " + bytes.length);
63+
Logger.getLogger(Launcher.class.getName()).log(Level.INFO, "decrypted password byte array length : {0}", bytes.length);
6464
int nbCaracToRemove = (bytes.length) % 8;
6565
byte[] result = new byte[bytes.length - nbCaracToRemove];
6666
System.arraycopy(bytes, nbCaracToRemove, result, 0, bytes.length -
@@ -78,7 +78,7 @@ public static String encodePassword(String password) throws
7878
Cipher cipher = Cipher.getInstance("DES");
7979
cipher.init(Cipher.ENCRYPT_MODE, decryptionKey);
8080
byte[] cipherText = cipher.doFinal(password.getBytes("UTF-8"));
81-
StringBuffer buf = new StringBuffer();
81+
StringBuilder buf = new StringBuilder();
8282
for (int i = 0; i != cipherText.length; i++) {
8383
int v = cipherText[i] & 0xff;
8484
buf.append(DIGITS.charAt(v >> 4));
@@ -92,16 +92,17 @@ public static String encodePassword(String password) throws
9292
* @param args arguments passed through JNLP
9393
* @return the Authentication object
9494
*/
95-
public static AuthenticationInfo extractAuthenticationInfo(String login,
96-
String encodedPassword) {
95+
public static AuthenticationInfo extractAuthenticationInfo(String login, String encodedPassword) {
9796
String clearPwd = null;
97+
String decodedLogin = login;
9898
try {
9999
clearPwd = decodePassword(encodedPassword);
100+
decodedLogin = URLDecoder.decode(login, "UTF-8");
100101
} catch (Exception e) {
101-
Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE,
102-
"can't retrieve credentials", e);
102+
Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, "can't retrieve credentials", e);
103103
System.exit(-1);
104104
}
105-
return new AuthenticationInfo(login, clearPwd);
105+
106+
return new AuthenticationInfo(decodedLogin, clearPwd);
106107
}
107108
}

src/main/java/com/silverpeas/openoffice/windows/FileWebDavAccessManager.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public class FileWebDavAccessManager {
4545
private String userName;
4646
private String password;
4747
private String lockToken = null;
48-
static Logger logger = Logger.getLogger(
49-
FileWebDavAccessManager.class.getName());
48+
static Logger logger = Logger.getLogger(FileWebDavAccessManager.class.getName());
5049

5150
/**
5251
* The AccessManager is inited with authentication info to avoid login prompt
@@ -69,11 +68,11 @@ public String retrieveFile(String url) throws HttpException, IOException {
6968
WebdavManager webdav = new WebdavManager(uri.getHost(), userName, password);
7069
// Let's lock the file
7170
lockToken = webdav.lockFile(uri, userName);
72-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.locked") + ' '
73-
+ lockToken);
71+
logger.log(Level.INFO, "{0}{1}{2}", new Object[]{MessageUtil.getMessage("info.webdav.locked"),
72+
' ', lockToken});
7473
String tmpFile = webdav.getFile(uri, lockToken);
75-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.file.locally.saved") + ' '
76-
+ tmpFile);
74+
logger.log(Level.INFO, "{0}{1}{2}", new Object[]{MessageUtil.getMessage(
75+
"info.webdav.file.locally.saved"), ' ', tmpFile});
7776
return tmpFile;
7877
}
7978

@@ -88,11 +87,9 @@ public void pushFile(String tmpFilePath, String url) throws HttpException,
8887
IOException {
8988
URI uri = getURI(url);
9089
WebdavManager webdav = new WebdavManager(uri.getHost(), userName, password);
91-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.put")
92-
+ ' ' + tmpFilePath);
90+
logger.log(Level.INFO, "{0}{1}{2}", new Object[]{MessageUtil.getMessage("info.webdav.put"), ' ', tmpFilePath});
9391
webdav.putFile(uri, tmpFilePath, lockToken);
94-
logger.log(Level.INFO, MessageUtil.getMessage("info.webdav.unlocking")
95-
+ ' ' + uri.getEscapedURI());
92+
logger.log(Level.INFO, "{0}{1}{2}", new Object[]{MessageUtil.getMessage("info.webdav.unlocking"), ' ', uri.getEscapedURI()});
9693
// Let's unlock the file
9794
webdav.unlockFile(uri, lockToken);
9895
// delete temp file

src/main/java/com/silverpeas/openoffice/windows/webdav/WebdavManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public WebdavManager(String host, String login, String password) {
8484
connectionParams.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
8585
connectionManager.setParams(connectionParams);
8686
HttpClientParams clientParams = new HttpClientParams();
87-
clientParams.setParameter(HttpClientParams.CREDENTIAL_CHARSET, "ISO-8859-1");
87+
clientParams.setParameter(HttpClientParams.CREDENTIAL_CHARSET, "UTF-8");
8888
clientParams.setParameter(HttpClientParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
8989
client = new HttpClient(clientParams, connectionManager);
9090
Credentials creds = new UsernamePasswordCredentials(login, password);

src/test/java/com/silverpeas/openoffice/util/PasswordManagerTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
* You should have received a copy of the GNU Affero General Public License
2222
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
*/
24-
25-
/*
26-
* To change this template, choose Tools | Templates
27-
* and open the template in the editor.
28-
*/
29-
3024
package com.silverpeas.openoffice.util;
3125

3226
import com.silverpeas.openoffice.AuthenticationInfo;
@@ -37,7 +31,7 @@
3731
* @author ehugonnet
3832
*/
3933
public class PasswordManagerTest extends TestCase {
40-
34+
4135
public PasswordManagerTest(String testName) {
4236
super(testName);
4337
}
@@ -84,12 +78,16 @@ public void testEncodePassword() throws Exception {
8478
* Test of extractAuthenticationInfo method, of class PasswordManager.
8579
*/
8680
public void testExtractAuthenticationInfo() {
87-
System.out.println("extractAuthenticationInfo");
8881
String login = "bart";
8982
String encodedPassword = "5f6b7130460e9b316ca968ec952d3fa3";
9083
AuthenticationInfo expResult = new AuthenticationInfo("bart", "helloworld");
91-
AuthenticationInfo result =
92-
PasswordManager.extractAuthenticationInfo(login, encodedPassword);
84+
AuthenticationInfo result = PasswordManager.extractAuthenticationInfo(login, encodedPassword);
85+
assertEquals(expResult, result);
86+
87+
login = "homer%40simpson.com";
88+
encodedPassword = "046e010f9c0cfaa5";
89+
expResult = new AuthenticationInfo("homer@simpson.com", "homer");
90+
result = PasswordManager.extractAuthenticationInfo(login, encodedPassword);
9391
assertEquals(expResult, result);
9492
}
9593

0 commit comments

Comments
 (0)