Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed Jun 4, 2018
2 parents 9a2deab + 9b4076c commit c9e086a
Show file tree
Hide file tree
Showing 17 changed files with 549 additions and 151 deletions.
4 changes: 2 additions & 2 deletions norconex-commons-lang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.norconex.commons</groupId>
<artifactId>norconex-commons-lang</artifactId>
<version>1.14.0</version>
<version>1.15.0</version>
<packaging>jar</packaging>
<name>Norconex Commons Lang</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<site.baseurl/>
<currentStableVersion>1.14.0</currentStableVersion>
<currentStableVersion>1.15.0</currentStableVersion>

<commons-lang3.version>3.6</commons-lang3.version>
<commons-configuration.version>1.10</commons-configuration.version>
Expand Down
20 changes: 20 additions & 0 deletions norconex-commons-lang/src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
</properties>
<body>

<release version="1.15.0" date="2018-06-03" description="Feature release">
<action dev="davisda4,essiembre" type="add">
New EncryptionXMLUtil class offering methods to facilitate integration
of EncryptionKey with IXMLConfigurable objects (or other XML objects).
</action>
<action dev="davisda4" type="update">
EncryptionUtil now uses AES for encryption and supports custom key size.
</action>
<action dev="essiembre" type="update">
ConfigurationLoader now sets the Velocity character encoding to UTF-8.
</action>
<action dev="essiembre" type="update">
HttpURL now extract protocols before first colon, no longer requiring
two forward slash. Also more lenient towards relative URLs.
</action>
<action dev="essiembre" type="update">
QueryString now strips out fragments when part of a URL.
</action>
</release>

