Merge remote-tracking branch 'eclipse/master' into cleanup-properties

# Conflicts:
#
hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpProperties.j
ava
This commit is contained in:
Kai Zimmermann
2016-03-04 12:11:35 +01:00
53 changed files with 1321 additions and 828 deletions

View File

@@ -15,7 +15,6 @@ import java.util.concurrent.Callable;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.TenantAware.TenantRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,8 +29,7 @@ import org.springframework.stereotype.Service;
import com.google.common.base.Throwables;
/**
* @author Michael Hirsch
*
*
*/
@Service
public class SystemSecurityContext {
@@ -45,15 +43,12 @@ public class SystemSecurityContext {
final SecurityContext oldContext = SecurityContextHolder.getContext();
try {
logger.debug("entering system code execution");
return tenantAware.runAsTenant(tenantAware.getCurrentTenant(), new TenantRunner<T>() {
@Override
public T run() {
try {
setSystemContext();
return callable.call();
} catch (final Exception e) {
throw Throwables.propagate(e);
}
return tenantAware.runAsTenant(tenantAware.getCurrentTenant(), () -> {
try {
setSystemContext();
return callable.call();
} catch (final Exception e) {
throw Throwables.propagate(e);
}
});
@@ -106,7 +101,8 @@ public class SystemSecurityContext {
}
@Override
public void setAuthenticated(final boolean isAuthenticated) throws IllegalArgumentException {
public void setAuthenticated(final boolean isAuthenticated) {
// not needed
}
}
}

View File

@@ -20,9 +20,6 @@ import com.google.common.net.HttpHeaders;
/**
* A utility which determines the correct IP of a connected {@link Target}. E.g
* from a {@link HttpServletRequest}.
*
*
*
*
*/
public final class IpUtil {
@@ -95,7 +92,6 @@ public final class IpUtil {
if (isIpV6) {
return URI.create(scheme + SCHEME_SEPERATOR + "[" + host + "]");
}
return URI.create(scheme + SCHEME_SEPERATOR + host);
}
@@ -104,12 +100,14 @@ public final class IpUtil {
*
* @param host
* the host
* @param exchange
* the exchange will store in the path
* @return the {@link URI}
* @throws IllegalArgumentException
* If the given string not parsable
*/
public static URI createAmqpUri(final String host) {
return createUri(AMPQP_SCHEME, host);
public static URI createAmqpUri(final String host, final String exchange) {
return createUri(AMPQP_SCHEME, host).resolve("/" + exchange);
}
/**

View File

@@ -56,7 +56,8 @@ public class ExcludePathAwareShallowETagFilterTest {
filterUnderTest.doFilterInternal(servletRequestMock, servletResponseMock, filterChainMock);
// verify no eTag header is set and response has not been changed
assertThat(servletResponseMock.getHeader("ETag")).isNull();
assertThat(servletResponseMock.getHeader("ETag"))
.as("ETag header should not be set during downloading, too expensive").isNull();
// the servlet response must be the same mock!
verify(filterChainMock, times(1)).doFilter(servletRequestMock, servletResponseMock);
}

View File

@@ -53,7 +53,8 @@ public class IpUtilTest {
final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "bumlux");
// verify
assertThat(remoteAddr).isEqualTo(knownRemoteClientIP);
assertThat(remoteAddr).as("The remote address should be as the known client IP address")
.isEqualTo(knownRemoteClientIP);
verify(requestMock, times(1)).getHeader("bumlux");
verify(requestMock, times(1)).getRemoteAddr();
}
@@ -71,7 +72,8 @@ public class IpUtilTest {
final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "X-Forwarded-For");
// verify
assertThat(remoteAddr).isEqualTo(knownRemoteClientIP);
assertThat(remoteAddr).as("The remote address should be as the known client IP address")
.isEqualTo(knownRemoteClientIP);
verify(requestMock, times(1)).getHeader(HttpHeaders.X_FORWARDED_FOR);
verify(requestMock, times(0)).getRemoteAddr();
}
@@ -94,45 +96,50 @@ public class IpUtilTest {
}
private void assertHttpUri(final String host, final URI httpUri) {
assertTrue(IpUtil.isHttpUri(httpUri));
assertFalse(IpUtil.isAmqpUri(httpUri));
assertEquals(host, httpUri.getHost());
assertEquals("http", httpUri.getScheme());
assertTrue("The given URI has an http scheme", IpUtil.isHttpUri(httpUri));
assertFalse("The given URI is not an AMQP scheme", IpUtil.isAmqpUri(httpUri));
assertEquals("The URI hosts matches the given host", host, httpUri.getHost());
assertEquals("The given URI scheme is http", "http", httpUri.getScheme());
}
@Test
@Description("Tests create amqp uri ipv4 and ipv6")
public void testCreateAmqpUri() {
final String ipv4 = "10.99.99.1";
URI amqpUri = IpUtil.createAmqpUri(ipv4);
URI amqpUri = IpUtil.createAmqpUri(ipv4, "path");
assertAmqpUri(ipv4, amqpUri);
final String host = "myhost";
amqpUri = IpUtil.createAmqpUri(host);
amqpUri = IpUtil.createAmqpUri(host, "path");
assertAmqpUri(host, amqpUri);
final String ipv6 = "0:0:0:0:0:0:0:1";
amqpUri = IpUtil.createAmqpUri(ipv6);
amqpUri = IpUtil.createAmqpUri(ipv6, "path");
assertAmqpUri("[" + ipv6 + "]", amqpUri);
}
private void assertAmqpUri(final String host, final URI httpUri) {
assertTrue(IpUtil.isAmqpUri(httpUri));
assertFalse(IpUtil.isHttpUri(httpUri));
assertEquals(host, httpUri.getHost());
assertEquals("amqp", httpUri.getScheme());
private void assertAmqpUri(final String host, final URI amqpUri) {
assertTrue("The given URI is an AMQP scheme", IpUtil.isAmqpUri(amqpUri));
assertFalse("The given URI is not an HTTP scheme", IpUtil.isHttpUri(amqpUri));
assertEquals("The given host matches the URI host", host, amqpUri.getHost());
assertEquals("The given URI has an AMQP scheme", "amqp", amqpUri.getScheme());
assertEquals("The given URI has an AMQP path", "/path", amqpUri.getRawPath());
}
@Test(expected = IllegalArgumentException.class)
@Test
@Description("Tests create invalid uri")
public void testCreateInvalidUri() {
final String host = "10.99.99.1";
final URI testUri = IpUtil.createUri("test", host);
assertFalse(IpUtil.isAmqpUri(testUri));
assertFalse(IpUtil.isHttpUri(testUri));
assertEquals(host, testUri.getHost());
IpUtil.createUri(":/", host);
fail();
assertFalse("The given URI is not an AMQP address", IpUtil.isAmqpUri(testUri));
assertFalse("The given URI is not an HTTP address", IpUtil.isHttpUri(testUri));
assertEquals("The given host matches the URI host", host, testUri.getHost());
try {
IpUtil.createUri(":/", host);
fail("Missing expected IllegalArgumentException due invalid URI");
} catch (final IllegalArgumentException e) {
// expected
}
}
}