ARTEMIS-801 Decode URL paths

If the path to file contains some special characters, they are encoded
in URL form using %<hex> syntax. We should decode such path when it
is used as path to file on local filesystem.
This commit is contained in:
Erich Duda 2016-10-14 09:03:22 +02:00 committed by Clebert Suconic
parent e53aaf398e
commit c183ed9cc1
3 changed files with 39 additions and 6 deletions

View File

@ -23,22 +23,33 @@ import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal;
import org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal;
import org.jboss.logging.Logger;
import org.junit.Assert;
import org.junit.Test;
public class GuestLoginModuleTest extends Assert {
private static final Logger logger = Logger.getLogger(GuestLoginModuleTest.class);
static {
String path = System.getProperty("java.security.auth.login.config");
if (path == null) {
URL resource = GuestLoginModuleTest.class.getClassLoader().getResource("login.config");
if (resource != null) {
path = resource.getFile();
System.setProperty("java.security.auth.login.config", path);
try {
path = URLDecoder.decode(resource.getFile(), StandardCharsets.UTF_8.name());
System.setProperty("java.security.auth.login.config", path);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
}
}

View File

@ -27,23 +27,34 @@ import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal;
import org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal;
import org.apache.commons.io.FileUtils;
import org.jboss.logging.Logger;
import org.junit.Assert;
import org.junit.Test;
public class PropertiesLoginModuleTest extends Assert {
private static final Logger logger = Logger.getLogger(PropertiesLoginModuleTest.class);
static {
String path = System.getProperty("java.security.auth.login.config");
if (path == null) {
URL resource = PropertiesLoginModuleTest.class.getClassLoader().getResource("login.config");
if (resource != null) {
path = resource.getFile();
System.setProperty("java.security.auth.login.config", path);
try {
path = URLDecoder.decode(resource.getFile(), StandardCharsets.UTF_8.name());
System.setProperty("java.security.auth.login.config", path);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
}
}

View File

@ -20,7 +20,10 @@ import javax.management.remote.JMXPrincipal;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import javax.security.cert.X509Certificate;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
@ -28,12 +31,15 @@ import org.apache.activemq.artemis.spi.core.security.jaas.CertificateLoginModule
import org.apache.activemq.artemis.spi.core.security.jaas.JaasCallbackHandler;
import org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoader;
import org.apache.activemq.artemis.spi.core.security.jaas.TextFileCertificateLoginModule;
import org.jboss.logging.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TextFileCertificateLoginModuleTest {
private static final Logger logger = Logger.getLogger(TextFileCertificateLoginModuleTest.class);
private static final String CERT_USERS_FILE_SMALL = "cert-users-SMALL.properties";
private static final String CERT_USERS_FILE_LARGE = "cert-users-LARGE.properties";
private static final String CERT_GROUPS_FILE = "cert-roles.properties";
@ -45,8 +51,13 @@ public class TextFileCertificateLoginModuleTest {
if (path == null) {
URL resource = TextFileCertificateLoginModuleTest.class.getClassLoader().getResource("login.config");
if (resource != null) {
path = resource.getFile();
System.setProperty("java.security.auth.login.config", path);
try {
path = URLDecoder.decode(resource.getFile(), StandardCharsets.UTF_8.name());
System.setProperty("java.security.auth.login.config", path);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
}
}