Skip to content

Commit

Permalink
💥 removing unwanted PermissionFactory
Browse files Browse the repository at this point in the history
Signed-off-by: dseurotech <[email protected]>
  • Loading branch information
dseurotech committed Jan 31, 2025
1 parent b2db0da commit d7bac90
Show file tree
Hide file tree
Showing 120 changed files with 687 additions and 1,292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eclipse.kapua.service.KapuaService;
import org.eclipse.kapua.service.account.Account;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
import org.eclipse.kapua.service.config.KapuaConfigurableService;

/**
Expand Down Expand Up @@ -118,8 +117,8 @@ protected AbstractKapuaConfigurableResourceLimitedService(
* The {@link CacheFactory} that handles caching of the entities
* @since 1.2.0
* @deprecated Since 2.0.0. Please use
* {@link #AbstractKapuaConfigurableResourceLimitedService(String, Domain, EntityManagerFactory, EntityCacheFactory, KapuaEntityFactory, PermissionFactory, AuthorizationService,
* AccountRelativeFinder, RootUserTester)} This constructor may be removed in a next release
* {@link #AbstractKapuaConfigurableResourceLimitedService(String, Domain, EntityManagerFactory, EntityCacheFactory, KapuaEntityFactory, AuthorizationService, AccountRelativeFinder,
* RootUserTester)} This constructor may be removed in a next release
*/
@Deprecated
protected AbstractKapuaConfigurableResourceLimitedService(
Expand All @@ -129,7 +128,7 @@ protected AbstractKapuaConfigurableResourceLimitedService(
EntityCacheFactory abstractCacheFactory,
Class<S> serviceClass,
Class<F> factoryClass) {
super(pid, domain, entityManagerFactory, abstractCacheFactory, null, null, null);
super(pid, domain, entityManagerFactory, abstractCacheFactory, null, null);

/*
These should be provided by the Locator, but in most cases when this class is instantiated through this constructor the Locator is not yet ready,
Expand All @@ -153,8 +152,6 @@ protected AbstractKapuaConfigurableResourceLimitedService(
* The {@link CacheFactory} that handles caching of the entities
* @param factory
* The {@link KapuaEntityFactory} instance.
* @param permissionFactory
* The {@link PermissionFactory} instance.
* @param authorizationService
* The {@link AuthorizationService} instance.
* @param rootUserTester
Expand All @@ -165,11 +162,10 @@ protected AbstractKapuaConfigurableResourceLimitedService(String pid,
EntityManagerFactory entityManagerFactory,
EntityCacheFactory abstractCacheFactory,
F factory,
PermissionFactory permissionFactory,
AuthorizationService authorizationService,
AccountRelativeFinder accountRelativeFinder,
RootUserTester rootUserTester) {
super(pid, domain, entityManagerFactory, abstractCacheFactory, permissionFactory, authorizationService, rootUserTester);
super(pid, domain, entityManagerFactory, abstractCacheFactory, authorizationService, rootUserTester);
this.factory = factory;
this.factoryClass = null; //TODO: not needed for this construction path, remove as soon as the deprecated constructor is removed
this.accountRelativeFinder = accountRelativeFinder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import org.eclipse.kapua.model.query.KapuaQuery;
import org.eclipse.kapua.service.account.Account;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
import org.eclipse.kapua.service.authorization.permission.Permission;
import org.eclipse.kapua.service.config.KapuaConfigurableService;
import org.eclipse.kapua.storage.TxManager;
import org.eclipse.kapua.storage.TxManagerImpl;
Expand All @@ -85,7 +85,6 @@ public abstract class AbstractKapuaConfigurableService extends AbstractKapuaServ
private final String pid;

//TODO: make final as soon as deprecated constructors are removed
private PermissionFactory permissionFactory;
private AuthorizationService authorizationService;
private RootUserTester rootUserTester;
protected TxManager txManager;
Expand Down Expand Up @@ -123,8 +122,8 @@ public abstract class AbstractKapuaConfigurableService extends AbstractKapuaServ
* The {@link EntityManagerFactory} that handles persistence unit
* @since 1.0.0
* @deprecated Since 2.0.0. Please use
* {@link AbstractKapuaConfigurableService#AbstractKapuaConfigurableService(String, Domain, EntityManagerFactory, EntityCacheFactory, PermissionFactory, AuthorizationService,
* RootUserTester)} This constructor may be removed in a next release
* {@link AbstractKapuaConfigurableService#AbstractKapuaConfigurableService(String, Domain, EntityManagerFactory, EntityCacheFactory, AuthorizationService, RootUserTester)} This
* constructor may be removed in a next release
*/
@Deprecated
protected AbstractKapuaConfigurableService(String pid, Domain domain, EntityManagerFactory entityManagerFactory) {
Expand All @@ -137,7 +136,6 @@ protected AbstractKapuaConfigurableService(String pid, Domain domain, EntityMana
*/
null,
null,
null,
null);
}

Expand All @@ -154,8 +152,8 @@ protected AbstractKapuaConfigurableService(String pid, Domain domain, EntityMana
* The {@link CacheFactory} that handles caching of the entities
* @since 1.2.0
* @deprecated Since 2.0.0. Please use
* {@link AbstractKapuaConfigurableService#AbstractKapuaConfigurableService(String, Domain, EntityManagerFactory, EntityCacheFactory, PermissionFactory, AuthorizationService,
* RootUserTester)} This constructor may be removed in a next release
* {@link AbstractKapuaConfigurableService#AbstractKapuaConfigurableService(String, Domain, EntityManagerFactory, EntityCacheFactory, AuthorizationService, RootUserTester)} This
* constructor may be removed in a next release
*/
@Deprecated
protected AbstractKapuaConfigurableService(String pid, Domain domain, EntityManagerFactory entityManagerFactory, EntityCacheFactory abstractCacheFactory) {
Expand All @@ -168,7 +166,6 @@ protected AbstractKapuaConfigurableService(String pid, Domain domain, EntityMana
therefore fetching of these instances is demanded to the artificial getters introduced.
*/
null,
null,
null);
}

Expand All @@ -190,14 +187,12 @@ protected AbstractKapuaConfigurableService(String pid,
Domain domain,
EntityManagerFactory entityManagerFactory,
EntityCacheFactory abstractCacheFactory,
PermissionFactory permissionFactory,
AuthorizationService authorizationService,
RootUserTester rootUserTester) {
super(entityManagerFactory, abstractCacheFactory);

this.pid = pid;
this.domain = domain;
this.permissionFactory = permissionFactory;
this.authorizationService = authorizationService;
this.rootUserTester = rootUserTester;
this.txManager = new TxManagerImpl(
Expand Down Expand Up @@ -458,7 +453,7 @@ private KapuaTocd getConfigMetadata(KapuaId scopeId, boolean excludeDisabled) th
throw new KapuaServiceDisabledException(pid);
}
// Check access
getAuthorizationService().checkPermission(getPermissionFactory().newPermission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId));
getAuthorizationService().checkPermission(new Permission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId));
// Get the Tocd
// Keep distinct values for service PID, Scope ID and disabled properties included/excluded from AD
Triple<String, KapuaId, Boolean> cacheKey = Triple.of(pid, scopeId, excludeDisabled);
Expand Down Expand Up @@ -526,7 +521,7 @@ protected Map<String, Object> getConfigValues(KapuaId scopeId, boolean excludeDi
// Argument validation
ArgumentValidator.notNull(scopeId, "scopeId");
// Check access
getAuthorizationService().checkPermission(getPermissionFactory().newPermission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId));
getAuthorizationService().checkPermission(new Permission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId));
// Get configuration values
KapuaQuery query = new KapuaQuery(scopeId);

Expand Down Expand Up @@ -580,7 +575,7 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map<String, Objec
}
}

