Search in sources :

Example 1 with SecurityContextAwareCallable

use of com.evolveum.midpoint.web.component.SecurityContextAwareCallable in project midpoint by Evolveum.

the class PageSelfDashboard method initMyAccounts.

private void initMyAccounts() {
    AsyncDashboardPanel<Object, List<SimpleAccountDto>> accounts = new AsyncDashboardPanel<Object, List<SimpleAccountDto>>(ID_ACCOUNTS, createStringResource("PageDashboard.accounts"), GuiStyleConstants.CLASS_SHADOW_ICON_ACCOUNT, GuiStyleConstants.CLASS_OBJECT_SHADOW_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>> createCallable(Authentication auth, IModel<Object> callableParameterModel) {
            return new SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>>(getSecurityEnforcer(), auth) {

                @Override
                public AccountCallableResult<List<SimpleAccountDto>> callWithContextPrepared() throws Exception {
                    return loadAccounts();
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            return new MyAccountsPanel(markupId, new PropertyModel<List<SimpleAccountDto>>(getModel(), CallableResult.F_VALUE));
        }

        @Override
        protected void onPostSuccess(AjaxRequestTarget target) {
            showFetchResult();
            super.onPostSuccess(target);
        }

        @Override
        protected void onUpdateError(AjaxRequestTarget target, Exception ex) {
            showFetchResult();
            super.onUpdateError(target, ex);
        }

        private void showFetchResult() {
            AccountCallableResult<List<SimpleAccountDto>> result = (AccountCallableResult<List<SimpleAccountDto>>) getModel().getObject();
            PageBase page = (PageBase) getPage();
            for (OperationResult res : result.getFetchResults()) {
                if (!WebComponentUtil.isSuccessOrHandledError(res)) {
                    page.showResult(res);
                }
            }
        }
    };
    accounts.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_ACCOUNTS);
            return WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(accounts);
}
Also used : IModel(org.apache.wicket.model.IModel) SimpleAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AsyncDashboardPanel(com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel) MyAccountsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyAccountsPanel) Authentication(org.springframework.security.core.Authentication) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) CallableResult(com.evolveum.midpoint.web.component.util.CallableResult) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)

Example 2 with SecurityContextAwareCallable

use of com.evolveum.midpoint.web.component.SecurityContextAwareCallable in project midpoint by Evolveum.

the class PageSelfDashboard method initLayout.

