Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
User substitution jmix-projects/jmix-security#30
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaimanov committed Sep 13, 2021
1 parent b6b5ed0 commit ede57e8
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.jmix.ui.component.Button;
import io.jmix.ui.component.Window;
import io.jmix.ui.component.mainwindow.Drawer;
import io.jmix.ui.component.mainwindow.UserIndicator;
import io.jmix.ui.icon.JmixIcon;
import io.jmix.ui.navigation.Route;
import io.jmix.ui.screen.Screen;
Expand All @@ -13,6 +14,7 @@
import io.jmix.ui.screen.UiControllerUtils;
import io.jmix.ui.screen.UiDescriptor;
import org.springframework.beans.factory.annotation.Autowired;
import io.jmix.securitydata.impl.substitution.UserSubstitutionManager;

@UiController("${normalizedPrefix_underscore}MainScreen")
@UiDescriptor("main-screen.xml")
Expand All @@ -21,13 +23,18 @@ public class MainScreen extends Screen implements Window.HasWorkArea {

@Autowired
private ScreenTools screenTools;
@Autowired
private UserSubstitutionManager userSubstitutionManager;

@Autowired
private AppWorkArea workArea;
@Autowired
private Drawer drawer;
@Autowired
private Button collapseDrawerButton;
@Autowired
private UserIndicator userIndicator;


@Override
public AppWorkArea getWorkArea() {
Expand All @@ -44,6 +51,15 @@ private void onCollapseDrawerButtonClick(Button.ClickEvent event) {
}
}

@Subscribe
public void onAfterInit(AfterInitEvent afterInitEvent) {
userIndicator.setAdditionalUsers(userSubstitutionManager.getCurrentSubstitutedUsers());
userIndicator.addSubstituteStep(user->{
userSubstitutionManager.substituteUser(user.getUsername());
});
userIndicator.refreshUser();
}

@Subscribe
public void onAfterShow(AfterShowEvent event) {
screenTools.openDefaultScreen(
Expand Down

0 comments on commit ede57e8

Please sign in to comment.