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:
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
|
||||
import org.eclipse.hawkbit.im.authentication.MultitenancyIndicator;
|
||||
import org.eclipse.hawkbit.im.authentication.PermissionUtils;
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
||||
import org.eclipse.hawkbit.im.authentication.UserTenantAware;
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareUser;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -57,10 +57,10 @@ public class InMemoryUserManagementAutoConfiguration extends GlobalAuthenticatio
|
||||
|
||||
InMemoryUserManagementAutoConfiguration(
|
||||
final SecurityProperties securityProperties,
|
||||
final TenantAwareUserProperties userTenantAwareProperties,
|
||||
final TenantAwareUserProperties tenantAwareUserProperties,
|
||||
final Optional<PasswordEncoder> passwordEncoder) {
|
||||
userDetailsService = userDetailsService(
|
||||
securityProperties, userTenantAwareProperties, passwordEncoder.orElse(null));
|
||||
securityProperties, tenantAwareUserProperties, passwordEncoder.orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,11 +72,11 @@ public class InMemoryUserManagementAutoConfiguration extends GlobalAuthenticatio
|
||||
|
||||
private static UserDetailsService userDetailsService(
|
||||
final SecurityProperties securityProperties,
|
||||
final TenantAwareUserProperties userTenantAwareProperties,
|
||||
final TenantAwareUserProperties tenantAwareUserProperties,
|
||||
final PasswordEncoder passwordEncoder) {
|
||||
final List<User> userPrincipals = new ArrayList<>();
|
||||
userTenantAwareProperties.getUsers().forEach((username, user) -> {
|
||||
final UserTenantAware userPrincipal = new UserTenantAware(
|
||||
tenantAwareUserProperties.getUsers().forEach((username, user) -> {
|
||||
final TenantAwareUser userPrincipal = new TenantAwareUser(
|
||||
username, password(user.getPassword(), passwordEncoder),
|
||||
createAuthorities(user.getRoles(), Collections::emptyList),
|
||||
ObjectUtils.isEmpty(user.getTenant()) ? DEFAULT_TENANT : user.getTenant());
|
||||
@@ -87,7 +87,7 @@ public class InMemoryUserManagementAutoConfiguration extends GlobalAuthenticatio
|
||||
// the default user from spring security properties as super DEFAULT tenant user
|
||||
if (userPrincipals.isEmpty()) {
|
||||
userPrincipals
|
||||
.add(new UserTenantAware(
|
||||
.add(new TenantAwareUser(
|
||||
securityProperties.getUser().getName(),
|
||||
password(securityProperties.getUser().getPassword(), passwordEncoder),
|
||||
createAuthorities(
|
||||
@@ -153,9 +153,9 @@ public class InMemoryUserManagementAutoConfiguration extends GlobalAuthenticatio
|
||||
}
|
||||
|
||||
private static User clone(final User user) {
|
||||
if (user instanceof UserTenantAware) {
|
||||
return new UserTenantAware(user.getUsername(), user.getPassword(), user.getAuthorities(),
|
||||
((UserTenantAware)user).getTenant());
|
||||
if (user instanceof TenantAwareUser) {
|
||||
return new TenantAwareUser(user.getUsername(), user.getPassword(), user.getAuthorities(),
|
||||
((TenantAwareUser)user).getTenant());
|
||||
} else {
|
||||
return new User(user.getUsername(), user.getPassword(), user.getAuthorities());
|
||||
}
|
||||
|
||||
@@ -74,17 +74,17 @@ public class SecurityAutoConfiguration {
|
||||
* resolving user authorities/roles.
|
||||
*
|
||||
* @param securityProperties The Spring {@link SecurityProperties} for the security user
|
||||
* @param userTenantAwareProperties The {@link TenantAwareUserProperties} for the managed users
|
||||
* @param tenantAwareUserProperties The {@link TenantAwareUserProperties} for the managed users
|
||||
* @return an {@link InMemoryUserAuthoritiesResolver} bean
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public UserAuthoritiesResolver inMemoryAuthoritiesResolver(final SecurityProperties securityProperties,
|
||||
final TenantAwareUserProperties userTenantAwareProperties) {
|
||||
final Map<String, User> userTenantAwares = userTenantAwareProperties.getUsers();
|
||||
final TenantAwareUserProperties tenantAwareUserProperties) {
|
||||
final Map<String, User> tenantAwareUsers = tenantAwareUserProperties.getUsers();
|
||||
final Map<String, List<String>> usersToPermissions;
|
||||
if (!CollectionUtils.isEmpty(userTenantAwares)) {
|
||||
usersToPermissions = userTenantAwares.entrySet().stream().collect(
|
||||
if (!CollectionUtils.isEmpty(tenantAwareUsers)) {
|
||||
usersToPermissions = tenantAwareUsers.entrySet().stream().collect(
|
||||
Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getRoles()));
|
||||
} else {
|
||||
usersToPermissions = Collections.singletonMap(securityProperties.getUser().getName(),
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.concurrent.Callable;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
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.repository.model.helper.SystemManagementHolder;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -163,7 +163,7 @@ public class SecurityContextSwitch {
|
||||
authorities = annotation.authorities();
|
||||
}
|
||||
final TestingAuthenticationToken testingAuthenticationToken = new TestingAuthenticationToken(
|
||||
new UserTenantAware(annotation.principal(), annotation.tenantId()),
|
||||
new TenantAwareUser(annotation.principal(), annotation.tenantId()),
|
||||
annotation.credentials(), authorities);
|
||||
testingAuthenticationToken.setDetails(
|
||||
new TenantAwareAuthenticationDetails(annotation.tenantId(), annotation.controller()));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user