use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class ToolsUtils method serializeObject.
public static void serializeObject(Object object, Writer writer) throws JAXBException {
if (object == null) {
return;
}
Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
if (object instanceof ObjectType) {
object = new JAXBElement(C_OBJECT, Object.class, object);
}
marshaller.marshal(object, writer);
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class PageAdminObjectDetails method saveOrPreviewPerformed.
public void saveOrPreviewPerformed(AjaxRequestTarget target, OperationResult result, boolean previewOnly) {
boolean isAnythingChanged = processDeputyAssignments();
ObjectWrapper<O> objectWrapper = getObjectWrapper();
LOGGER.debug("Saving object {}", objectWrapper);
// todo: improve, delta variable is quickfix for MID-1006
// redirecting to user list page everytime user is created in repository
// during user add in gui,
// and we're not taking care about account/assignment create errors
// (error message is still displayed)
delta = null;
Task task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
ModelExecuteOptions options = getExecuteChangesOptions();
LOGGER.debug("Using execute options {}.", new Object[] { options });
try {
reviveModels();
delta = objectWrapper.getObjectDelta();
if (objectWrapper.getOldDelta() != null) {
delta = ObjectDelta.summarize(objectWrapper.getOldDelta(), delta);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("User delta computed from form:\n{}", new Object[] { delta.debugDump(3) });
}
} catch (Exception ex) {
result.recordFatalError(getString("pageUser.message.cantCreateUser"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
showResult(result);
return;
}
switch(objectWrapper.getStatus()) {
case ADDING:
try {
PrismObject<O> objectToAdd = delta.getObjectToAdd();
WebComponentUtil.encryptCredentials(objectToAdd, true, getMidpointApplication());
prepareObjectForAdd(objectToAdd);
getPrismContext().adopt(objectToAdd, getCompileTimeClass());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta before add user:\n{}", new Object[] { delta.debugDump(3) });
}
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
final Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
final Collection<SimpleValidationError> validationErrors = performCustomValidation(objectToAdd, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
} else {
result.recordSuccess();
}
} catch (Exception ex) {
result.recordFatalError(getString("pageFocus.message.cantCreateFocus"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
showResult(result);
}
break;
case MODIFYING:
try {
WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
prepareObjectDeltaForModify(delta);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta before modify user:\n{}", new Object[] { delta.debugDump(3) });
}
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
deltas.add(delta);
}
List<ObjectDelta<? extends ObjectType>> additionalDeltas = getAdditionalModifyDeltas(result);
if (additionalDeltas != null) {
for (ObjectDelta additionalDelta : additionalDeltas) {
if (!additionalDelta.isEmpty()) {
additionalDelta.revive(getPrismContext());
deltas.add(additionalDelta);
}
}
}
if (delta.isEmpty() && ModelExecuteOptions.isReconcile(options)) {
ObjectDelta emptyDelta = ObjectDelta.createEmptyModifyDelta(getCompileTimeClass(), objectWrapper.getObject().getOid(), getPrismContext());
deltas.add(emptyDelta);
Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
} else if (!deltas.isEmpty()) {
Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
} else {
// from previous attempts (useful only if we would call finishProcessing at the end, but that's not the case now)
progressReporter.clearProgressPanel();
if (!previewOnly) {
if (!isAnythingChanged) {
result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
showResult(result);
}
redirectBack();
} else {
warn(getString("PageAdminObjectDetails.noChangesPreview"));
target.add(getFeedbackPanel());
}
}
} catch (Exception ex) {
if (!executeForceDelete(objectWrapper, task, options, result)) {
result.recordFatalError(getString("pageUser.message.cantUpdateUser"), ex);
LoggingUtils.logUnexpectedException(LOGGER, getString("pageUser.message.cantUpdateUser"), ex);
} else {
result.recomputeStatus();
}
showResult(result);
}
break;
// support for add/delete containers (e.g. delete credentials)
default:
error(getString("pageAdminFocus.message.unsupportedState", objectWrapper.getStatus()));
}
// result.recomputeStatus();
//
// if (!result.isInProgress()) {
// LOGGER.trace("Result NOT in progress, calling finishProcessing");
// finishProcessing(target, result, false);
// }
LOGGER.trace("returning from saveOrPreviewPerformed");
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class WorkItemPanel method initLayout.
protected void initLayout(Form mainForm, PageBase pageBase) {
WebMarkupContainer additionalInfoColumn = new WebMarkupContainer(ID_ADDITIONAL_INFO_COLUMN);
WebMarkupContainer historyContainer = new WebMarkupContainer(ID_HISTORY_CONTAINER);
historyContainer.add(new ItemApprovalHistoryPanel(ID_HISTORY, new PropertyModel<>(getModel(), WorkItemDto.F_WORKFLOW_CONTEXT), UserProfileStorage.TableId.PAGE_WORK_ITEM_HISTORY_PANEL, (int) pageBase.getItemsPerPage(UserProfileStorage.TableId.PAGE_WORK_ITEM_HISTORY_PANEL)));
final VisibleEnableBehaviour historyContainerVisible = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getModelObject().hasHistory();
}
};
historyContainer.add(historyContainerVisible);
historyContainer.add(WebComponentUtil.createHelp(ID_HISTORY_HELP));
additionalInfoColumn.add(historyContainer);
WebMarkupContainer relatedWorkItemsContainer = new WebMarkupContainer(ID_RELATED_WORK_ITEMS_CONTAINER);
final IModel<List<WorkItemDto>> relatedWorkItemsModel = new PropertyModel<>(getModel(), WorkItemDto.F_OTHER_WORK_ITEMS);
final ISortableDataProvider<WorkItemDto, String> relatedWorkItemsProvider = new ListDataProvider<>(this, relatedWorkItemsModel);
relatedWorkItemsContainer.add(new WorkItemsPanel(ID_RELATED_WORK_ITEMS, relatedWorkItemsProvider, null, 10, WorkItemsPanel.View.ITEMS_FOR_PROCESS));
final VisibleEnableBehaviour relatedWorkItemsContainerVisible = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !relatedWorkItemsModel.getObject().isEmpty();
}
};
relatedWorkItemsContainer.add(relatedWorkItemsContainerVisible);
relatedWorkItemsContainer.add(WebComponentUtil.createHelp(ID_RELATED_WORK_ITEMS_HELP));
additionalInfoColumn.add(relatedWorkItemsContainer);
final WebMarkupContainer relatedWorkflowRequestsContainer = new WebMarkupContainer(ID_RELATED_REQUESTS_CONTAINER);
final IModel<List<ProcessInstanceDto>> relatedWorkflowRequestsModel = new PropertyModel<>(getModel(), WorkItemDto.F_RELATED_WORKFLOW_REQUESTS);
final ISortableDataProvider<ProcessInstanceDto, String> relatedWorkflowRequestsProvider = new ListDataProvider<>(this, relatedWorkflowRequestsModel);
relatedWorkflowRequestsContainer.add(new ProcessInstancesPanel(ID_RELATED_REQUESTS, relatedWorkflowRequestsProvider, null, 10, ProcessInstancesPanel.View.TASKS_FOR_PROCESS, new PropertyModel<>(getModel(), WorkItemDto.F_PROCESS_INSTANCE_ID)));
final VisibleEnableBehaviour relatedWorkflowRequestsContainerVisible = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !relatedWorkflowRequestsModel.getObject().isEmpty();
}
};
relatedWorkflowRequestsContainer.add(relatedWorkflowRequestsContainerVisible);
relatedWorkflowRequestsContainer.add(WebComponentUtil.createHelp(ID_RELATED_REQUESTS_HELP));
additionalInfoColumn.add(relatedWorkflowRequestsContainer);
final VisibleEnableBehaviour additionalInfoColumnVisible = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return historyContainerVisible.isVisible() || relatedWorkItemsContainerVisible.isVisible() || relatedWorkflowRequestsContainerVisible.isVisible();
}
};
additionalInfoColumn.add(additionalInfoColumnVisible);
add(additionalInfoColumn);
WebMarkupContainer primaryInfoColumn = new WebMarkupContainer(ID_PRIMARY_INFO_COLUMN);
// primaryInfoColumn.add(new Label(ID_REQUESTED_BY, new PropertyModel(getModel(), WorkItemDto.F_REQUESTER_NAME)));
// primaryInfoColumn.add(new Label(ID_REQUESTED_BY_FULL_NAME, new PropertyModel(getModel(), WorkItemDto.F_REQUESTER_FULL_NAME)));
// primaryInfoColumn.add(new Label(ID_REQUESTED_ON, new PropertyModel(getModel(), WorkItemDto.F_STARTED_FORMATTED_FULL)));
primaryInfoColumn.add(new Label(ID_WORK_ITEM_CREATED_ON, new PropertyModel(getModel(), WorkItemDto.F_CREATED_FORMATTED_FULL)));
primaryInfoColumn.add(new Label(ID_WORK_ITEM_DEADLINE, new PropertyModel(getModel(), WorkItemDto.F_DEADLINE_FORMATTED_FULL)));
primaryInfoColumn.add(new Label(ID_ORIGINALLY_ALLOCATED_TO, new PropertyModel(getModel(), WorkItemDto.F_ORIGINAL_ASSIGNEE_FULL)));
primaryInfoColumn.add(new Label(ID_CURRENTLY_ALLOCATED_TO, new PropertyModel(getModel(), WorkItemDto.F_CURRENT_ASSIGNEES_FULL)));
primaryInfoColumn.add(new Label(ID_CANDIDATES, new PropertyModel(getModel(), WorkItemDto.F_CANDIDATES)));
WebMarkupContainer stageInfoContainer = new WebMarkupContainer(ID_STAGE_INFO_CONTAINER);
primaryInfoColumn.add(stageInfoContainer);
stageInfoContainer.add(new Label(ID_STAGE_INFO, new PropertyModel<String>(getModel(), WorkItemDto.F_STAGE_INFO)));
stageInfoContainer.add(new VisibleBehaviour(() -> getModelObject().getStageInfo() != null));
WebMarkupContainer escalationLevelInfoContainer = new WebMarkupContainer(ID_ESCALATION_LEVEL_INFO_CONTAINER);
primaryInfoColumn.add(escalationLevelInfoContainer);
escalationLevelInfoContainer.add(new Label(ID_ESCALATION_LEVEL_INFO, new PropertyModel<String>(getModel(), WorkItemDto.F_ESCALATION_LEVEL_INFO)));
escalationLevelInfoContainer.add(new VisibleBehaviour(() -> getModelObject().getEscalationLevelInfo() != null));
WebMarkupContainer requesterCommentContainer = new WebMarkupContainer(ID_REQUESTER_COMMENT_CONTAINER);
requesterCommentContainer.setOutputMarkupId(true);
primaryInfoColumn.add(requesterCommentContainer);
requesterCommentContainer.add(new Label(ID_REQUESTER_COMMENT_MESSAGE, new PropertyModel<String>(getModel(), WorkItemDto.F_REQUESTER_COMMENT)));
//primaryInfoColumn.add(new ScenePanel(ID_DELTAS_TO_BE_APPROVED, new PropertyModel<SceneDto>(getModel(), WorkItemDto.F_DELTAS)));
primaryInfoColumn.add(new TaskChangesPanel(ID_DELTAS_TO_BE_APPROVED, new PropertyModel<>(getModel(), WorkItemDto.F_CHANGES)));
primaryInfoColumn.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return additionalInfoColumnVisible.isVisible() ? "col-md-5" : "col-md-12";
}
}));
add(primaryInfoColumn);
add(new AjaxFallbackLink(ID_SHOW_REQUEST) {
public void onClick(AjaxRequestTarget target) {
String oid = WorkItemPanel.this.getModelObject().getTaskOid();
if (oid != null) {
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, oid);
getPageBase().navigateToNext(PageTaskEdit.class, parameters);
}
}
});
add(WebComponentUtil.createHelp(ID_SHOW_REQUEST_HELP));
WebMarkupContainer additionalInformation = new InformationListPanel(ID_ADDITIONAL_INFORMATION, new PropertyModel<>(getModel(), WorkItemDto.F_ADDITIONAL_INFORMATION));
add(additionalInformation);
WorkItemDto dto = getModelObject();
ApprovalStageDefinitionType level = WfContextUtil.getCurrentStageDefinition(dto.getWorkflowContext());
WebMarkupContainer additionalAttribues = new WebMarkupContainer(ID_ADDITIONAL_ATTRIBUTES);
add(additionalAttribues);
additionalAttribues.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
public boolean isVisible() {
return (level != null && level.getFormRef() != null && level.getFormRef().getOid() != null);
}
;
});
if (level != null && level.getFormRef() != null && level.getFormRef().getOid() != null) {
String formOid = level.getFormRef().getOid();
ObjectType focus = dto.getFocus(pageBase);
if (focus == null) {
// TODO FIXME (this should not occur anyway)
focus = new UserType(pageBase.getPrismContext());
}
Task task = pageBase.createSimpleTask(OPERATION_LOAD_CUSTOM_FORM);
DynamicFormPanel<?> customForm = new DynamicFormPanel<>(ID_CUSTOM_FORM, focus.asPrismObject(), formOid, mainForm, task, pageBase);
additionalAttribues.add(customForm);
} else {
additionalAttribues.add(new Label(ID_CUSTOM_FORM));
}
add(new TextArea<>(ID_APPROVER_COMMENT, new PropertyModel<String>(getModel(), WorkItemDto.F_APPROVER_COMMENT)));
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class AssignExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
ActionParameterValueType resourceParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_RESOURCE, false, false, NAME);
ActionParameterValueType roleParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_ROLE, false, false, NAME);
Collection<ObjectReferenceType> resources;
if (resourceParameterValue != null) {
PipelineData data = expressionHelper.evaluateParameter(resourceParameterValue, null, input, context, globalResult);
resources = data.getDataAsReferences(ResourceType.COMPLEX_TYPE);
} else {
resources = null;
}
Collection<ObjectReferenceType> roles;
if (roleParameterValue != null) {
PipelineData data = expressionHelper.evaluateParameter(roleParameterValue, null, input, context, globalResult);
roles = data.getDataAsReferences(RoleType.COMPLEX_TYPE);
} else {
roles = null;
}
if (resources == null && roles == null) {
throw new ScriptExecutionException("Nothing to assign: neither resource nor role specified");
}
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof FocusType) {
PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, NAME, value, context);
}
context.println((exception != null ? "Attempted to modify " : "Modified ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject of FocusType"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
// TODO updated objects?
return input;
}
use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.
the class PageMyPasswordQuestions method updateQuestions.
private void updateQuestions(String useroid, AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_SAVE_QUESTIONS);
OperationResult result = new OperationResult(OPERATION_SAVE_QUESTIONS);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
SecurityQuestionAnswerType[] answerTypeList = new SecurityQuestionAnswerType[questionNumber];
try {
int listnum = 0;
for (Iterator iterator = pqPanels.iterator(); iterator.hasNext(); ) {
MyPasswordQuestionsPanel type = (MyPasswordQuestionsPanel) iterator.next();
SecurityQuestionAnswerType answerType = new SecurityQuestionAnswerType();
ProtectedStringType answer = new ProtectedStringType();
answer.setClearValue(((TextField<String>) type.get(MyPasswordQuestionsPanel.F_ANSWER)).getModelObject());
answerType.setQuestionAnswer(answer);
//used apache's unescapeHtml method for special chars like \'
String results = StringEscapeUtils.unescapeHtml((type.get(MyPasswordQuestionsPanel.F_QUESTION)).getDefaultModelObjectAsString());
answerType.setQuestionIdentifier(getQuestionIdentifierFromQuestion(results));
answerTypeList[listnum] = answerType;
listnum++;
}
//if(answerTypeList.length !=)
// fill in answerType data here
ItemPath path = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceContainer(UserType.class, useroid, path, getPrismContext(), answerTypeList);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
getModelService().executeChanges(deltas, null, task, result);
/*
System.out.println("getModel");
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
PasswordQuestionsDto dto = new PasswordQuestionsDto();
PrismObjectDefinition objDef =registry.findObjectDefinitionByCompileTimeClass(UserType.class);
Class<? extends ObjectType> type = UserType.class;
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
SecurityQuestionAnswerType secQuesAnsType= new SecurityQuestionAnswerType();
ProtectedStringType protStrType= new ProtectedStringType();
protStrType.setClearValue("deneme");
secQuesAnsType.setQuestionAnswer(protStrType);
dto.setSecurityAnswers(new ArrayList<SecurityQuestionAnswerType>());
dto.getSecurityAnswers().add(secQuesAnsType);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, dto.getSecurityAnswers().get(0).getQuestionAnswer());
// PropertyDelta delta= PropertyDelta.createModifica
System.out.println("Update Questions3");
deltas.add(ObjectDelta.createModifyDelta(useroid, delta, type, getPrismContext()));
System.out.println("Update Questions4");
getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_QUESTIONS), result);
System.out.println("Update Questions5");
*/
success(getString("message.success"));
target.add(getFeedbackPanel());
} catch (Exception ex) {
error(getString("message.error"));
target.add(getFeedbackPanel());
ex.printStackTrace();
}
}
Aggregations