Rename UserTenantAware to TenantAwareUser (#1668)

in order to be compatible with other TenantAware entities

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-02-27 08:43:40 +02:00
committed by GitHub
parent 24d70827b7
commit a0db5ff70e
5 changed files with 25 additions and 26 deletions

View File

@@ -27,7 +27,7 @@ import org.springframework.security.core.userdetails.User;
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class UserTenantAware extends User {
public class TenantAwareUser extends User {
@Serial
private static final long serialVersionUID = 1L;
@@ -40,7 +40,7 @@ public class UserTenantAware extends User {
* @param authorities the authorities which the user has
* @param tenant the tenant of the user
*/
public UserTenantAware(final String username, final String password,
public TenantAwareUser(final String username, final String password,
final Collection<? extends GrantedAuthority> authorities, final String tenant) {
super(username, password, authorities == null ? Collections.emptyList() : authorities);
this.tenant = tenant;
@@ -52,7 +52,7 @@ public class UserTenantAware extends User {
* @param username the username of the user
* @param tenant the tenant of the user
*/
public UserTenantAware(final String username, String tenant) {
public TenantAwareUser(final String username, String tenant) {
this(username, "***", null, tenant);
}

View File

@@ -21,7 +21,7 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.ContextAware;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.im.authentication.UserTenantAware;
import org.eclipse.hawkbit.im.authentication.TenantAwareUser;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.UserAuthoritiesResolver;
import org.springframework.lang.Nullable;
@@ -39,7 +39,6 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;
* from the {@link SecurityContext#getAuthentication()}
* {@link Authentication#getDetails()} which holds the
* {@link TenantAwareAuthenticationDetails} object.
*
*/
public class SecurityContextTenantAware implements ContextAware {
@@ -85,8 +84,8 @@ public class SecurityContextTenantAware implements ContextAware {
final Object principal = context.getAuthentication().getPrincipal();
if (context.getAuthentication().getDetails() instanceof TenantAwareAuthenticationDetails) {
return ((TenantAwareAuthenticationDetails) context.getAuthentication().getDetails()).getTenant();
} else if (principal instanceof UserTenantAware) {
return ((UserTenantAware) principal).getTenant();
} else if (principal instanceof TenantAwareUser) {
return ((TenantAwareUser) principal).getTenant();
}
}
return null;
@@ -191,14 +190,14 @@ public class SecurityContextTenantAware implements ContextAware {
private final Authentication delegate;
private final UserTenantAware principal;
private final TenantAwareUser principal;
private final TenantAwareAuthenticationDetails tenantAwareAuthenticationDetails;
private AuthenticationDelegate(final Authentication delegate, final String tenant, final String username,
final Collection<? extends GrantedAuthority> authorities) {
this.delegate = delegate;
this.principal = new UserTenantAware(username, username, authorities, tenant);
this.principal = new TenantAwareUser(username, username, authorities, tenant);
tenantAwareAuthenticationDetails = new TenantAwareAuthenticationDetails(tenant, false);
}