Fix getAllAuthorities (#2548)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user