Introduce pluggable tenant resolver (#2151)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -49,9 +49,9 @@ public class JpaConfiguration extends JpaBaseConfiguration {
|
||||
protected JpaConfiguration(
|
||||
final DataSource dataSource, final JpaProperties properties,
|
||||
final ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider,
|
||||
final TenantAware tenantAware) {
|
||||
final TenantAware.TenantResolver tenantResolver) {
|
||||
super(dataSource, properties, jtaTransactionManagerProvider);
|
||||
tenantIdentifier = new TenantIdentifier(tenantAware);
|
||||
tenantIdentifier = new TenantIdentifier(tenantResolver);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -21,16 +21,16 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomi
|
||||
*/
|
||||
class TenantIdentifier implements CurrentTenantIdentifierResolver<String> {
|
||||
|
||||
private final TenantAware tenantAware;
|
||||
private final TenantAware.TenantResolver tenantResolver;
|
||||
|
||||
TenantIdentifier(final TenantAware tenantAware) {
|
||||
this.tenantAware = tenantAware;
|
||||
TenantIdentifier(final TenantAware.TenantResolver tenantResolver) {
|
||||
this.tenantResolver = tenantResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveCurrentTenantIdentifier() {
|
||||
// on bootstrapping hibernate requests tenant and want to be non-null
|
||||
return Optional.ofNullable(tenantAware.getCurrentTenant()).map(String::toUpperCase).orElse("");
|
||||
return Optional.ofNullable(tenantResolver.resolveTenant()).map(String::toUpperCase).orElse("");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,8 +31,9 @@
|
||||
<id>eclipselink</id>
|
||||
<activation>
|
||||
<property>
|
||||
<!-- default, if not set - eclipse link -->
|
||||
<name>!jpa.vendor</name>
|
||||
<!-- default, if not set (or not hibernate) - eclipse link -->
|
||||
<name>jpa.vendor</name>
|
||||
<value>!hibernate</value>
|
||||
</property>
|
||||
</activation>
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
||||
import org.eclipse.hawkbit.security.SpringSecurityAuditorAware;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware.DefaultTenantResolver;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware.TenantResolver;
|
||||
import org.eclipse.hawkbit.tenancy.UserAuthoritiesResolver;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.ControllerPollProperties;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
|
||||
@@ -165,9 +167,16 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
ContextAware contextAware(final UserAuthoritiesResolver authoritiesResolver, final SecurityContextSerializer securityContextSerializer) {
|
||||
TenantResolver tenantResolver() {
|
||||
return new DefaultTenantResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
ContextAware contextAware(
|
||||
final UserAuthoritiesResolver authoritiesResolver, final SecurityContextSerializer securityContextSerializer,
|
||||
final TenantResolver tenantResolver) {
|
||||
// allow spying the security context
|
||||
return org.mockito.Mockito.spy(new SecurityContextTenantAware(authoritiesResolver, securityContextSerializer));
|
||||
return org.mockito.Mockito.spy(new SecurityContextTenantAware(authoritiesResolver, securityContextSerializer, tenantResolver));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user