Sonar Fix (#2239)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -58,7 +58,7 @@ public final class SpRole {
|
||||
public static final String SYSTEM_ADMIN_HIERARCHY =
|
||||
SpPermission.SYSTEM_ADMIN + IMPLIES + TENANT_ADMIN + LINE_BREAK;
|
||||
|
||||
public static String DEFAULT_ROLE_HIERARCHY =
|
||||
public static final String DEFAULT_ROLE_HIERARCHY =
|
||||
TARGET_ADMIN_HIERARCHY +
|
||||
REPOSITORY_ADMIN_HIERARCHY +
|
||||
ROLLOUT_ADMIN_HIERARCHY +
|
||||
|
||||
@@ -128,8 +128,8 @@ public class StaticAuthenticationProvider extends DaoAuthenticationProvider {
|
||||
}
|
||||
|
||||
private static User clone(final User user) {
|
||||
if (user instanceof TenantAwareUser) {
|
||||
return new TenantAwareUser(user.getUsername(), user.getPassword(), user.getAuthorities(), ((TenantAwareUser) user).getTenant());
|
||||
if (user instanceof TenantAwareUser tenantAwareUser) {
|
||||
return new TenantAwareUser(user.getUsername(), user.getPassword(), user.getAuthorities(), tenantAwareUser.getTenant());
|
||||
} else {
|
||||
return new User(user.getUsername(), user.getPassword(), user.getAuthorities());
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import java.io.ObjectOutputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
|
||||
public interface SecurityContextSerializer {
|
||||
@@ -74,11 +76,10 @@ public interface SecurityContextSerializer {
|
||||
/**
|
||||
* Implementation based on the java serialization.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S112") // accepted
|
||||
class JavaSerialization implements SecurityContextSerializer {
|
||||
|
||||
private JavaSerialization() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(final SecurityContext securityContext) {
|
||||
Objects.requireNonNull(securityContext);
|
||||
|
||||
@@ -62,11 +62,11 @@ public class SpringSecurityAuditorAware implements AuditorAware<String> {
|
||||
if (authentication.getDetails() instanceof TenantAwareAuthenticationDetails tenantAwareDetails && tenantAwareDetails.isController()) {
|
||||
return "CONTROLLER_PLUG_AND_PLAY";
|
||||
}
|
||||
if (authentication.getPrincipal() instanceof UserDetails) {
|
||||
return ((UserDetails) authentication.getPrincipal()).getUsername();
|
||||
if (authentication.getPrincipal() instanceof UserDetails userDetails) {
|
||||
return userDetails.getUsername();
|
||||
}
|
||||
if (authentication.getPrincipal() instanceof OidcUser) {
|
||||
return ((OidcUser) authentication.getPrincipal()).getPreferredUsername();
|
||||
if (authentication.getPrincipal() instanceof OidcUser oidcUser) {
|
||||
return oidcUser.getPreferredUsername();
|
||||
}
|
||||
return authentication.getPrincipal().toString();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
@Feature("Unit Tests - Security")
|
||||
@Story("Permission Test")
|
||||
public final class SpPermissionTest {
|
||||
final class SpPermissionTest {
|
||||
|
||||
@Test
|
||||
@Description("Try to double check if all permissions works as expected")
|
||||
@@ -42,7 +42,8 @@ public final class SpPermissionTest {
|
||||
}
|
||||
});
|
||||
final Collection<String> allAuthorities = SpPermission.getAllAuthorities();
|
||||
assertThat(allAuthorities).hasSize(20);
|
||||
assertThat(allAuthorities).containsAll(expected);
|
||||
assertThat(allAuthorities)
|
||||
.hasSize(20)
|
||||
.containsAll(expected);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user