private void initLayout() {
    DashboardSearchPanel dashboardSearchPanel = new DashboardSearchPanel(ID_SEARCH_PANEL);
    List<String> searchPanelActions = Arrays.asList(AuthorizationConstants.AUTZ_UI_USERS_ALL_URL, AuthorizationConstants.AUTZ_UI_USERS_URL, AuthorizationConstants.AUTZ_UI_RESOURCES_ALL_URL, AuthorizationConstants.AUTZ_UI_RESOURCES_URL, AuthorizationConstants.AUTZ_UI_TASKS_ALL_URL, AuthorizationConstants.AUTZ_UI_TASKS_URL);
    dashboardSearchPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.SEARCH);
            return WebComponentUtil.getElementVisibility(visibilityType, searchPanelActions);
        }
    });
    add(dashboardSearchPanel);
    LinksPanel linksPanel = new LinksPanel(ID_LINKS_PANEL, Model.ofList(loadLinksList()));
    linksPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.SHORTCUTS);
            return WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(linksPanel);
    // TODO is this correct? [med]
    application = getApplication();
    final Session session = Session.get();
    AsyncDashboardPanel<Object, List<CaseWorkItemType>> workItemsPanel = new AsyncDashboardPanel<>(ID_WORK_ITEMS_PANEL, createStringResource("PageSelfDashboard.workItems"), GuiStyleConstants.CLASS_OBJECT_WORK_ITEM_ICON, GuiStyleConstants.CLASS_OBJECT_WORK_ITEM_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<CaseWorkItemType>>> createCallable(Authentication auth, IModel callableParameterModel) {
            return new SecurityContextAwareCallable<>(getSecurityContextManager(), auth) {

                @Override
                public CallableResult<List<CaseWorkItemType>> callWithContextPrepared() {
                    // it is ignored anyway - FIXME
                    return new CallableResult<>(emptyList(), null);
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            CaseWorkItemsPanel workItemsPanel = new CaseWorkItemsPanel(markupId, CaseWorkItemsPanel.View.DASHBOARD) {

                private static final long serialVersionUID = 1L;

                @Override
                protected ObjectFilter getCaseWorkItemsFilter() {
                    return QueryUtils.filterForNotClosedStateAndAssignees(getPrismContext().queryFor(CaseWorkItemType.class), AuthUtil.getPrincipalUser(), OtherPrivilegesLimitationType.F_APPROVAL_WORK_ITEMS, getRelationRegistry()).desc(F_CREATE_TIMESTAMP).buildFilter();
                }
            };
            workItemsPanel.setOutputMarkupId(true);
            return workItemsPanel;
        }
    };
    workItemsPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_WORKITEMS);
            return getCaseManager().isEnabled() && WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(workItemsPanel);
    AsyncDashboardPanel<Object, List<CaseType>> myRequestsPanel = new AsyncDashboardPanel<>(ID_REQUESTS_PANEL, createStringResource("PageSelfDashboard.myRequests"), GuiStyleConstants.CLASS_SHADOW_ICON_REQUEST, GuiStyleConstants.CLASS_OBJECT_SERVICE_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<CaseType>>> createCallable(Authentication auth, IModel callableParameterModel) {
            return new SecurityContextAwareCallable<>(getSecurityContextManager(), auth) {

                @Override
                public CallableResult<List<CaseType>> callWithContextPrepared() {
                    // it is ignored anyway - FIXME
                    return new CallableResult<>(emptyList(), null);
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            return new CasesTablePanel(markupId) {

                @Override
                protected ObjectFilter getCasesFilter() {
                    return QueryUtils.filterForMyRequests(getPrismContext().queryFor(CaseType.class), AuthUtil.getPrincipalUser().getOid()).desc(ItemPath.create(CaseType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP)).buildFilter();
                }

                @Override
                protected boolean isDashboard() {
                    return true;
                }

                @Override
                protected UserProfileStorage.TableId getTableId() {
                    return UserProfileStorage.TableId.PAGE_CASE_CHILD_CASES_TAB;
                }
            };
        }
    };
    myRequestsPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_REQUESTS);
            return getCaseManager().isEnabled() && WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(myRequestsPanel);
    initMyAccounts(session);
    initAssignments();
}
Also used : IModel(org.apache.wicket.model.IModel) LinksPanel(com.evolveum.midpoint.web.page.self.component.LinksPanel) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) DashboardSearchPanel(com.evolveum.midpoint.web.page.self.component.DashboardSearchPanel) CaseWorkItemsPanel(com.evolveum.midpoint.web.page.admin.cases.CaseWorkItemsPanel) AsyncDashboardPanel(com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) Authentication(org.springframework.security.core.Authentication) CasesTablePanel(com.evolveum.midpoint.web.page.admin.server.CasesTablePanel) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collections.emptyList(java.util.Collections.emptyList) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) CallableResult(com.evolveum.midpoint.web.component.util.CallableResult) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) Session(org.apache.wicket.Session)

Example 3 with SecurityContextAwareCallable

use of com.evolveum.midpoint.web.component.SecurityContextAwareCallable in project midpoint by Evolveum.

the class AsyncWebProcessManagerImpl method submit.

@Override
public void submit(@NotNull String processId, @NotNull Callable callable) {
    AsyncWebProcess process = getProcess(processId);
    if (process == null) {
        throw new IllegalStateException("Process with id '" + processId + "' doesn't exist");
    }
    Callable<?> securityAware = callable;
    if (!(callable instanceof SecurityContextAwareCallable)) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        SecurityContextManager secManager = application.getSecurityContextManager();
        securityAware = new SecurityContextAwareCallable(secManager, auth) {

            @Override
            public Object callWithContextPrepared() throws Exception {
                return callable.call();
            }
        };
    }
    Future<?> future = executor.submit(securityAware);
    process.setFuture(future);
}
Also used : Authentication(org.springframework.security.core.Authentication) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager)

Example 4 with SecurityContextAwareCallable

use of com.evolveum.midpoint.web.component.SecurityContextAwareCallable in project midpoint by Evolveum.

the class ProgressAwareChangesExecutorImpl method executeChangesAsync.

