Search in sources :

Example 31 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class ObjectLinkColumn method populateItem.

@Override
public void populateItem(Item<ICellPopulator<T>> cellItem, String componentId, final IModel<T> rowModel) {
    IModel<ObjectType> superModel = createLinkModel(rowModel);
    final ObjectType targetObjectType = superModel.getObject();
    IModel<String> nameModel = new PropertyModel<String>(superModel, FocusType.F_NAME.getLocalPart() + ".orig");
    cellItem.add(new LinkPanel(componentId, nameModel) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ObjectLinkColumn.this.onClick(target, rowModel, targetObjectType);
        }

        @Override
        public boolean isEnabled() {
            return ObjectLinkColumn.this.isEnabled(rowModel);
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PropertyModel(org.apache.wicket.model.PropertyModel)

Example 32 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.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();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Iterator(java.util.Iterator) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 33 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class CryptoUtil method checkEncrypted.

private static <T extends ObjectType> void checkEncrypted(PrismPropertyValue<?> pval) {
    Itemable item = pval.getParent();
    if (item == null) {
        return;
    }
    ItemDefinition itemDef = item.getDefinition();
    if (itemDef == null || itemDef.getTypeName() == null) {
        return;
    }
    if (itemDef.getTypeName().equals(ProtectedStringType.COMPLEX_TYPE)) {
        QName propName = item.getElementName();
        PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>) pval;
        ProtectedStringType ps = psPval.getValue();
        if (ps.getClearValue() != null) {
            throw new IllegalStateException("Unencrypted value in field " + propName);
        }
    } else if (itemDef.getTypeName().equals(NotificationConfigurationType.COMPLEX_TYPE)) {
        // this is really ugly hack needed because currently it is not possible to break NotificationConfigurationType into prism item [pm]
        NotificationConfigurationType ncfg = ((PrismPropertyValue<NotificationConfigurationType>) pval).getValue();
        if (ncfg.getMail() != null) {
            for (MailServerConfigurationType mscfg : ncfg.getMail().getServer()) {
                if (mscfg.getPassword() != null && mscfg.getPassword().getClearValue() != null) {
                    throw new IllegalStateException("Unencrypted value in mail server config password entry");
                }
            }
        }
        if (ncfg.getSms() != null) {
            for (SmsConfigurationType smscfg : ncfg.getSms()) {
                for (SmsGatewayConfigurationType gwcfg : smscfg.getGateway()) {
                    if (gwcfg.getPassword() != null && gwcfg.getPassword().getClearValue() != null) {
                        throw new IllegalStateException("Unencrypted value in SMS gateway config password entry");
                    }
                }
            }
        }
    }
}
Also used : NotificationConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationConfigurationType) Itemable(com.evolveum.midpoint.prism.Itemable) QName(javax.xml.namespace.QName) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) MailServerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType) SmsGatewayConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsGatewayConfigurationType) SmsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsConfigurationType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 34 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class CryptoUtil method encryptValue.

private static <T extends ObjectType> void encryptValue(Protector protector, PrismPropertyValue<?> pval) throws EncryptionException {
    Itemable item = pval.getParent();
    if (item == null) {
        return;
    }
    ItemDefinition itemDef = item.getDefinition();
    if (itemDef == null || itemDef.getTypeName() == null) {
        return;
    }
    if (itemDef.getTypeName().equals(ProtectedStringType.COMPLEX_TYPE)) {
        QName propName = item.getElementName();
        PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>) pval;
        ProtectedStringType ps = psPval.getValue();
        encryptProtectedStringType(protector, ps, propName.getLocalPart());
        if (pval.getParent() == null) {
            pval.setParent(item);
        }
    } else if (itemDef.getTypeName().equals(NotificationConfigurationType.COMPLEX_TYPE)) {
        // this is really ugly hack needed because currently it is not possible to break NotificationConfigurationType into prism item [pm]
        NotificationConfigurationType ncfg = ((PrismPropertyValue<NotificationConfigurationType>) pval).getValue();
        if (ncfg.getMail() != null) {
            for (MailServerConfigurationType mscfg : ncfg.getMail().getServer()) {
                encryptProtectedStringType(protector, mscfg.getPassword(), "mail server password");
            }
        }
        if (ncfg.getSms() != null) {
            for (SmsConfigurationType smscfg : ncfg.getSms()) {
                for (SmsGatewayConfigurationType gwcfg : smscfg.getGateway()) {
                    encryptProtectedStringType(protector, gwcfg.getPassword(), "sms gateway password");
                }
            }
        }
    }
}
Also used : NotificationConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationConfigurationType) Itemable(com.evolveum.midpoint.prism.Itemable) QName(javax.xml.namespace.QName) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) MailServerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType) SmsGatewayConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsGatewayConfigurationType) SmsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsConfigurationType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 35 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class ModelCrudService method modifyObject.

