Skip to content

Commit

Permalink
fix: add input validation to KapuaConfigurableServiceBase
Browse files Browse the repository at this point in the history
Added validation for scopeId and configValues in KapuaConfigurableServiceBase to prevent NullPointerExceptions. Ensured configValues is checked for null and emptiness.
  • Loading branch information
MDeLuise committed Jul 1, 2024
1 parent 2349705 commit 39e6353
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;

import java.util.Map;
import java.util.Optional;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.util.ArgumentValidator;
import org.eclipse.kapua.model.config.metatype.KapuaTocd;
import org.eclipse.kapua.model.domain.Actions;
import org.eclipse.kapua.model.id.KapuaId;
Expand All @@ -22,9 +26,6 @@
import org.eclipse.kapua.service.config.KapuaConfigurableService;
import org.eclipse.kapua.storage.TxManager;

import java.util.Map;
import java.util.Optional;

/**
* Base {@link KapuaConfigurableService} implementation, build upon {@link ServiceConfigurationManager}.
* <p>
Expand Down Expand Up @@ -60,18 +61,27 @@ public KapuaConfigurableServiceBase(

@Override
public boolean isServiceEnabled(KapuaId scopeId) throws KapuaException {
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");

Check warning on line 65 in commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java

View check run for this annotation

Codecov / codecov/patch

commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java#L65

Added line #L65 was not covered by tests

return txManager.execute(tx -> serviceConfigurationManager.isServiceEnabled(tx, scopeId));
}

@Override
public KapuaTocd getConfigMetadata(KapuaId scopeId) throws KapuaException {
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");

Check warning on line 73 in commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java

View check run for this annotation

Codecov / codecov/patch

commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java#L73

Added line #L73 was not covered by tests

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

@Override
public Map<String, Object> getConfigValues(KapuaId scopeId) throws KapuaException {
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");

Check warning on line 83 in commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java

View check run for this annotation

Codecov / codecov/patch

commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java#L83

Added line #L83 was not covered by tests

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

Expand All @@ -80,6 +90,11 @@ public Map<String, Object> getConfigValues(KapuaId scopeId) throws KapuaExceptio

@Override
public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map<String, Object> values) throws KapuaException {
// Argument Validation
ArgumentValidator.notNull(scopeId, "scopeId");
ArgumentValidator.notNull(parentId, "parentId");
ArgumentValidator.notEmptyOrNull(values.values(), "values");

Check warning on line 96 in commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java

View check run for this annotation

Codecov / codecov/patch

commons/src/main/java/org/eclipse/kapua/commons/configuration/KapuaConfigurableServiceBase.java#L94-L96

Added lines #L94 - L96 were not covered by tests

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

txManager.<Void>execute(tx -> {
Expand Down

0 comments on commit 39e6353

Please sign in to comment.