getAuthorizationService().checkPermission(getPermissionFactory().newPermission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.write, scopeId));
getAuthorizationService().checkPermission(new Permission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.write, scopeId));

validateConfigurations(ocd, values, scopeId, parentId);

Expand Down Expand Up @@ -639,20 +634,6 @@ public String getServicePid() {
return pid;
}

/**
* PermissionFactory should be provided by the Locator, but in most cases when this class is instantiated through this constructor the Locator is not yet ready, therefore fetching of the required
* instance is demanded to this artificial getter.
*
* @return The instantiated (hopefully) {@link PermissionFactory} instance
*/
//TODO: Remove as soon as deprecated constructors are removed, use field directly instead.
protected PermissionFactory getPermissionFactory() {
if (permissionFactory == null) {
permissionFactory = KapuaLocator.getInstance().getFactory(PermissionFactory.class);
}
return permissionFactory;
}

/**
* AuthorizationService should be provided by the Locator, but in most cases when this class is instantiated through the deprecated constructor the Locator is not yet ready, therefore fetching of
* the required instance is demanded to this artificial getter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.KapuaService;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
import org.eclipse.kapua.service.authorization.permission.Permission;
import org.eclipse.kapua.service.config.KapuaConfigurableService;
import org.eclipse.kapua.storage.TxManager;

/**
* Base {@link KapuaConfigurableService} implementation, build upon {@link ServiceConfigurationManager}.
* <p>
* Note: at first glance, this might seems like a violation of Composition over Inheritance principle, however:
* - in this case inheritance is an acceptable strategy due to the strong link between {@link ServiceConfigurationManager#isServiceEnabled(org.eclipse.kapua.storage.TxContext, KapuaId)}
* and {@link org.eclipse.kapua.service.KapuaService#isServiceEnabled(KapuaId)} (the latter being dependent from the first for configurable services).
* - this class is nothing more than glue and convenience, demanding all of its logic to the {@link ServiceConfigurationManager}'s instance provided, so no flexibility has been sacrificed
* Note: at first glance, this might seems like a violation of Composition over Inheritance principle, however: - in this case inheritance is an acceptable strategy due to the strong link between
* {@link ServiceConfigurationManager#isServiceEnabled(org.eclipse.kapua.storage.TxContext, KapuaId)} and {@link org.eclipse.kapua.service.KapuaService#isServiceEnabled(KapuaId)} (the latter being
* dependent from the first for configurable services). - this class is nothing more than glue and convenience, demanding all of its logic to the {@link ServiceConfigurationManager}'s instance
* provided, so no flexibility has been sacrificed
*
* @since 2.0.0
*/
Expand All @@ -44,19 +44,16 @@ public class KapuaConfigurableServiceBase
protected final ServiceConfigurationManager serviceConfigurationManager;
private final String domain;
protected final AuthorizationService authorizationService;
protected final PermissionFactory permissionFactory;

