use of com.evolveum.midpoint.web.component.SecurityContextAwareCallable in project midpoint by Evolveum.
the class PageSelfDashboard method initMyAccounts.
private void initMyAccounts(Session session) {
AsyncDashboardPanel<Object, List<SimpleAccountDto>> accounts = new AsyncDashboardPanel<>(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<>(getSecurityContextManager(), auth) {
@Override
public AccountCallableResult<List<SimpleAccountDto>> callWithContextPrepared() {
// TODO is this correct? [med]
setupContext(application, session);
return loadAccounts();
}
};
}
@Override
protected Component getMainComponent(String markupId) {
return new MyAccountsPanel(markupId, new PropertyModel<>(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);
}
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, Runnable runnable) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
SecurityContextManager secManager = application.getSecurityContextManager();
submit(processId, new SecurityContextAwareCallable(secManager, auth) {
@Override
public Object callWithContextPrepared() {
runnable.run();
return null;
}
});
}
use of com.evolveum.midpoint.web.component.SecurityContextAwareCallable in project midpoint by Evolveum.
the class ProgressPanel method executeChangesAsync.
private void executeChangesAsync(ProgressReporter reporter, 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();
Callable<Void> execution = new SecurityContextAwareCallable<Void>(secManager, auth, connInfo) {
@Override
public Void callWithContextPrepared() throws Exception {
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);
}
Aggregations