Fix getAllAuthorities (#2548)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-07-15 09:28:55 +03:00
committed by GitHub
parent 0e3fa11d3e
commit 8a60f9b98b
2 changed files with 35 additions and 1 deletions

View File

@@ -163,7 +163,7 @@ public final class SpPermission {
final Field[] declaredFields = SpPermission.class.getDeclaredFields();
for (final Field field : declaredFields) {
if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) &&
String.class.equals(field.getType())) {
String.class.equals(field.getType()) && !field.getName().endsWith("_HIERARCHY")) {
try {
final String role = (String) field.get(null);
allPermissions.add(role);

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.im.authentication;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import org.junit.jupiter.api.Test;
/**
* Test {@link SpPermission}.
* <p/>
* Feature: Unit Tests - Security<br/>
* Story: Permission Test
*/
final class SpPermissionTest {
/**
* Double-checks that all permissions doesn't contain any hierarchies.
*/
@Test
void allAuthoritiesShouldNotContainHierarchies() {
final Collection<String> allAuthorities = SpPermission.getAllAuthorities();
assertThat(allAuthorities).isNotEmpty().as("Are not hierarchies").allMatch(permission -> !permission.contains("\n"));
}
}