From b4df85573f5f6e048623b788bdc98943d607d225 Mon Sep 17 00:00:00 2001 From: Will Abson Date: Wed, 25 Jun 2014 16:06:44 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud) 73684: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 73483: Merged DEV to V4.2-BUG-FIX (4.2.3) 72998 : MNT-11359 : Cmis operations randomly fail with internal server error - Create CharsetDecoder on demand git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74799 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../webdav/auth/AuthenticationFilter.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/source/java/org/alfresco/repo/webdav/auth/AuthenticationFilter.java b/source/java/org/alfresco/repo/webdav/auth/AuthenticationFilter.java index f4624c708a..c5130dfa1a 100644 --- a/source/java/org/alfresco/repo/webdav/auth/AuthenticationFilter.java +++ b/source/java/org/alfresco/repo/webdav/auth/AuthenticationFilter.java @@ -27,6 +27,7 @@ import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -67,28 +68,23 @@ public class AuthenticationFilter extends BaseAuthenticationFilter implements De private static final String PPT_EXTN = ".ppt"; /** The password encodings to try in priority order **/ - private static final String[] ENCODINGS = new String[] { - "UTF-8", - System.getProperty("file.encoding"), - "ISO-8859-1" - }; - - /** Corresponding array of CharsetDecoders with CodingErrorAction.REPORT. Duplicates removed. */ - private static final CharsetDecoder[] DECODERS; + private static final String[] ENCODINGS; static { - Map decoders = new LinkedHashMap(ENCODINGS.length * 2); - for (String encoding : ENCODINGS) + String[] encodings = new String[] { + "UTF-8", + System.getProperty("file.encoding"), + "ISO-8859-1" + }; + + Set encodingsSet = new LinkedHashSet(); + for (String encoding : encodings) { - if (!decoders.containsKey(encoding)) - { - decoders.put(encoding, Charset.forName(encoding).newDecoder() - .onMalformedInput(CodingErrorAction.REPORT)); - } + encodingsSet.add(encoding); } - DECODERS = new CharsetDecoder[decoders.size()]; - decoders.values().toArray(DECODERS); + ENCODINGS = new String[encodingsSet.size()]; + encodingsSet.toArray(ENCODINGS); } // Various services required by NTLM authenticator @@ -132,9 +128,11 @@ public class AuthenticationFilter extends BaseAuthenticationFilter implements De byte[] encodedString = Base64.decodeBase64(authHdr.substring(5).getBytes()); // ALF-13621: Due to browser inconsistencies we have to try a fallback path of encodings - Set attemptedAuths = new HashSet(DECODERS.length * 2); - for (CharsetDecoder decoder : DECODERS) - { + Set attemptedAuths = new HashSet(ENCODINGS.length * 2); + for (String encoding : ENCODINGS) + { + CharsetDecoder decoder = Charset.forName(encoding).newDecoder() + .onMalformedInput(CodingErrorAction.REPORT); try { // Attempt to decode using this charset