Search in sources :

Example 11 with PasswordType

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

the class ConnectorInstanceConnIdImpl method addObject.

@Override
public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObject(PrismObject<? extends ShadowType> shadow, Collection<Operation> additionalOperations, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException {
    validateShadow(shadow, "add", false);
    ShadowType shadowType = shadow.asObjectable();
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".addObject");
    result.addParam("resourceObject", shadow);
    // because of serialization issues
    result.addParam("additionalOperations", DebugUtil.debugDump(additionalOperations));
    ObjectClassComplexTypeDefinition ocDef;
    ResourceAttributeContainerDefinition attrContDef = attributesContainer.getDefinition();
    if (attrContDef != null) {
        ocDef = attrContDef.getComplexTypeDefinition();
    } else {
        ocDef = resourceSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass());
        if (ocDef == null) {
            throw new SchemaException("Unknown object class " + shadow.asObjectable().getObjectClass());
        }
    }
    // getting icf object class from resource object class
    ObjectClass icfObjectClass = connIdNameMapper.objectClassToIcf(shadow, getSchemaNamespace(), connectorType, legacySchema);
    if (icfObjectClass == null) {
        result.recordFatalError("Couldn't get icf object class from " + shadow);
        throw new IllegalArgumentException("Couldn't get icf object class from " + shadow);
    }
    // setting ifc attributes from resource object attributes
    Set<Attribute> attributes = null;
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("midPoint object before conversion:\n{}", attributesContainer.debugDump());
        }
        attributes = connIdConvertor.convertFromResourceObject(attributesContainer, ocDef);
        if (shadowType.getCredentials() != null && shadowType.getCredentials().getPassword() != null) {
            PasswordType password = shadowType.getCredentials().getPassword();
            ProtectedStringType protectedString = password.getValue();
            GuardedString guardedPassword = ConnIdUtil.toGuardedString(protectedString, "new password", protector);
            if (guardedPassword != null) {
                attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_NAME, guardedPassword));
            }
        }
        if (ActivationUtil.hasAdministrativeActivation(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, ActivationUtil.isAdministrativeEnabled(shadowType)));
        }
        if (ActivationUtil.hasValidFrom(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_DATE_NAME, XmlTypeConverter.toMillis(shadowType.getActivation().getValidFrom())));
        }
        if (ActivationUtil.hasValidTo(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.DISABLE_DATE_NAME, XmlTypeConverter.toMillis(shadowType.getActivation().getValidTo())));
        }
        if (ActivationUtil.hasLockoutStatus(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.LOCK_OUT_NAME, ActivationUtil.isLockedOut(shadowType)));
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("ICF attributes after conversion:\n{}", ConnIdUtil.dump(attributes));
        }
    } catch (SchemaException | RuntimeException ex) {
        result.recordFatalError("Error while converting resource object attributes. Reason: " + ex.getMessage(), ex);
        throw new SchemaException("Error while converting resource object attributes. Reason: " + ex.getMessage(), ex);
    }
    if (attributes == null) {
        result.recordFatalError("Couldn't set attributes for icf.");
        throw new IllegalStateException("Couldn't set attributes for icf.");
    }
    List<String> icfAuxiliaryObjectClasses = new ArrayList<>();
    for (QName auxiliaryObjectClass : shadowType.getAuxiliaryObjectClass()) {
        icfAuxiliaryObjectClasses.add(connIdNameMapper.objectClassToIcf(auxiliaryObjectClass, resourceSchemaNamespace, connectorType, false).getObjectClassValue());
    }
    if (!icfAuxiliaryObjectClasses.isEmpty()) {
        AttributeBuilder ab = new AttributeBuilder();
        ab.setName(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME);
        ab.addValue(icfAuxiliaryObjectClasses);
        attributes.add(ab.build());
    }
    OperationOptionsBuilder operationOptionsBuilder = new OperationOptionsBuilder();
    OperationOptions options = operationOptionsBuilder.build();
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.BEFORE, result);
    OperationResult connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".create");
    connIdResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
    connIdResult.addArbitraryCollectionAsParam("auxiliaryObjectClasses", icfAuxiliaryObjectClasses);
    connIdResult.addArbitraryCollectionAsParam("attributes", attributes);
    connIdResult.addArbitraryObjectAsParam("options", options);
    connIdResult.addContext("connector", connIdConnectorFacade.getClass());
    Uid uid = null;
    try {
        // CALL THE ICF FRAMEWORK
        InternalMonitor.recordConnectorOperation("create");
        // TODO provide object name
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_CREATE, ocDef, null);
        uid = connIdConnectorFacade.create(icfObjectClass, attributes, options);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_CREATE, ocDef, uid);
    } catch (Throwable ex) {
        // TODO name
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_CREATE, ocDef, ex, null);
        Throwable midpointEx = processIcfException(ex, this, connIdResult);
        result.computeStatus("Add object failed");
        // exception
        if (midpointEx instanceof ObjectAlreadyExistsException) {
            throw (ObjectAlreadyExistsException) midpointEx;
        } else if (midpointEx instanceof CommunicationException) {
            //				result.muteError();
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            throw (SchemaException) midpointEx;
        } else if (midpointEx instanceof ConfigurationException) {
            throw (ConfigurationException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.AFTER, result);
    if (uid == null || uid.getUidValue() == null || uid.getUidValue().isEmpty()) {
        connIdResult.recordFatalError("ICF did not returned UID after create");
        result.computeStatus("Add object failed");
        throw new GenericFrameworkException("ICF did not returned UID after create");
    }
    Collection<ResourceAttribute<?>> identifiers = ConnIdUtil.convertToIdentifiers(uid, attributesContainer.getDefinition().getComplexTypeDefinition(), resourceSchema);
    for (ResourceAttribute<?> identifier : identifiers) {
        attributesContainer.getValue().addReplaceExisting(identifier);
    }
    connIdResult.recordSuccess();
    result.recordSuccess();
    return AsynchronousOperationReturnValue.wrap(attributesContainer.getAttributes(), result);
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) Attribute(org.identityconnectors.framework.common.objects.Attribute) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString) GuardedString(org.identityconnectors.common.security.GuardedString) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Uid(org.identityconnectors.framework.common.objects.Uid) QualifiedUid(org.identityconnectors.framework.common.objects.QualifiedUid) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 12 with PasswordType

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

