Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed May 29, 2014
2 parents 0e871a0 + f259389 commit 1c4908c
Show file tree
Hide file tree
Showing 116 changed files with 17,432 additions and 12,845 deletions.
5 changes: 5 additions & 0 deletions build-system/pom.xml
Expand Up @@ -271,6 +271,11 @@
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -129,5 +129,5 @@ public boolean isVisible() {
* @param callableParameterModel Model providing access to parameters needed by the callable
* @return A callable instance that encapsulates the logic needed to obtain the panel data
*/
protected abstract Callable<T> createCallable(Authentication auth, IModel<V> callableParameterModel);
protected abstract SecurityContextAwareCallable<T> createCallable(Authentication auth, IModel<V> callableParameterModel);
}
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2010-2014 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.web.component;

import com.evolveum.midpoint.security.api.SecurityEnforcer;
import org.apache.commons.lang.Validate;
import org.springframework.security.core.Authentication;

import java.util.concurrent.Callable;

/**
* @author lazyman
*/
public abstract class SecurityContextAwareCallable<V> implements Callable<V> {

private SecurityEnforcer enforcer;
private Authentication authentication;

protected SecurityContextAwareCallable(SecurityEnforcer enforcer, Authentication authentication) {
Validate.notNull(enforcer, "Security enforcer must not be null.");

this.enforcer = enforcer;
this.authentication = authentication;
}

@Override
public final V call() throws Exception {
enforcer.setupPreAuthenticatedSecurityContext(authentication);

try {
return callWithContextPrepared();
} finally {
enforcer.setupPreAuthenticatedSecurityContext((Authentication) null);
//todo cleanup security context
}
}

public abstract V callWithContextPrepared() throws Exception;
}
Expand Up @@ -16,8 +16,10 @@

package com.evolveum.midpoint.web.component.message;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.page.admin.PageAdmin;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;
Expand Down Expand Up @@ -101,10 +103,10 @@ public OpResult(OperationResult result) {
try {
OperationResultType resultType = result.createOperationResultType();
ObjectFactory of = new ObjectFactory();
xml = getPrismContext().getJaxbDomHack().marshalElementToString(of.createOperationResult(resultType));
} catch (JAXBException ex) {
xml = getPrismContext().serializeAtomicValue(of.createOperationResult(resultType), PrismContext.LANG_XML);
} catch (SchemaException ex) {
error("Can't create xml: " + ex);
}
}
}