private void executeChangesAsync(ProgressPanel progressPanel, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
    MidPointApplication application = MidPointApplication.get();
    final ModelInteractionService modelInteraction = application.getModelInteractionService();
    final ModelService model = application.getModel();
    final SecurityContextManager secManager = application.getSecurityContextManager();
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    final HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    AsyncWebProcessModel<ProgressReporter> reporterModel = progressPanel.getReporterModel();
    Callable<Void> execution = new SecurityContextAwareCallable<>(secManager, auth, connInfo) {

        @Override
        public Void callWithContextPrepared() {
            ProgressReporter reporter = reporterModel.getProcessData();
            try {
                LOGGER.debug("Execution start");
                reporter.recordExecutionStart();
                if (previewOnly) {
                    ModelContext previewResult = modelInteraction.previewChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setPreviewResult(previewResult);
                } else if (deltas != null && deltas.size() > 0) {
                    Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = model.executeChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setObjectDeltaOperation(executedDeltas);
                }
            } catch (CommonException | RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
                if (!result.isFatalError()) {
                    // just to be sure the exception is recorded into the result
                    result.recordFatalError(e.getMessage(), e);
                }
            } finally {
                LOGGER.debug("Execution finish {}", result);
            }
            reporter.recordExecutionStop();
            // signals that the operation has finished
            reporter.setAsyncOperationResult(result);
            return null;
        }
    };
    // to disable showing not-final results (why does it work? and why is the result shown otherwise?)
    result.setInProgress();
    AsyncWebProcessManager manager = application.getAsyncWebProcessManager();
    manager.submit(reporterModel.getId(), execution);
}
Also used : ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) ProgressReporter(com.evolveum.midpoint.web.component.progress.ProgressReporter) ModelService(com.evolveum.midpoint.model.api.ModelService) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) Authentication(org.springframework.security.core.Authentication) Collection(java.util.Collection) AsyncWebProcessManager(com.evolveum.midpoint.web.application.AsyncWebProcessManager) CommonException(com.evolveum.midpoint.util.exception.CommonException) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager)

Example 5 with SecurityContextAwareCallable

use of com.evolveum.midpoint.web.component.SecurityContextAwareCallable in project midpoint by Evolveum.

the class PageSelfDashboard method initAssignments.

private void initAssignments() {
    AsyncDashboardPanel<Object, List<AssignmentItemDto>> assignedOrgUnits = new AsyncDashboardPanel<>(ID_ASSIGNMENTS, createStringResource("PageDashboard.assignments"), GuiStyleConstants.CLASS_ICON_ASSIGNMENTS, GuiStyleConstants.CLASS_OBJECT_ROLE_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<AssignmentItemDto>>> createCallable(Authentication auth, IModel callableParameterModel) {
            return new SecurityContextAwareCallable<>(getSecurityContextManager(), auth) {

                @Override
                public CallableResult<List<AssignmentItemDto>> callWithContextPrepared() {
                    return loadAssignments();
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            return new MyAssignmentsPanel(markupId, new PropertyModel<>(getModel(), CallableResult.F_VALUE));
        }
    };
    assignedOrgUnits.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_ASSIGNMENTS);
            return WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(assignedOrgUnits);
}
Also used : IModel(org.apache.wicket.model.IModel) MyAssignmentsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyAssignmentsPanel) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) AsyncDashboardPanel(com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel) Authentication(org.springframework.security.core.Authentication) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collections.emptyList(java.util.Collections.emptyList) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) CallableResult(com.evolveum.midpoint.web.component.util.CallableResult) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) AssignmentItemDto(com.evolveum.midpoint.web.page.admin.home.dto.AssignmentItemDto)

Aggregations

SecurityContextAwareCallable (com.evolveum.midpoint.web.component.SecurityContextAwareCallable)8 Authentication (org.springframework.security.core.Authentication)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 SecurityContextManager (com.evolveum.midpoint.security.api.SecurityContextManager)4 CallableResult (com.evolveum.midpoint.web.component.util.CallableResult)4 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)4 AsyncDashboardPanel (com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel)4 AccountCallableResult (com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)4 IModel (org.apache.wicket.model.IModel)4 Collections.emptyList (java.util.Collections.emptyList)3 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)2 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)2 ModelService (com.evolveum.midpoint.model.api.ModelService)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)2 CommonException (com.evolveum.midpoint.util.exception.CommonException)2 AsyncWebProcessManager (com.evolveum.midpoint.web.application.AsyncWebProcessManager)2 MyAccountsPanel (com.evolveum.midpoint.web.page.admin.home.component.MyAccountsPanel)2 SimpleAccountDto (com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto)2