the class TestPasswordPolicyProcessor method test203modifyUserJackPasswordNoPasswordHistory.

@Test
public void test203modifyUserJackPasswordNoPasswordHistory() throws Exception {
    final String TEST_NAME = "test203modifyUserJackPasswordNoPasswordHistory";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    ProtectedStringType newValue = new ProtectedStringType();
    newValue.setClearValue("n0Hist0ryEntr7");
    modifyObjectReplaceProperty(UserType.class, USER_JACK_OID, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE), task, result, newValue);
    // THEN
    PrismObject<UserType> userJack = getObject(UserType.class, USER_JACK_OID);
    assertNotNull("Expected to find user Jack, but no one exists here", userJack);
    UserType userJackType = userJack.asObjectable();
    CredentialsType credentials = userJackType.getCredentials();
    assertNotNull("User Jack has no credentials", credentials);
    PasswordType password = credentials.getPassword();
    assertNotNull("User Jack has no password", password);
    List<PasswordHistoryEntryType> historyEntries = password.getHistoryEntry();
    assertEquals("Expected no history entries, but found: " + historyEntries.size(), 0, historyEntries.size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) PasswordHistoryEntryType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 13 with PasswordType

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

the class TestPasswordPolicyProcessor method test101ModifyUserPassword.

@Test
public void test101ModifyUserPassword() throws Exception {
    final String TEST_NAME = "test101ModifyUserPassword";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    modifyUserChangePassword(USER_JACK_OID, PASSWORD1, task, result);
    // THEN
    PrismObject<UserType> jack = getObject(UserType.class, USER_JACK_OID);
    assertNotNull("User Jack was not found.", jack);
    UserType jackType = jack.asObjectable();
    CredentialsType credentialsType = jackType.getCredentials();
    assertNotNull("No credentials set for user Jack", credentialsType);
    PasswordType passwordType = credentialsType.getPassword();
    assertNotNull("No password set for user Jack", passwordType);
    ProtectedStringType passwordAfterChange = passwordType.getValue();
    assertNotNull("Password musn't be null", passwordAfterChange);
    assertEquals("Password doesn't match", PASSWORD1, protector.decryptString(passwordAfterChange));
    assertPasswordHistoryEntries(passwordType, USER_JACK_PASSWORD);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test)

Example 14 with PasswordType

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

the class AbstractModelIntegrationTest method assertShadowLdapPassword.

protected void assertShadowLdapPassword(PrismObject<ShadowType> shadow, String expectedPassword) throws EncryptionException {
    CredentialsType credentialsType = shadow.asObjectable().getCredentials();
    assertNotNull("No credentials in " + shadow, credentialsType);
    PasswordType passwordType = credentialsType.getPassword();
    assertNotNull("No password in " + shadow, passwordType);
    ProtectedStringType protectedStringType = passwordType.getValue();
    assertLdapPassword(protectedStringType, expectedPassword, shadow);
}
Also used : CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 15 with PasswordType

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

the class TestOpenDj method assertShadowPassword.

protected void assertShadowPassword(ShadowType provisioningShadow) throws Exception {
    CredentialsType credentials = provisioningShadow.getCredentials();
    if (credentials == null) {
        return;
    }
    PasswordType passwordType = credentials.getPassword();
    if (passwordType == null) {
        return;
    }
    ProtectedStringType passwordValue = passwordType.getValue();
    assertNull("Unexpected password value in " + provisioningShadow + ": " + passwordValue, passwordValue);
}
Also used : CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Aggregations

PasswordType (com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType)23 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)18 CredentialsType (com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType)16 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 Test (org.testng.annotations.Test)8 Task (com.evolveum.midpoint.task.api.Task)7 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 MetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 PasswordHistoryEntryType (com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)1