use of com.evolveum.midpoint.prism.PrismObjectDefinition in project midpoint by Evolveum.
the class TaskQuartzImpl method recordObjectActionExecuted.
@Override
public <T extends ObjectType> void recordObjectActionExecuted(PrismObject<T> object, Class<T> objectTypeClass, String defaultOid, ChangeType changeType, String channel, Throwable exception) {
if (actionsExecutedInformation != null) {
String name, displayName, oid;
PrismObjectDefinition definition;
Class<T> clazz;
if (object != null) {
name = PolyString.getOrig(object.getName());
displayName = StatisticsUtil.getDisplayName(object);
definition = object.getDefinition();
clazz = object.getCompileTimeClass();
oid = object.getOid();
if (oid == null) {
// in case of ADD operation
oid = defaultOid;
}
} else {
name = null;
displayName = null;
definition = null;
clazz = objectTypeClass;
oid = defaultOid;
}
if (definition == null && clazz != null) {
definition = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(clazz);
}
QName typeQName;
if (definition != null) {
typeQName = definition.getTypeName();
} else {
typeQName = ObjectType.COMPLEX_TYPE;
}
actionsExecutedInformation.recordObjectActionExecuted(name, displayName, typeQName, oid, changeType, channel, exception);
}
}
use of com.evolveum.midpoint.prism.PrismObjectDefinition in project midpoint by Evolveum.
the class PageSecurityQuestions method resetPassword.
private void resetPassword(UserType user, AjaxRequestTarget target) {
Task task = createAnonymousTask(OPERATION_RESET_PASSWORD);
OperationResult result = task.getResult();
LOGGER.debug("Resetting password for {}", user);
ProtectedStringType password = new ProtectedStringType();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolve(), SystemConfigurationType.F_DEFAULT_USER_TEMPLATE, SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY);
PrismObject<SystemConfigurationType> systemConfig = null;
String newPassword = "";
PageBase page = (PageBase) getPage();
ModelService modelService = page.getModelService();
try {
systemConfig = modelService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), options, task, result);
LOGGER.trace("system config {}", systemConfig);
if (systemConfig.asObjectable().getNotificationConfiguration() != null) {
// Security policy with the minumum number of chars
if (systemConfig.asObjectable().getGlobalPasswordPolicyRef() != null) {
PrismObject<ValuePolicyType> valPolicy = modelService.getObject(ValuePolicyType.class, systemConfig.asObjectable().getGlobalPasswordPolicyRef().getOid(), options, task, result);
LOGGER.trace("password policy {}", valPolicy);
newPassword = getModelInteractionService().generateValue(valPolicy.asObjectable().getStringPolicy(), valPolicy.asObjectable().getStringPolicy().getLimitations().getMinLength(), false, user.asPrismObject(), "security questions password generation", task, result);
} else {
// TODO What if there is no policy? What should be done to
// provide a new automatic password
warn(getString("pageSecurityQuestions.message.noPolicySet"));
target.add(getFeedbackPanel());
return;
}
} else {
// TODO localization
getSession().error(getString("pageSecurityQuestions.message.notificationsNotSet"));
LOGGER.trace("Notificatons not set, returning to login page");
throw new RestartResponseException(PageLogin.class);
}
} catch (ObjectNotFoundException | ExpressionEvaluationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
} catch (SchemaException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
e1.printStackTrace();
} catch (SecurityViolationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
} catch (CommunicationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
} catch (ConfigurationException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
}
password.setClearValue(newPassword);
WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(UserType.class);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, password);
Class<? extends ObjectType> type = UserType.class;
deltas.add(ObjectDelta.createModifyDelta(user.getOid(), delta, type, getPrismContext()));
try {
modelService.executeChanges(deltas, null, task, result);
OperationResult parentResult = new OperationResult(OPERATION_LOAD_RESET_PASSWORD_POLICY);
try {
if (getModelInteractionService().getCredentialsPolicy(null, null, parentResult).getSecurityQuestions().getResetMethod().getResetType().equals(CredentialsResetTypeType.SECURITY_QUESTIONS)) {
getSession().setAttribute("pwdReset", newPassword);
setResponsePage(PageShowPassword.class);
} else if (getModelInteractionService().getCredentialsPolicy(null, null, parentResult).getSecurityQuestions().getResetMethod().getResetType().equals(CredentialsResetTypeType.SECURITY_QUESTIONS_EMAIL)) {
if (systemConfig.asObjectable().getNotificationConfiguration() != null && systemConfig.asObjectable().getNotificationConfiguration().getMail() != null) {
MailConfigurationType mailConfig = systemConfig.asObjectable().getNotificationConfiguration().getMail();
if (mailConfig.getServer() != null) {
List serverList = mailConfig.getServer();
if (serverList.size() > 0) {
MailServerConfigurationType mailServerType = mailConfig.getServer().get(0);
sendMailToUser(mailServerType.getUsername(), getMidpointApplication().getProtector().decryptString(mailServerType.getPassword()), newPassword, mailServerType.getHost(), mailServerType.getPort().toString(), mailConfig.getDefaultFrom(), user.getEmailAddress());
} else {
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
} else {
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
} else {
// System.out.println("ifff4");
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
}
} catch (ObjectNotFoundException | SchemaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO ASAP a message should be shown as the result of the process
// MailMessage mailMessage=new MailMessage(, port);
// mailTransport.send(mailMessage, transportName, task,
// parentResult);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException | EncryptionException e) {
LoggingUtils.logUnexpectedException(LOGGER, "reset password exception", e);
}
}
use of com.evolveum.midpoint.prism.PrismObjectDefinition in project midpoint by Evolveum.
the class PageAbstractSelfCredentials method onSavePerformed.
protected void onSavePerformed(AjaxRequestTarget target) {
List<PasswordAccountDto> selectedAccounts = getSelectedAccountsList();
if (isCheckOldPassword()) {
LOGGER.debug("Check old password");
if (model.getObject().getOldPassword() == null || model.getObject().getOldPassword().trim().equals("")) {
warn(getString("PageSelfCredentials.specifyOldPasswordMessage"));
target.add(getFeedbackPanel());
return;
} else {
OperationResult checkPasswordResult = new OperationResult(OPERATION_CHECK_PASSWORD);
Task checkPasswordTask = createSimpleTask(OPERATION_CHECK_PASSWORD);
try {
ProtectedStringType oldPassword = new ProtectedStringType();
oldPassword.setClearValue(model.getObject().getOldPassword());
boolean isCorrectPassword = getModelInteractionService().checkPassword(user.getOid(), oldPassword, checkPasswordTask, checkPasswordResult);
if (!isCorrectPassword) {
warn(getString("PageSelfCredentials.incorrectOldPassword"));
target.add(getFeedbackPanel());
return;
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't check password", ex);
checkPasswordResult.recordFatalError("Couldn't check password." + ex.getMessage(), ex);
target.add(getFeedbackPanel());
return;
} finally {
checkPasswordResult.computeStatus();
}
}
}
if (selectedAccounts.isEmpty()) {
warn(getString("PageSelfCredentials.noAccountSelected"));
target.add(getFeedbackPanel());
return;
}
if (getModelObject().getPassword() == null) {
warn(getString("PageSelfCredentials.emptyPasswordFiled"));
target.add(getFeedbackPanel());
return;
}
OperationResult result = new OperationResult(OPERATION_SAVE_PASSWORD);
try {
MyPasswordsDto dto = model.getObject();
ProtectedStringType password = dto.getPassword();
if (!password.isEncrypted()) {
WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
}
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
for (PasswordAccountDto accDto : selectedAccounts) {
PrismObjectDefinition objDef = accDto.isMidpoint() ? registry.findObjectDefinitionByCompileTimeClass(UserType.class) : registry.findObjectDefinitionByCompileTimeClass(ShadowType.class);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, password);
Class<? extends ObjectType> type = accDto.isMidpoint() ? UserType.class : ShadowType.class;
deltas.add(ObjectDelta.createModifyDelta(accDto.getOid(), delta, type, getPrismContext()));
}
getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_PASSWORD), result);
result.computeStatus();
} catch (Exception ex) {
setEncryptedPasswordData(null);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save password changes", ex);
result.recordFatalError(getString("PageAbstractSelfCredentials.save.password.failed", ex.getMessage()), ex);
} finally {
result.computeStatusIfUnknown();
;
}
finishChangePassword(result, target);
}
use of com.evolveum.midpoint.prism.PrismObjectDefinition in project midpoint by Evolveum.
the class AbstractRoleMemberPanel method initObjectForAdd.
// TODO: merge this with TreeTablePanel.initObjectForAdd, also see MID-3233
private void initObjectForAdd(ObjectReferenceType parentOrgRef, QName type, QName relation, AjaxRequestTarget target) throws SchemaException {
getPageBase().hideMainPopup(target);
PrismContext prismContext = getPageBase().getPrismContext();
PrismObjectDefinition def = prismContext.getSchemaRegistry().findObjectDefinitionByType(type);
PrismObject obj = def.instantiate();
if (parentOrgRef == null) {
parentOrgRef = createReference(relation);
}
ObjectType objType = (ObjectType) obj.asObjectable();
if (FocusType.class.isAssignableFrom(obj.getCompileTimeClass())) {
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(parentOrgRef);
((FocusType) objType).getAssignment().add(assignment);
}
// TODO: fix MID-3234
if (parentOrgRef.getType() != null && OrgType.COMPLEX_TYPE.equals(parentOrgRef.getType())) {
objType.getParentOrgRef().add(parentOrgRef.clone());
}
WebComponentUtil.dispatchToObjectDetailsPage(obj, this);
}
use of com.evolveum.midpoint.prism.PrismObjectDefinition in project midpoint by Evolveum.
the class TreeTablePanel method initObjectForAdd.
// TODO: merge this with AbstractRoleMemeberPanel.initObjectForAdd, also see MID-3233
private void initObjectForAdd(ObjectReferenceType parentOrgRef, QName type, QName relation, AjaxRequestTarget target) throws SchemaException {
TreeTablePanel.this.getPageBase().hideMainPopup(target);
PrismContext prismContext = TreeTablePanel.this.getPageBase().getPrismContext();
PrismObjectDefinition def = prismContext.getSchemaRegistry().findObjectDefinitionByType(type);
PrismObject obj = def.instantiate();
ObjectType objType = (ObjectType) obj.asObjectable();
if (FocusType.class.isAssignableFrom(obj.getCompileTimeClass())) {
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(parentOrgRef);
((FocusType) objType).getAssignment().add(assignment);
}
// TODO: fix MID-3234
if (parentOrgRef == null) {
ObjectType org = getTreePanel().getSelected().getValue();
parentOrgRef = ObjectTypeUtil.createObjectRef(org);
parentOrgRef.setRelation(relation);
objType.getParentOrgRef().add(parentOrgRef);
} else {
objType.getParentOrgRef().add(parentOrgRef.clone());
}
WebComponentUtil.dispatchToObjectDetailsPage(obj, this);
}
Aggregations