Skip to content

Commit

Permalink
refactor: Make AccessControl session scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuJLund committed Sep 21, 2024
1 parent 72f00f9 commit 9ccecbe
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class VaadinCreateUI extends UI implements EventBusListener, HasI18N {
// in the unit tests included. Supposed these were the real production
// services this UI can be extended and getters for the services overriden
// for creating test UI for unit tests.
private AccessControl accessControl = new BasicAccessControl();
private transient ProductDataService productService = ProductDataService
.get();
private transient UserService userService = UserService.get();
Expand Down Expand Up @@ -127,7 +126,7 @@ protected void showAppLayout() {
VaadinIcons.USERS, AdminView.VIEW_NAME);

Product draft = getProductService()
.findDraft(accessControl.getPrincipalName());
.findDraft(getAccessControl().getPrincipalName());
if (draft != null) {
handleDraft(draft);
} else {
Expand All @@ -148,7 +147,7 @@ private void handleDraft(Product draft) {
.navigateTo(String.format("%s/%s", BooksView.VIEW_NAME, id)));
dialog.addCancelListener(e -> {
logger.info("Draft discarded");
getProductService().saveDraft(accessControl.getPrincipalName(),
getProductService().saveDraft(getAccessControl().getPrincipalName(),
null);
getNavigator().navigateTo(target);
});
Expand All @@ -165,6 +164,11 @@ public static VaadinCreateUI get() {
* @return Instance of AccessControl
*/
public AccessControl getAccessControl() {
var accessControl = getSession().getAttribute(AccessControl.class);
if (accessControl == null) {
accessControl = new BasicAccessControl();
getSession().setAttribute(AccessControl.class, accessControl);
}
return accessControl;
}

Expand Down

0 comments on commit 9ccecbe

Please sign in to comment.