/**
	 * <p>
	 * Modifies object using relative change description.
	 * </p>
	 * <p>
	 * Must fail if user with provided OID does not exists. Must fail if any of
	 * the described changes cannot be applied. Should be atomic.
	 * </p>
	 * <p>
	 * If two or more modify operations are executed in parallel, the operations
	 * should be merged. In case that the operations are in conflict (e.g. one
	 * operation adding a value and the other removing the same value), the
	 * result is not deterministic.
	 * </p>
	 * <p>
	 * The operation may fail if the modified object does not conform to the
	 * underlying schema of the storage system or the schema enforced by the
	 * implementation.
	 * </p>
	 * 
	 * @param parentResult
	 *            parent OperationResult (in/out)
	 * @throws ObjectNotFoundException
	 *             specified object does not exist
	 * @throws SchemaException
	 *             resulting object would violate the schema
	 * @throws ExpressionEvaluationException
	 * 				evaluation of expression associated with the object has failed
	 * @throws CommunicationException 
	 * @throws ObjectAlreadyExistsException
	 * 				If the account or another "secondary" object already exists and cannot be created
	 * @throws PolicyViolationException 
	 * 				Policy violation was detected during processing of the object
	 * @throws IllegalArgumentException
	 *             wrong OID format, described change is not applicable
	 * @throws SystemException
	 *             unknown error from underlying layers or other unexpected
	 *             state
	 */
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
    Validate.notNull(modifications, "Object modification must not be null.");
    Validate.notEmpty(oid, "Change oid must not be null or empty.");
    Validate.notNull(parentResult, "Result type must not be null.");
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Modifying object with oid {}", oid);
        LOGGER.trace(DebugUtil.debugDump(modifications));
    }
    if (modifications.isEmpty()) {
        LOGGER.warn("Calling modifyObject with empty modificaiton set");
        return;
    }
    ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
    // TODO: check definitions, but tolerate missing definitions in <attributes>
    OperationResult result = parentResult.createSubresult(MODIFY_OBJECT);
    result.addCollectionOfSerializablesAsParam("modifications", modifications);
    RepositoryCache.enter();
    try {
        ObjectDelta<T> objectDelta = (ObjectDelta<T>) ObjectDelta.createModifyDelta(oid, modifications, type, prismContext);
        Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
        modelService.executeChanges(deltas, options, task, result);
        result.computeStatus();
    } catch (ExpressionEvaluationException ex) {
        LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
        result.recordFatalError(ex);
        throw ex;
    } catch (ObjectNotFoundException ex) {
        LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
        result.recordFatalError(ex);
        throw ex;
    } catch (SchemaException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (ConfigurationException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (SecurityViolationException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (RuntimeException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } finally {
        RepositoryCache.exit();
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)371 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)321 Test (org.testng.annotations.Test)267 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)252 Task (com.evolveum.midpoint.task.api.Task)251 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)230 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)170 ArrayList (java.util.ArrayList)136 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)65 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)61 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)56 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)53 Holder (javax.xml.ws.Holder)51 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)50 QName (javax.xml.namespace.QName)46 PrismObject (com.evolveum.midpoint.prism.PrismObject)42 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)36 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)36 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)34