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 68c941f commit 3f23f59
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import io.jmix.core.security.CurrentAuthentication;
import io.jmix.reports.ParameterClassResolver;
import io.jmix.reports.ReportSecurityManager;
import io.jmix.reports.runner.ReportRunContext;
import io.jmix.reports.runner.ReportRunner;
import io.jmix.reports.entity.*;
import io.jmix.reports.exception.FailedToConnectToOpenOfficeException;
import io.jmix.reports.exception.NoOpenOfficeFreePortsException;
import io.jmix.reports.exception.ReportingException;
import io.jmix.reports.runner.ReportRunContext;
import io.jmix.reports.runner.ReportRunner;
import io.jmix.security.constraint.PolicyStore;
import io.jmix.security.constraint.SecureOperations;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -109,7 +109,10 @@ public String loadReportsList() {

loadContext.setFetchPlan(fetchPlan)
.setQueryString("select r from report_Report r where r.restAccess = true");
reportSecurityManager.applySecurityPolicies(loadContext, null, currentAuthentication.getUser());
reportSecurityManager.applySecurityPolicies(
loadContext,
null,
currentAuthentication.getCurrentOrSubstitutedUser());
List<Report> reports = dataManager.loadList(loadContext);

List<ReportInfo> objects = reports.stream()
Expand Down Expand Up @@ -188,7 +191,7 @@ protected Report loadReportInternal(String entityId) {
.setQueryString("select r from report_Report r where r.id = :id and r.restAccess = true")
.setParameter("id", getReportIdFromString(entityId));

reportSecurityManager.applySecurityPolicies(loadContext, null, currentAuthentication.getUser());
reportSecurityManager.applySecurityPolicies(loadContext, null, currentAuthentication.getCurrentOrSubstitutedUser());

Report report = dataManager.load(loadContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ protected void openRunReportScreen(Screen screen, Object selectedValue, MetaClas

protected void openRunReportScreen(Screen screen, Object selectedValue, MetaClass inputValueMetaClass,
@Nullable String outputFileName) {
List<Report> reports = reportSecurityManager.getAvailableReports(screen.getId(), currentAuthentication.getUser(), inputValueMetaClass);
List<Report> reports = reportSecurityManager.getAvailableReports(
screen.getId(),
currentAuthentication.getCurrentOrSubstitutedUser(),
inputValueMetaClass);

ScreenContext screenContext = UiControllerUtils.getScreenContext(screen);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class ReportExecutionDialog extends StandardLookup<Report> {
@Install(to = "reportsDl", target = Target.DATA_LOADER)
protected List<Report> reportsDlLoadDelegate(LoadContext<Report> loadContext) {
return reportSecurityManager.getAvailableReports(screenParameter,
currentAuthentication.getUser(),
currentAuthentication.getCurrentOrSubstitutedUser(),
metaClassParameter);
}

Expand All @@ -96,7 +96,7 @@ protected void onApplyFilterBtnClick(Button.ClickEvent event) {

protected void filterReports() {
List<Report> reports = reportSecurityManager.getAvailableReports(screenParameter,
currentAuthentication.getUser(),
currentAuthentication.getCurrentOrSubstitutedUser(),
metaClassParameter)
.stream()
.filter(this::filterReport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void onInit(InitEvent event) {
protected void onBeforeShow(BeforeShowEvent event) {
List<Report> reports = this.reports;
if (reports == null) {
reports = reportSecurityManager.getAvailableReports(screenParameter, currentAuthentication.getUser(),
reports = reportSecurityManager.getAvailableReports(screenParameter, currentAuthentication.getCurrentOrSubstitutedUser(),
metaClassParameter);
}

Expand Down Expand Up @@ -173,7 +173,7 @@ protected void filterReports() {
Date dateFilterValue = updatedDateFilter.getValue();

List<Report> reports =
reportSecurityManager.getAvailableReports(screenParameter, currentAuthentication.getUser(),
reportSecurityManager.getAvailableReports(screenParameter, currentAuthentication.getCurrentOrSubstitutedUser(),
metaClassParameter)
.stream()
.filter(report -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ protected void onBeforeShow(BeforeShowEvent event) {
@Subscribe(id = "reportsDl", target = Target.DATA_LOADER)
public void onReportsDlPostLoad(CollectionLoader.PostLoadEvent<Report> event) {
List<Report> entities = event.getLoadedEntities();
List<Report> availableReports = reportSecurityManager.getAvailableReports(null, currentAuthentication.getUser(), null);
List<Report> availableReports = reportSecurityManager.getAvailableReports(
null,
currentAuthentication.getCurrentOrSubstitutedUser(),
null);
entities.retainAll(availableReports);
reportsDc.setItems(entities);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ public void setPivotTableData(byte[] pivotTableData) {
@Subscribe(id = "reportsDl", target = Target.DATA_LOADER)
public void onReportsDlPostLoad(CollectionLoader.PostLoadEvent<Report> event) {
List<Report> entities = event.getLoadedEntities();
List<Report> availableReports = reportSecurityManager.getAvailableReports(null, currentAuthentication.getUser(), null);
List<Report> availableReports = reportSecurityManager.getAvailableReports(
null,
currentAuthentication.getCurrentOrSubstitutedUser(),
null);
entities.retainAll(availableReports);
reportsDc.setItems(entities);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package io.jmix.reports;

import io.jmix.core.*;
import io.jmix.core.metamodel.model.MetaClass;
import io.jmix.data.QueryTransformer;
import io.jmix.data.QueryTransformerFactory;
import io.jmix.core.metamodel.model.MetaClass;
import io.jmix.dynattr.DynAttrQueryHints;
import io.jmix.reports.entity.Report;
import io.jmix.security.model.BaseRole;
Expand Down

0 comments on commit 3f23f59

Please sign in to comment.