Fix criticals sonar issues
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -14,7 +14,7 @@ import java.net.ServerSocket;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Look for a free port.
|
||||
*/
|
||||
public class FreePortFileWriter {
|
||||
|
||||
@@ -24,7 +24,9 @@ public class FreePortFileWriter {
|
||||
|
||||
/**
|
||||
* @param from
|
||||
* port range from (start point)
|
||||
* @param to
|
||||
* port range to (end point)
|
||||
*/
|
||||
public FreePortFileWriter(final int from, final int to, final String filePortPath) {
|
||||
this.from = from;
|
||||
@@ -51,23 +53,20 @@ public class FreePortFileWriter {
|
||||
portFile.getParentFile().mkdirs();
|
||||
if (portFile.exists()) {
|
||||
return false;
|
||||
} else {
|
||||
boolean isFree = false;
|
||||
final ServerSocket sock = new ServerSocket();
|
||||
sock.setReuseAddress(true);
|
||||
sock.bind(new InetSocketAddress(port));
|
||||
if (portFile.createNewFile()) {
|
||||
portFile.deleteOnExit();
|
||||
isFree = true;
|
||||
}
|
||||
sock.close();
|
||||
// is free:
|
||||
return isFree;
|
||||
// We rely on an exception thrown to determine availability or
|
||||
// not availability.
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
// not free.
|
||||
boolean isFree = false;
|
||||
final ServerSocket sock = new ServerSocket();
|
||||
sock.setReuseAddress(true);
|
||||
sock.bind(new InetSocketAddress(port));
|
||||
if (portFile.createNewFile()) {
|
||||
portFile.deleteOnExit();
|
||||
isFree = true;
|
||||
}
|
||||
sock.close();
|
||||
return isFree;
|
||||
// We rely on an exception thrown to determine availability or
|
||||
// not availability and don't want to log the exception.
|
||||
} catch (@SuppressWarnings({ "squid:S2221", "squid:S1166" }) final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
createTestdatabaseAndStart();
|
||||
}
|
||||
|
||||
private static void createTestdatabaseAndStart() {
|
||||
private static synchronized void createTestdatabaseAndStart() {
|
||||
if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
|
||||
tesdatabase = new CIMySqlTestDatabase();
|
||||
tesdatabase.before();
|
||||
|
||||
@@ -13,11 +13,14 @@ import java.util.List;
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class JpaTestRepositoryManagement implements TestRepositoryManagement {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class);
|
||||
@Autowired
|
||||
private TenantAwareCacheManager cacheManager;
|
||||
|
||||
@@ -28,6 +31,7 @@ public class JpaTestRepositoryManagement implements TestRepositoryManagement {
|
||||
private SystemManagement systemManagement;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void clearTestRepository() {
|
||||
deleteAllRepos();
|
||||
cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear());
|
||||
@@ -43,7 +47,7 @@ public class JpaTestRepositoryManagement implements TestRepositoryManagement {
|
||||
return null;
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Error hile delete tenant", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ package org.eclipse.hawkbit.repository.test.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -191,16 +191,17 @@ public class TestdataFactory {
|
||||
public DistributionSet createDistributionSet(final String prefix, final String version,
|
||||
final boolean isRequiredMigrationStep) {
|
||||
|
||||
final SoftwareModule appMod = softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule(
|
||||
findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE), prefix + SM_TYPE_APP,
|
||||
version + "." + new Random().nextInt(100), LOREM.words(20), prefix + " vendor Limited, California"));
|
||||
final SoftwareModule appMod = softwareManagement.createSoftwareModule(
|
||||
entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE),
|
||||
prefix + SM_TYPE_APP, version + "." + new SecureRandom().nextInt(100), LOREM.words(20),
|
||||
prefix + " vendor Limited, California"));
|
||||
final SoftwareModule runtimeMod = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_RT),
|
||||
prefix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20),
|
||||
prefix + "app runtime", version + "." + new SecureRandom().nextInt(100), LOREM.words(20),
|
||||
prefix + " vendor GmbH, Stuttgart, Germany"));
|
||||
final SoftwareModule osMod = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_OS),
|
||||
prefix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20),
|
||||
prefix + " Firmware", version + "." + new SecureRandom().nextInt(100), LOREM.words(20),
|
||||
prefix + " vendor Limited Inc, California"));
|
||||
|
||||
return distributionSetManagement
|
||||
|
||||
@@ -28,16 +28,12 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
public class WithSpringAuthorityRule implements TestRule {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.junit.rules.TestRule#apply(org.junit.runners.model.Statement,
|
||||
* org.junit.runner.Description)
|
||||
*/
|
||||
@Override
|
||||
public Statement apply(final Statement base, final Description description) {
|
||||
return new Statement() {
|
||||
@Override
|
||||
// throwable comes from jnuit evaluate signature
|
||||
@SuppressWarnings("squid:S00112")
|
||||
public void evaluate() throws Throwable {
|
||||
final SecurityContext oldContext = before(description);
|
||||
try {
|
||||
@@ -49,7 +45,7 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
};
|
||||
}
|
||||
|
||||
private SecurityContext before(final Description description) throws Throwable {
|
||||
private SecurityContext before(final Description description) {
|
||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||
WithUser annotation = description.getAnnotation(WithUser.class);
|
||||
if (annotation == null) {
|
||||
@@ -63,19 +59,14 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
}
|
||||
return oldContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param annotation
|
||||
*/
|
||||
|
||||
private void setSecurityContext(final WithUser annotation) {
|
||||
SecurityContextHolder.setContext(new SecurityContext() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void setAuthentication(final Authentication authentication) {
|
||||
// nothing todo
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,7 +104,8 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
if (addPermission) {
|
||||
allPermissions.add(permissionName);
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
// don't want to log this exceptions.
|
||||
} catch (@SuppressWarnings("squid:S1166") IllegalArgumentException | IllegalAccessException e) {
|
||||
// nope
|
||||
}
|
||||
}
|
||||
@@ -129,18 +121,17 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
private void after(final SecurityContext oldContext) {
|
||||
SecurityContextHolder.setContext(oldContext);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears the current security context.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
public void clear() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable
|
||||
* @return
|
||||
* @return the callable result
|
||||
* @throws Exception
|
||||
*/
|
||||
public <T> T runAsPrivileged(final Callable<T> callable) throws Exception {
|
||||
@@ -151,7 +142,7 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
*
|
||||
* @param withUser
|
||||
* @param callable
|
||||
* @return
|
||||
* @return callable result
|
||||
* @throws Exception
|
||||
*/
|
||||
public <T> T runAs(final WithUser withUser, final Callable<T> callable) throws Exception {
|
||||
@@ -170,7 +161,7 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
public static WithUser withUser(final String principal, final String... authorities) {
|
||||
return withUserAndTenant(principal, "default", true, true, authorities);
|
||||
}
|
||||
|
||||
|
||||
public static WithUser withUser(final String principal, final boolean allSpPermision, final String... authorities) {
|
||||
return withUserAndTenant(principal, "default", true, allSpPermision, authorities);
|
||||
}
|
||||
@@ -185,6 +176,15 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
|
||||
public static WithUser withUserAndTenant(final String principal, final String tenant,
|
||||
final boolean autoCreateTenant, final boolean allSpPermission, final String... authorities) {
|
||||
return createWithUser(principal, tenant, autoCreateTenant, allSpPermission, authorities);
|
||||
}
|
||||
|
||||
private static WithUser privilegedUser() {
|
||||
return createWithUser("bumlux", "default", true, true, new String[] { "ROLE_CONTROLLER" });
|
||||
}
|
||||
|
||||
private static WithUser createWithUser(final String principal, final String tenant, final boolean autoCreateTenant,
|
||||
final boolean allSpPermission, final String... authorities) {
|
||||
return new WithUser() {
|
||||
|
||||
@Override
|
||||
@@ -214,7 +214,7 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
|
||||
@Override
|
||||
public String[] removeFromAllPermission() {
|
||||
return null;
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,65 +222,10 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.WithUser#autoCreateTenant()
|
||||
*/
|
||||
@Override
|
||||
public boolean autoCreateTenant() {
|
||||
return autoCreateTenant;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static WithUser privilegedUser() {
|
||||
return new WithUser() {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return WithUser.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String principal() {
|
||||
return "bumlux";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String credentials() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] authorities() {
|
||||
return new String[] { "ROLE_CONTROLLER" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allSpPermissions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] removeFromAllPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tenantId() {
|
||||
return "default";
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.WithUser#autoCreateTenant()
|
||||
*/
|
||||
@Override
|
||||
public boolean autoCreateTenant() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
* Abstract class for target/ds tag token layout.
|
||||
*
|
||||
* @param <T>
|
||||
* the special entity
|
||||
*/
|
||||
public abstract class AbstractTagToken<T extends BaseEntity> implements Serializable {
|
||||
|
||||
@@ -75,6 +78,9 @@ public abstract class AbstractTagToken<T extends BaseEntity> implements Serializ
|
||||
@Autowired
|
||||
protected ManagementUIState managementUIState;
|
||||
|
||||
// BaseEntity implements Serializable so this entity is serializable. Maybe
|
||||
// a sonar bug
|
||||
@SuppressWarnings("squid:S1948")
|
||||
protected T selectedEntity;
|
||||
|
||||
@PostConstruct
|
||||
|
||||
Reference in New Issue
Block a user