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