public KapuaConfigurableServiceBase(
TxManager txManager,
ServiceConfigurationManager serviceConfigurationManager,
String authorizationDomain,
AuthorizationService authorizationService,
PermissionFactory permissionFactory) {
AuthorizationService authorizationService) {
this.txManager = txManager;
this.serviceConfigurationManager = serviceConfigurationManager;
this.domain = authorizationDomain;
this.authorizationService = authorizationService;
this.permissionFactory = permissionFactory;
}

@Override
Expand All @@ -73,7 +70,7 @@ public KapuaTocd getConfigMetadata(KapuaId scopeId) throws KapuaException {
ArgumentValidator.notNull(scopeId, "scopeId");

// Check access
authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.read, scopeId));
authorizationService.checkPermission(new Permission(domain, Actions.read, scopeId));
return txManager.execute(tx -> serviceConfigurationManager.getConfigMetadata(tx, scopeId, true));
}

Expand All @@ -83,7 +80,7 @@ public Map<String, Object> getConfigValues(KapuaId scopeId) throws KapuaExceptio
ArgumentValidator.notNull(scopeId, "scopeId");

// Check access
authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.read, scopeId));
authorizationService.checkPermission(new Permission(domain, Actions.read, scopeId));

return txManager.execute(tx -> serviceConfigurationManager.getConfigValues(tx, scopeId, true));
}
Expand All @@ -94,7 +91,7 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map<String, Objec
ArgumentValidator.notNull(scopeId, "scopeId");
ArgumentValidator.notNull(values, "values");

authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.write, scopeId));
authorizationService.checkPermission(new Permission(domain, Actions.write, scopeId));

