=== modified file 'dhis-2/dhis-services/dhis-service-core/pom.xml' --- dhis-2/dhis-services/dhis-service-core/pom.xml 2015-09-15 13:38:27 +0000 +++ dhis-2/dhis-services/dhis-service-core/pom.xml 2015-10-03 10:58:10 +0000 @@ -54,10 +54,6 @@ - commons-codec - commons-codec - - org.apache.commons commons-email === modified file 'dhis-2/dhis-support/dhis-support-commons/pom.xml' --- dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-10-01 13:57:42 +0000 +++ dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-10-03 10:58:10 +0000 @@ -28,10 +28,6 @@ commons-lang3 - commons-codec - commons-codec - - org.apache.commons commons-jexl === modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/CodecUtils.java' --- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/CodecUtils.java 2015-10-01 13:14:27 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/CodecUtils.java 2015-10-03 10:58:10 +0000 @@ -1,5 +1,7 @@ package org.hisp.dhis.commons.util; +import java.util.Base64; + /* * Copyright (c) 2004-2015, University of Oslo * All rights reserved. @@ -28,11 +30,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.codec.binary.Base64; - /** * Utility class for encoding and decoding operations. * @@ -40,67 +37,7 @@ */ public class CodecUtils { - private static final String EMPTY_REPLACEMENT = "_"; - private static final String REGEX_NUMERIC = "([0-9]*)"; - private static final String SEPARATOR = "_"; - private static final String ILLEGAL_FILENAME_CHARS_REGEX = "[/\\?%*:|\"'<>.]"; - - /** - * Database encodes the argument string. Remove non-character data from the - * string, prefixes the string if it starts with a numeric character and - * truncates the string if it is longer than 255 characters. - * - * @param string the string to encode. - * @return encoded string. - */ - public static String databaseEncode( String string ) - { - if ( string != null ) - { - string = string.toLowerCase(); - - string = string.replaceAll( " ", EMPTY_REPLACEMENT ); - string = string.replaceAll( "<", EMPTY_REPLACEMENT + "lt" + EMPTY_REPLACEMENT ); - string = string.replaceAll( ">", EMPTY_REPLACEMENT + "gt" + EMPTY_REPLACEMENT ); - string = string.replaceAll( "default", "_default" ); - - StringBuffer buffer = new StringBuffer(); - - Pattern pattern = Pattern.compile( "[a-zA-Z0-9_]" ); - - Matcher matcher = pattern.matcher( string ); - - while ( matcher.find() ) - { - buffer.append( matcher.group() ); - } - - string = buffer.toString(); - - string = string.replaceAll( EMPTY_REPLACEMENT + "+", EMPTY_REPLACEMENT ); - - // ----------------------------------------------------------------- - // Cannot start with numeric character - // ----------------------------------------------------------------- - - if ( string.length() > 0 && string.substring( 0, 1 ).matches( REGEX_NUMERIC ) ) - { - string = SEPARATOR + string; - } - - // ----------------------------------------------------------------- - // Cannot be longer than 255 characters - // ----------------------------------------------------------------- - - if ( string.length() > 255 ) - { - string = string.substring( 0, 255 ); - } - } - - return string; - } /** * Encodes the given string by removing chars which are illegal on most file @@ -134,10 +71,8 @@ */ public static String getBasicAuthString( String username, String password ) { - //TODO replace with Java 8 Base64 - String string = username + ":" + password; - return "Basic " + Base64.encodeBase64String( string.getBytes() ); + return "Basic " + Base64.getEncoder().encodeToString( string.getBytes() ); } } === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/CodeUtilsTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/CodeUtilsTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/CodeUtilsTest.java 2015-10-03 10:58:10 +0000 @@ -0,0 +1,52 @@ +package org.hisp.dhis.commons.util; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Lars Helge Overland + */ +public class CodeUtilsTest +{ + @Test + public void testFilenameEncode() + { + assertEquals( "nicechart", CodecUtils.filenameEncode( "nicechart" ) ); + } + + @Test + public void test() + { + assertEquals( "Basic am9objpkb2UxMjM=", CodecUtils.getBasicAuthString( "john", "doe123" ) ); + assertEquals( "Basic YWRtaW46ZGlzdHJpY3Q=", CodecUtils.getBasicAuthString( "admin", "district" ) ); + } +} === modified file 'dhis-2/pom.xml' --- dhis-2/pom.xml 2015-10-02 11:27:19 +0000 +++ dhis-2/pom.xml 2015-10-03 10:58:10 +0000 @@ -677,11 +677,6 @@ 1.3.1 - commons-codec - commons-codec - 1.10 - - org.apache.commons commons-math3 3.4.1