Fix sonar findings (2) (#3016)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2026-04-15 14:39:28 +03:00
committed by GitHub
parent a00374f455
commit 8015b0e3f1
6 changed files with 73 additions and 81 deletions

View File

@@ -9,8 +9,6 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import lombok.AccessLevel;
@@ -37,9 +35,9 @@ public class DefaultRolloutApprovalStrategy implements RolloutApprovalStrategy {
*/
@Override
public boolean isApprovalNeeded(final Rollout rollout) {
return TenantConfigHelper.getAsSystem(TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED, Boolean.class)
&& hasNoApproveRolloutPermission(getCurrentAuthentication().map(Authentication::getAuthorities).orElseGet(List::of).stream()
.map(GrantedAuthority::getAuthority).toList());
return TenantConfigHelper.getAsSystem(TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED, Boolean.class) // if approval enabled for tenant
&& !getCurrentAuthentication().map(Authentication::getAuthorities).map(grantedAuthorities -> grantedAuthorities.stream()
.map(GrantedAuthority::getAuthority).anyMatch(SpPermission.APPROVE_ROLLOUT::equals)).orElse(false);
}
@Override
@@ -55,8 +53,4 @@ public class DefaultRolloutApprovalStrategy implements RolloutApprovalStrategy {
private static Optional<Authentication> getCurrentAuthentication() {
return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication());
}
private static boolean hasNoApproveRolloutPermission(final Collection<String> authorities) {
return authorities.stream().noneMatch(SpPermission.APPROVE_ROLLOUT::equals);
}
}

View File

@@ -266,7 +266,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaBaseEntity> implements
@NonNull
public List<T> findAll(final Operation operation, @Nullable final Specification<T> spec) {
if (operation == null) {
return repository.findAll(spec);
return spec == null ? repository.findAll() : repository.findAll(spec);
} else {
return repository.findAll(accessController.appendAccessRules(operation, spec));
}

View File

@@ -66,7 +66,7 @@ public final class HawkbitBaseRepository<T, ID extends Serializable> extends Sim
@Override
public Slice<T> findAllWithoutCount(@Nullable final Specification<T> spec, final Pageable pageable) {
final TypedQuery<T> query = getQuery(spec, pageable);
final TypedQuery<T> query = getQuery(spec == null ? Specification.unrestricted() : spec, pageable);
return pageable.isUnpaged() ? new PageImpl<>(query.getResultList()) : readPageWithoutCount(query, pageable);
}
@@ -104,7 +104,7 @@ public final class HawkbitBaseRepository<T, ID extends Serializable> extends Sim
@Override
public long count(@Nullable final Operation operation, @Nullable final Specification<T> spec) {
return count(spec);
return spec == null ? count() : count(spec);
}
@Override