<release version="1.14.0" date="2017-11-26" description="Feature release">
<action dev="essiembre" type="add">
Can now store and load Properties file as JSON.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2010-2016 Norconex Inc.
/* Copyright 2010-2018 Norconex Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,7 +42,6 @@
*
* @author Pascal Essiembre
*/
@SuppressWarnings("nls")
public final class ClassFinder {

private static final Logger LOG = Logger.getLogger(ClassFinder.class);
Expand Down Expand Up @@ -127,8 +126,7 @@ public static List<String> findSubTypes(
return new ArrayList<>();
}
if (file.isDirectory()) {
return findSubTypesFromDirectory(
new File(file.getAbsolutePath() + "/"), superClass);
return findSubTypesFromDirectory(file, superClass);
}
if (file.getName().endsWith(".jar")) {
return findSubTypesFromJar(file, superClass);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2010-2014 Norconex Inc.
/* Copyright 2010-2018 Norconex Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,6 @@
*
* @author Pascal Essiembre
*/
@SuppressWarnings("nls")
public final class Sleeper {

/** Number of milliseconds representing 1 second. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2017 Norconex Inc.
/* Copyright 2017-2018 Norconex Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -110,9 +110,11 @@ public static String truncateWithHash(
* For this reason, the <code>maxByteLength</code> argument must be
* be large enough for any truncation to occur.
* @param text text to truncate
* @param charset character encoding
* @param maxByteLength maximum byte length the truncated text must have
* @return truncated character byte array, or original text if no
* truncation required
* @throws CharacterCodingException character coding problem
*/
public static String truncateBytesWithHash(String text,
Charset charset, int maxByteLength)
Expand All @@ -135,10 +137,12 @@ public static String truncateBytesWithHash(String text,
* For this reason, the <code>maxByteLength</code> argument must be
* be large enough for any truncation to occur.
* @param text text to truncate
* @param charset character encoding
* @param maxByteLength maximum byte length the truncated text must have
* @param separator string separating truncated text from hash code
* @return truncated character byte array, or original text if no
* truncation required
* @throws CharacterCodingException character coding problem
*/
public static String truncateBytesWithHash(String text,
Charset charset, int maxByteLength, String separator)
Expand All @@ -161,9 +165,11 @@ public static String truncateBytesWithHash(String text,
* For this reason, the <code>maxByteLength</code> argument must be
* be large enough for any truncation to occur.
* @param bytes byte array of text to truncate
* @param charset character encoding
* @param maxByteLength maximum byte length the truncated text must have
* @return truncated character byte array, or original text if no
* truncation required
* @throws CharacterCodingException character coding problem
*/
public static byte[] truncateBytesWithHash(
byte[] bytes, Charset charset, int maxByteLength)
Expand All @@ -184,10 +190,12 @@ public static byte[] truncateBytesWithHash(
* For this reason, the <code>maxByteLength</code> argument must be
* be large enough for any truncation to occur.
* @param bytes byte array of text to truncate
* @param charset character encoding
* @param maxByteLength maximum byte length the truncated text must have
* @param separator string separating truncated text from hash code
* @return truncated character byte array, or original text if no
* truncation required
* @throws CharacterCodingException character coding problem
*/
public static byte[] truncateBytesWithHash(
byte[] bytes, Charset charset, int maxByteLength, String separator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
* </p>
* @author Pascal Essiembre
*/
@SuppressWarnings("nls")
public final class ConfigurationLoader {

private static final String EXTENSION_PROPERTIES = ".properties";
Expand All @@ -139,6 +138,8 @@ public ConfigurationLoader() {
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
velocityEngine.setProperty(
RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "");
velocityEngine.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
velocityEngine.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8");
velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
"org.apache.velocity.runtime.log.Log4JLogChute");
velocityEngine.setProperty("runtime.log", "");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2015-2016 Norconex Inc.
/* Copyright 2015-2018 Norconex Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,8 @@
import java.nio.file.Paths;

/**
* Pointer to the an encryption key, or the encryption key itself. An
* encryption key can be seen as equivalent to a secret key,
* Pointer to the an encryption key, or the encryption key itself. An
* encryption key can be seen as equivalent to a secret key,
* passphrase or password.
* @author Pascal Essiembre
* @since 1.9.0
Expand All @@ -33,52 +33,89 @@ public class EncryptionKey implements Serializable {

private static final long serialVersionUID = 1L;

public enum Source {
public static final int DEFAULT_KEY_SIZE = 128;

public enum Source {
/** Value is the actual key. */
KEY,
KEY,
/** Value is the path to a file containing the key. */
FILE,
FILE,
/** Value is the name of an environment variable containing the key. */
ENVIRONMENT,
ENVIRONMENT,
/** Value is the name of a JVM system property containing the key. */
PROPERTY
}

private final String value;
private final Integer size;
private final Source source;

/**
* Creates a new reference to an encryption key. The reference can either
* Creates a new reference to an encryption key. The reference can either
* be the key itself, or a pointer to a file or environment variable
* containing the key (as defined by the supplied value type).
* containing the key (as defined by the supplied value type). The actual
* value can be any sort of string, and it is converted to an encryption
* key of length size using cryptographic algorithms. If the size is
* specified, it must be supported by your version of Java.
*
* @param value the encryption key
* @param size the size in bits of the encryption key
* @param source the type of value
*/
public EncryptionKey(String value, Source source) {
public EncryptionKey(String value, Source source, int size) {
super();
this.value = value;
this.source = source;
this.size = size;
}
/**
* Creates a new reference to an encryption key. The reference can either
* be the key itself, or a pointer to a file or environment variable
* containing the key (as defined by the supplied value type).
* @param value the encryption key
* @param source the type of value
*/
public EncryptionKey(String value, Source source) {
this(value, source, DEFAULT_KEY_SIZE);
}
/**
* Creates a new encryption key where the value is the actual key, and the
* number of key bits to generate is the size.
* @param value the encrption key
* @param size the encryption key size in bits
*/
public EncryptionKey(String value, int size) {
this(value, Source.KEY, size);
}
/**
* Creates a new encryption key where the value is the actual key.
* @param value the encryption key
*/
public EncryptionKey(String value) {
this(value, Source.KEY);
this(value, Source.KEY, DEFAULT_KEY_SIZE);
}
public String getValue() {
return value;
}
public Source getSource() {
return source;
}
/**
* Gets the size in bits of the encryption key. Default is
* {@value #DEFAULT_KEY_SIZE}.
* @return size in bits of the encryption key
* @since 1.15.0
*/
public int getSize() {
return (size != null ? size : DEFAULT_KEY_SIZE);
}

/**
* Locate the key according to its value type and return it. This
* method will always resolve the value each type it is invoked and
* Locate the key according to its value type and return it. This
* method will always resolve the value each type it is invoked and
* never caches the key, unless the key value specified at construction
* time is the actual key.
* @return encryption key or <code>null</code> if the key does not exist
* @return encryption key or <code>null</code> if the key does not exist
* for the specified type
*/
public String resolve() {
Expand All @@ -101,12 +138,12 @@ public String resolve() {
return null;
}
}

private String fromEnv() {
//TODO allow a flag to optionally throw an exception when null?
return System.getenv(value);
}

private String fromProperty() {
//TODO allow a flag to optionally throw an exception when null?
return System.getProperty(value);
Expand All @@ -128,7 +165,7 @@ private String fromFile() {
"Could not read key file.", e);
}
}

//Do not use Apache Commons Lang below to avoid any dependency
//when used on command-line with EncryptionUtil.
@Override
Expand All @@ -137,6 +174,7 @@ public int hashCode() {
int result = 1;
result = prime * result + ((source == null) ? 0 : source.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
result = prime * result + size;
return result;
}
@Override
Expand All @@ -161,10 +199,18 @@ public boolean equals(Object obj) {
} else if (!value.equals(other.value)) {
return false;
}
if (size == null) {
if (other.size != null) {
return false;
}
} else if (!size.equals(other.size)) {
return false;
}
return true;
}
@Override
public String toString() {
return "EncryptionKey [value=" + value + ", source=" + source + "]";
}
return "EncryptionKey [value=" + value
+ ", source=" + source + ", size=" + size + "]";
}
}
Loading

0 comments on commit c9e086a

Please sign in to comment.