Removed the method exception from transaction manager as they where not

needed anymore. The bean in systemmanagement should also not open a
transaction.

Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-04-25 14:09:38 +02:00
parent cf8e4fd2fd
commit 6e85c724bf
3 changed files with 17 additions and 18 deletions

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit;
import javax.persistence.EntityManager;
import javax.transaction.Transaction;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.persistence.config.PersistenceUnitProperties;
@@ -37,11 +36,6 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager {
protected void doBegin(final Object transaction, final TransactionDefinition definition) {
super.doBegin(transaction, definition);
// ignore transactions on tenant independent calls
if (isTenantManagement(definition) || isCurrentTenantKeyGenerator(definition)) {
return;
}
final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager
.getResource(getEntityManagerFactory());
final EntityManager em = emHolder.getEntityManager();
@@ -54,14 +48,4 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager {
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
}
private boolean isCurrentTenantKeyGenerator(final TransactionDefinition definition) {
return definition.getName()
.startsWith(SystemManagement.class.getCanonicalName() + ".currentTenantKeyGenerator");
}
private boolean isTenantManagement(final TransactionDefinition definition) {
return definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".deleteTenant")
&& !definition.getName().startsWith(SystemManagement.class.getCanonicalName() + ".findTenants");
}
}

View File

@@ -164,6 +164,7 @@ public class SystemManagement {
* @return the {@link CurrentTenantKeyGenerator}
*/
@Bean
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public CurrentTenantKeyGenerator currentTenantKeyGenerator() {
return new CurrentTenantKeyGenerator();
}
@@ -206,7 +207,6 @@ public class SystemManagement {
@NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
// tenant independent
public List<String> findTenants() {
return tenantMetaDataRepository.findAll().stream().map(md -> md.getTenant()).collect(Collectors.toList());
}
@@ -221,7 +221,6 @@ public class SystemManagement {
@Transactional
@Modifying
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
// tenant independent
public void deleteTenant(@NotNull final String tenant) {
cacheManager.evictCaches(tenant);
cacheManager.getCache("currentTenant").evict(currentTenantKeyGenerator().generate(null, null));

View File

@@ -78,6 +78,22 @@ public class MultiTenancyEntityTest extends AbstractIntegrationTest {
assertThat(findTargetsForTenant).hasSize(1);
}
@Test
@Description(value = "Ensures that tenant with proper permissions can read and delete other tenants.")
@WithUser(tenantId = "mytenant", allSpPermissions = true)
public void deleteAnotherTenantPossible() throws Exception {
// create target for another tenant
final String anotherTenant = "anotherTenant";
final String controllerAnotherTenant = "anotherController";
createTargetForTenant(controllerAnotherTenant, anotherTenant);
assertThat(systemManagement.findTenants()).as("Expected number if tenants before deletion is").hasSize(3);
systemManagement.deleteTenant(anotherTenant);
assertThat(systemManagement.findTenants()).as("Expected number if tenants after deletion is").hasSize(2);
}
@Test
@Description(value = "Ensures that tenant metadata is retrieved for the current tenant.")
@WithUser(tenantId = "mytenant", autoCreateTenant = false, allSpPermissions = true)