public List<OpResult> getSubresults() {
Expand Down
Expand Up @@ -64,6 +64,7 @@ pageTasks.runsContinually=runs continually

pageTasks.category.AllCategories=All categories
pageTasks.category.Demo=Demo
pageTasks.category.BulkActions=Bulk actions
pageTasks.category.ImportFromFile=Import from file
pageTasks.category.ImportingAccounts=Importing accounts
pageTasks.category.LiveSynchronization=Live synchronization
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.SecurityContextAwareCallable;
import com.evolveum.midpoint.web.component.assignment.AssignmentEditorDtoType;
import com.evolveum.midpoint.web.component.util.CallableResult;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
Expand Down Expand Up @@ -209,12 +210,14 @@ private void initSystemInfo() {
"fa fa-fw fa-tachometer", DashboardColor.GREEN) {

@Override
protected Callable<CallableResult<SystemInfoDto>> createCallable(final Authentication auth,
IModel callableParameterModel) {
return new Callable<CallableResult<SystemInfoDto>>() {
protected SecurityContextAwareCallable<CallableResult<SystemInfoDto>> createCallable(
Authentication auth, IModel callableParameterModel) {

return new SecurityContextAwareCallable<CallableResult<SystemInfoDto>>(
getSecurityEnforcer(), auth) {

@Override
public CallableResult<SystemInfoDto> call() throws Exception {
public CallableResult<SystemInfoDto> callWithContextPrepared() throws Exception {
CallableResult callableResult = new CallableResult();

//TODO - fill correct data in users and tasks graphs[shood]
Expand Down Expand Up @@ -246,12 +249,14 @@ private void initMyWorkItems() {
"fa fa-fw fa-tasks", DashboardColor.RED) {

@Override
protected Callable<CallableResult<List<WorkItemDto>>> createCallable(final Authentication auth,
IModel callableParameterModel) {
return new Callable<CallableResult<List<WorkItemDto>>>() {
protected SecurityContextAwareCallable<CallableResult<List<WorkItemDto>>> createCallable(
Authentication auth, IModel callableParameterModel) {

return new SecurityContextAwareCallable<CallableResult<List<WorkItemDto>>>(
getSecurityEnforcer(), auth) {

@Override
public CallableResult<List<WorkItemDto>> call() throws Exception {
public CallableResult<List<WorkItemDto>> callWithContextPrepared() throws Exception {
return loadWorkItems();
}
};
Expand All @@ -278,15 +283,15 @@ private void initMyAccounts() {
"fa fa-fw fa-external-link", DashboardColor.BLUE) {

@Override
protected Callable<CallableResult<List<SimpleAccountDto>>> createCallable(final Authentication auth,
IModel<Object> callableParameterModel) {
protected SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>> createCallable(
Authentication auth, IModel<Object> callableParameterModel) {

return new Callable<CallableResult<List<SimpleAccountDto>>>() {
return new SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>>(
getSecurityEnforcer(), auth) {

@Override
public AccountCallableResult<List<SimpleAccountDto>> call() throws Exception {
// getSecurityEnforcer().setupPreAuthenticatedSecurityContext();

public AccountCallableResult<List<SimpleAccountDto>> callWithContextPrepared()
throws Exception {
return loadAccounts();
}
};
Expand Down Expand Up @@ -331,14 +336,14 @@ private void initAssignments() {
"fa fa-fw fa-star", DashboardColor.YELLOW) {

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

@Override
public CallableResult<List<AssignmentItemDto>> call() throws Exception {
getSecurityEnforcer().setupPreAuthenticatedSecurityContext(auth);
return new SecurityContextAwareCallable<CallableResult<List<AssignmentItemDto>>>(
getSecurityEnforcer(), auth) {

@Override
public CallableResult<List<AssignmentItemDto>> callWithContextPrepared() throws Exception {
return loadAssignments();
}
};
Expand Down
Expand Up @@ -38,6 +38,7 @@ pageTask.category.Demo=Demo
pageTask.category.ImportFromFile=Import from file
pageTask.category.ImportingAccounts=Importing accounts
pageTask.category.LiveSynchronization=Live synchronization
pageTask.category.BulkActions=Bulk actions
pageTask.category.Reconciliation=Reconciliation
pageTask.category.UserRecomputation=User recomputation
pageTask.category.Workflow=Workflow
Expand Down
Expand Up @@ -186,6 +186,7 @@ <h2><wicket:message key="pageTaskEdit.opResult"/></h2>

<a class="btn btn-danger" wicket:id="suspend" />
<a class="btn btn-success" wicket:id="resume" />
<a class="btn btn-success" wicket:id="runNow" />
</div>
</form>
</wicket:extend>
Expand Down
Expand Up @@ -117,6 +117,7 @@ public class PageTaskEdit extends PageAdminTasks {
private static final String OPERATION_SAVE_TASK = DOT_CLASS + "saveTask";
private static final String OPERATION_SUSPEND_TASKS = DOT_CLASS + "suspendTask";
private static final String OPERATION_RESUME_TASK = DOT_CLASS + "resumeTask";
private static final String OPERATION_RUN_NOW_TASK = DOT_CLASS + "runNowTask";

private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_IDENTIFIER = "identifier";
Expand All @@ -136,6 +137,7 @@ public class PageTaskEdit extends PageAdminTasks {
private static final String ID_OPERATION_RESULT_PANEL = "operationResultPanel";
private static final String ID_SUSPEND = "suspend";
private static final String ID_RESUME = "resume";
private static final String ID_RUN_NOW = "runNow";
private static final String ID_DRY_RUN = "dryRun";

private IModel<TaskDto> model;
Expand Down Expand Up @@ -169,11 +171,30 @@ private boolean isRunnableOrRunning() {
return TaskDtoExecutionStatus.RUNNABLE.equals(exec) || TaskDtoExecutionStatus.RUNNING.equals(exec);
}

private boolean isRunnable() {
TaskDtoExecutionStatus exec = model.getObject().getExecution();
return TaskDtoExecutionStatus.RUNNABLE.equals(exec);
}

private boolean isRunning() {
TaskDtoExecutionStatus exec = model.getObject().getExecution();
return TaskDtoExecutionStatus.RUNNING.equals(exec);
}

private boolean isClosed() {
TaskDtoExecutionStatus exec = model.getObject().getExecution();
return TaskDtoExecutionStatus.CLOSED.equals(exec);
}

private boolean isRecurring() {
return model.getObject().getRecurring();
}

private boolean isSuspended() {
TaskDtoExecutionStatus exec = model.getObject().getExecution();
return TaskDtoExecutionStatus.SUSPENDED.equals(exec);
}

private TaskDto loadTask() {
OperationResult result = new OperationResult(OPERATION_LOAD_TASK);
Task operationTask = getTaskManager().createTaskInstance(OPERATION_LOAD_TASK);
Expand Down Expand Up @@ -695,7 +716,7 @@ public void onClick(AjaxRequestTarget target) {

@Override
public boolean isVisible() {
return isRunnableOrRunning();
return !edit && isRunnableOrRunning();
}
});
mainForm.add(suspend);
Expand All @@ -711,11 +732,27 @@ public void onClick(AjaxRequestTarget target) {

@Override
public boolean isVisible() {
return !isRunning();
return !edit && (isSuspended() || (isClosed() && isRecurring()));
}
});
mainForm.add(resume);
}

AjaxButton runNow = new AjaxButton(ID_RUN_NOW, createStringResource("pageTaskEdit.button.runNow")) {

@Override
public void onClick(AjaxRequestTarget target) {
runNowPerformed(target);
}
};
runNow.add(new VisibleEnableBehaviour() {

@Override
public boolean isVisible() {
return !edit && (isRunnable() || (isClosed() && !isRecurring()));
}
});
mainForm.add(runNow);
}

private List<IColumn<OperationResult, String>> initResultColumns() {
List<IColumn<OperationResult, String>> columns = new ArrayList<IColumn<OperationResult, String>>();
Expand Down Expand Up @@ -864,7 +901,25 @@ private void resumePerformed(AjaxRequestTarget target) {
setResponsePage(PageTasks.class);
}

private static class EmptyOnBlurAjaxFormUpdatingBehaviour extends AjaxFormComponentUpdatingBehavior {
private void runNowPerformed(AjaxRequestTarget target) {
String oid = model.getObject().getOid();
OperationResult result = new OperationResult(OPERATION_RUN_NOW_TASK);
try {
getTaskService().scheduleTasksNow(Arrays.asList(oid), result);
result.computeStatus();

if (result.isSuccess()) {
result.recordStatus(OperationResultStatus.SUCCESS, "The task has been successfully scheduled to run.");
}
} catch (RuntimeException e) {
result.recordFatalError("Couldn't schedule the task due to an unexpected exception", e);
}

showResultInSession(result);
setResponsePage(PageTasks.class);
}

private static class EmptyOnBlurAjaxFormUpdatingBehaviour extends AjaxFormComponentUpdatingBehavior {

public EmptyOnBlurAjaxFormUpdatingBehaviour() {
super("onBlur");
Expand Down
Expand Up @@ -19,6 +19,7 @@ pageTaskEdit.button.back=Back
pageTaskEdit.button.save=Save
pageTaskEdit.button.edit=Edit
pageTaskEdit.button.resume=Resume
pageTaskEdit.button.runNow=Run now
pageTaskEdit.button.suspend=Suspend

pageTaskEdit.basic=Basic
Expand Down
Expand Up @@ -93,6 +93,7 @@ public void validate(Form<?> form) {
error(interval, "pageTask.scheduleValidation.bothIntervalAndCron");
}

// there can be recurring tasks that are started only on demand, so we allow specifying no timing information
// if (interval.getModelObject() == null && StringUtils.isEmpty(cron.getModelObject())) {
// error(interval, "pageTask.scheduleValidation.neitherIntervalNorCron");
// }
Expand Down
Expand Up @@ -383,6 +383,14 @@ public List<String> getHandlerUriList() {
public boolean getBound() {
return taskType.getBinding() == TaskBindingType.TIGHT;
}

public void setBound(boolean value) {
if (value) {
taskType.setBinding(TaskBindingType.TIGHT);
} else {
taskType.setBinding(TaskBindingType.LOOSE);
}
}

public Integer getInterval() {
return interval;
Expand Down Expand Up @@ -419,6 +427,14 @@ public ThreadStopActionType getThreadStop() {
public boolean getRecurring() {
return taskType.getRecurrence() == TaskRecurrenceType.RECURRING;
}

public void setRecurring(boolean value) {
if (value) {
taskType.setRecurrence(TaskRecurrenceType.RECURRING);
} else {
taskType.setRecurrence(TaskRecurrenceType.SINGLE);
}
}

public Long getCurrentRuntime() {
if (isRunNotFinished()) {
Expand Down

0 comments on commit 1c4908c

Please sign in to comment.