Trying to implement Multitenancy, but now can’t login with my (default) admin account
User.java
@TenantId
@Column(name = "TENANT")
private String tenant;
public String getTenant() {
return tenant;
}
@Override
public String getTenantId() {
return tenant;
}
public void setTenant(String tenant) {
this.tenant = tenant;
}
user-list-view.xml
<column property="tenant"/>
user-detail-view.xml
<comboBox id="tenantField" property="tenant" readOnly="true"/>
LoginView.java
@Autowired
MultitenancyUiSupport multitenancyFlowuiSupport;
private Location currentLocation;
@Override
public void beforeEnter(BeforeEnterEvent event) {
currentLocation = event.getLocation();
super.beforeEnter(event);
}
@Subscribe("login")
public void onLogin(LoginEvent event) {
String username = multitenancyFlowuiSupport.getUsernameByLocation(event.getUsername(), currentLocation);
UserDetailView.java
@Autowired
private TenantProvider tenantProvider;
@Autowired
private MultitenancyUiSupport multitenancyUiSupport;
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
String currentTenantId = tenantProvider.getCurrentUserTenantId();
if (!currentTenantId.equals(TenantProvider.NO_TENANT)
&& Strings.isNullOrEmpty(tenantField.getValue())) {
tenantField.setReadOnly(true);
tenantField.setValue(currentTenantId);
}
}
@Subscribe("tenantField")
public void onTenantFieldComponentValueChange(AbstractField.ComponentValueChangeEvent<JmixComboBox<String>, String> event) {
usernameField.setValue(
multitenancyUiSupport.getUsernameByTenant(usernameField.getValue(), event.getValue())
);
}
@Subscribe
public void onInit(InitEvent event) {
timeZoneField.setItems(List.of(TimeZone.getAvailableIDs()));
tenantField.setItems(multitenancyUiSupport.getTenantOptions());
}
@Subscribe
public void onInitEntity(InitEntityEvent<User> event) {
tenantField.setReadOnly(false);
usernameField.setReadOnly(false);
passwordField.setVisible(true);
confirmPasswordField.setVisible(true);
}