Search in sources :

Example 11 with PrismObjectDefinition

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);
    }
}
Also used : F_WORKFLOW_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_WORKFLOW_CONTEXT) F_MODEL_OPERATION_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_MODEL_OPERATION_CONTEXT) QName(javax.xml.namespace.QName) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 12 with PrismObjectDefinition

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);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) MailServerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) List(java.util.List) ArrayList(java.util.ArrayList) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) MailConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailConfigurationType) PageLogin(com.evolveum.midpoint.web.page.login.PageLogin) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ModelService(com.evolveum.midpoint.model.api.ModelService) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 13 with PrismObjectDefinition

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with PrismObjectDefinition

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);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Example 15 with PrismObjectDefinition

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);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition)

Aggregations

PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 ArrayList (java.util.ArrayList)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)4 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)4 QName (javax.xml.namespace.QName)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 Task (com.evolveum.midpoint.task.api.Task)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 Collection (java.util.Collection)3 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)2 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismReference (com.evolveum.midpoint.prism.PrismReference)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2