txManager.<Void>execute(tx -> {
serviceConfigurationManager.setConfigValues(tx, scopeId, Optional.ofNullable(parentId), values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.kapua.event.ServiceEventBus;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
import org.eclipse.kapua.storage.TxManagerImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -100,7 +99,6 @@ public void start() throws KapuaException {
final KapuaLocator locator = KapuaLocator.getInstance();
houseKeeperJob = new ServiceEventHousekeeper(
new EventStoreServiceImpl(locator.getService(AuthorizationService.class),
locator.getFactory(PermissionFactory.class),
new TxManagerImpl(() -> new JpaTxContext(serviceEventModuleConfiguration.getEntityManagerFactory().getJpaEntityManagerFactory()),
serviceEventModuleConfiguration.maxInsertAttempts),
new EventStoreRecordImplJpaRepository(serviceEventModuleConfiguration.getKapuaJpaRepositoryConfiguration())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.model.query.KapuaQuery;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
import org.eclipse.kapua.service.authorization.permission.Permission;
import org.eclipse.kapua.storage.TxManager;

/**
Expand All @@ -40,18 +40,15 @@ public class EventStoreServiceImpl
implements EventStoreService {

private final AuthorizationService authorizationService;
private final PermissionFactory permissionFactory;
private final TxManager txManager;
private final EventStoreRecordRepository repository;

@Inject
public EventStoreServiceImpl(
AuthorizationService authorizationService,
PermissionFactory permissionFactory,
TxManager txManager,
EventStoreRecordRepository repository) {
this.authorizationService = authorizationService;
this.permissionFactory = permissionFactory;
this.txManager = txManager;
this.repository = repository;
}
Expand All @@ -71,7 +68,7 @@ public EventStoreRecord update(EventStoreRecord kapuaEvent)
// Validation of the fields
ArgumentValidator.notNull(kapuaEvent.getId(), "kapuaEvent.id");
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.write, kapuaEvent.getScopeId()));
authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.write, kapuaEvent.getScopeId()));
// Do update
return txManager.execute(tx -> repository.update(tx, kapuaEvent));
}
Expand All @@ -85,7 +82,7 @@ public void delete(KapuaId scopeId, KapuaId kapuaEventId)
ArgumentValidator.notNull(kapuaEventId, KapuaEntityAttributes.ENTITY_ID);
// Check Access
Actions action = Actions.write;
authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, action, scopeId));
authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, action, scopeId));
// Do delete
txManager.execute(tx -> repository.delete(tx, scopeId, kapuaEventId));
}
Expand All @@ -97,7 +94,7 @@ public EventStoreRecord find(KapuaId scopeId, KapuaId kapuaEventId)
ArgumentValidator.notNull(scopeId, KapuaEntityAttributes.SCOPE_ID);
ArgumentValidator.notNull(kapuaEventId, KapuaEntityAttributes.ENTITY_ID);
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, scopeId));
authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, scopeId));
// Make sure kapuaEvent exists
return txManager.execute(tx -> repository.find(tx, scopeId, kapuaEventId))
.orElse(null);
Expand All @@ -109,7 +106,7 @@ public EventStoreRecord find(KapuaId kapuaEventId)
// Validation of the fields
ArgumentValidator.notNull(kapuaEventId, KapuaEntityAttributes.ENTITY_ID);
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, kapuaEventId));
authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, kapuaEventId));

return txManager.execute(tx -> repository.find(tx, KapuaId.ANY, kapuaEventId))
.orElse(null);
Expand All @@ -120,7 +117,7 @@ public EventStoreRecordListResult query(KapuaQuery query)
throws KapuaException {
ArgumentValidator.notNull(query, "query");
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, query.getScopeId()));
authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, query.getScopeId()));
return txManager.execute(tx -> repository.query(tx, query));
}

Expand All @@ -129,7 +126,7 @@ public long count(KapuaQuery query)
throws KapuaException {
ArgumentValidator.notNull(query, "query");
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(Domains.EVENT_STORE, Actions.read, query.getScopeId()));
authorizationService.checkPermission(new Permission(Domains.EVENT_STORE, Actions.read, query.getScopeId()));
return txManager.execute(tx -> repository.count(tx, query));
}
}
Loading

0 comments on commit d7bac90

Please sign in to comment.