Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Suta committed Jul 22, 2014
2 parents 5d4a2c2 + 5de985c commit b2764c3
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 15 deletions.
Expand Up @@ -806,6 +806,7 @@ private Collection<Operation> determineActivationChange(ShadowType shadow, Colle
}
XMLGregorianCalendar xmlCal = validFromPropertyDelta.getPropertyNew().getRealValue();
LOGGER.trace("Found activation validFrom change to: {}", xmlCal);
//TODO: why this if?? do we really want to not allow to set validFrom/validTo to null value?? the same for validTo
if (xmlCal != null) {
operations.add(new PropertyModificationOperation(validFromPropertyDelta));
}
Expand Down
Expand Up @@ -1419,22 +1419,28 @@ public Set<PropertyModificationOperation> modifyObject(ObjectClassComplexTypeDef

try {
updateAttributes = convertFromResourceObject(updateValues, result);

if (activationDeltas != null) {
// Activation change means modification of attributes
convertFromActivation(updateAttributes, activationDeltas);
}

if (passwordDelta != null) {
// Activation change means modification of attributes
convertFromPassword(updateAttributes, passwordDelta);
}

} catch (SchemaException 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);
} catch (RuntimeException ex) {
result.recordFatalError("Error while converting resource object attributes. Reason: " + ex.getMessage(), ex);
throw ex;
}

if (activationDeltas != null) {
// Activation change means modification of attributes
convertFromActivation(updateAttributes, activationDeltas);
}

if (passwordDelta != null) {
// Activation change means modification of attributes
convertFromPassword(updateAttributes, passwordDelta);
}


OperationOptions options = new OperationOptionsBuilder().build();
icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".update");
Expand Down Expand Up @@ -2190,17 +2196,18 @@ private void convertFromActivation(Set<Attribute> updateAttributes,

for (PropertyDelta<?> propDelta : activationDeltas) {
if (propDelta.getElementName().equals(ActivationType.F_ADMINISTRATIVE_STATUS)) {
ActivationStatusType status = propDelta.getPropertyNew().getValue(ActivationStatusType.class).getValue();
ActivationStatusType status = getPropertyNewValue(propDelta, ActivationStatusType.class);

// Not entirely correct, TODO: refactor later
updateAttributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, status == ActivationStatusType.ENABLED));
} else if (propDelta.getElementName().equals(ActivationType.F_VALID_FROM)) {
XMLGregorianCalendar xmlCal = propDelta.getPropertyNew().getValue(XMLGregorianCalendar.class).getValue();
XMLGregorianCalendar xmlCal = getPropertyNewValue(propDelta, XMLGregorianCalendar.class);//propDelta.getPropertyNew().getValue(XMLGregorianCalendar.class).getValue();
updateAttributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_DATE_NAME, XmlTypeConverter.toMillis(xmlCal)));
} else if (propDelta.getElementName().equals(ActivationType.F_VALID_TO)) {
XMLGregorianCalendar xmlCal = propDelta.getPropertyNew().getValue(XMLGregorianCalendar.class).getValue();
XMLGregorianCalendar xmlCal = getPropertyNewValue(propDelta, XMLGregorianCalendar.class);//propDelta.getPropertyNew().getValue(XMLGregorianCalendar.class).getValue();
updateAttributes.add(AttributeBuilder.build(OperationalAttributes.DISABLE_DATE_NAME, XmlTypeConverter.toMillis(xmlCal)));
} else if (propDelta.getElementName().equals(ActivationType.F_LOCKOUT_STATUS)) {
LockoutStatusType status = propDelta.getPropertyNew().getValue(LockoutStatusType.class).getValue();
LockoutStatusType status = getPropertyNewValue(propDelta, LockoutStatusType.class);//propDelta.getPropertyNew().getValue(LockoutStatusType.class).getValue();
updateAttributes.add(AttributeBuilder.build(OperationalAttributes.LOCK_OUT_NAME, status != LockoutStatusType.NORMAL));
} else {
throw new SchemaException("Got unknown activation attribute delta " + propDelta.getElementName());
Expand All @@ -2209,6 +2216,20 @@ private void convertFromActivation(Set<Attribute> updateAttributes,

}

private <T> T getPropertyNewValue(PropertyDelta propertyDelta, Class<T> clazz) throws SchemaException {
PrismProperty<PrismPropertyValue<T>> prop = propertyDelta.getPropertyNew();
if (prop == null){
return null;
}
PrismPropertyValue<T> propValue = prop.getValue(clazz);

if (propValue == null){
return null;
}

return propValue.getValue();
}

private void convertFromPassword(Set<Attribute> attributes, PropertyDelta<ProtectedStringType> passwordDelta) throws SchemaException {
if (passwordDelta == null) {
throw new IllegalArgumentException("No password was provided");
Expand Down
Expand Up @@ -62,6 +62,7 @@
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
Expand Down Expand Up @@ -1888,8 +1889,8 @@ public void test135ExecuteScript() throws Exception {

assertSteadyResource();
}

@Test
@Test
public void test150DisableAccount() throws Exception {
final String TEST_NAME = "test150DisableAccount";
TestUtil.displayTestTile(TEST_NAME);
Expand Down Expand Up @@ -1933,6 +1934,50 @@ public void test150DisableAccount() throws Exception {

assertSteadyResource();
}

@Test
public void test151ActivationStatusUndefinedAccount() throws Exception {
final String TEST_NAME = "test151ActivationStatusUndefinedAccount";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN

Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task,
result).asObjectable();
assertNotNull(accountType);
display("Retrieved account shadow", accountType);

DummyAccount dummyAccount = getDummyAccountAssert(ACCOUNT_WILL_USERNAME, willIcfUid);
assertFalse("Account is not disabled", dummyAccount.isEnabled());

syncServiceMock.reset();

ObjectDelta<ShadowType> delta = ObjectDelta.createModificationDeleteProperty(ShadowType.class,
ACCOUNT_WILL_OID, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, prismContext,
ActivationStatusType.DISABLED);
display("ObjectDelta", delta);
delta.checkConsistence();

// WHEN
provisioningService.modifyObject(ShadowType.class, delta.getOid(), delta.getModifications(),
new OperationProvisioningScriptsType(), null, task, result);

// THEN
result.computeStatus();
display("modifyObject result", result);
TestUtil.assertSuccess(result);

delta.checkConsistence();
// check if activation was changed
dummyAccount = getDummyAccountAssert(ACCOUNT_WILL_USERNAME, willIcfUid);
assertFalse("Dummy account "+ACCOUNT_WILL_USERNAME+" is enabled, expected disabled", dummyAccount.isEnabled());

syncServiceMock.assertNotifySuccessOnly();

assertSteadyResource();
}

@Test
public void test151EnableAccount() throws Exception {
Expand Down Expand Up @@ -1978,6 +2023,8 @@ public void test151EnableAccount() throws Exception {
assertSteadyResource();
}



@Test
public void test152SetValidFrom() throws Exception {
final String TEST_NAME = "test152SetValidFrom";
Expand Down Expand Up @@ -2073,6 +2120,58 @@ public void test153SetValidTo() throws Exception {
assertSteadyResource();
}

//TODO: if this needed?? for now, we don't allow to set activation valid from and valid to to null value...
@Test(enabled = false)
public void test154DeleteValidToValidFrom() throws Exception {
final String TEST_NAME = "test154DeleteValidToValidFrom";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN

Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task,
result).asObjectable();
assertNotNull(accountType);

display("Retrieved account shadow", accountType);

DummyAccount dummyAccount = getDummyAccountAssert(ACCOUNT_WILL_USERNAME, willIcfUid);
assertTrue(dummyAccount.isEnabled());

syncServiceMock.reset();

// long millis = VALID_TO_MILLIS;

ObjectDelta<ShadowType> delta = ObjectDelta.createModificationDeleteProperty(ShadowType.class,
ACCOUNT_WILL_OID, SchemaConstants.PATH_ACTIVATION_VALID_TO, prismContext,
XmlTypeConverter.createXMLGregorianCalendar(VALID_TO_MILLIS));
PrismObjectDefinition def = accountType.asPrismObject().getDefinition();
PropertyDelta validFromDelta = PropertyDelta.createModificationDeleteProperty(SchemaConstants.PATH_ACTIVATION_VALID_FROM, def.findPropertyDefinition(SchemaConstants.PATH_ACTIVATION_VALID_FROM), VALID_FROM_MILLIS);
delta.addModification(validFromDelta);
delta.checkConsistence();

// WHEN
provisioningService.modifyObject(ShadowType.class, delta.getOid(),
delta.getModifications(), new OperationProvisioningScriptsType(), null, task, result);

// THEN
result.computeStatus();
display("modifyObject result", result);
TestUtil.assertSuccess(result);

delta.checkConsistence();
// check if activation was changed
dummyAccount = getDummyAccountAssert(ACCOUNT_WILL_USERNAME, willIcfUid);
assertNull("Wrong account validTo in account "+ACCOUNT_WILL_USERNAME + ": " + dummyAccount.getValidTo(), dummyAccount.getValidTo());
assertNull("Wrong account validFrom in account "+ACCOUNT_WILL_USERNAME + ": " + dummyAccount.getValidFrom(), dummyAccount.getValidFrom());
assertTrue("Dummy account "+ACCOUNT_WILL_USERNAME+" is disabled, expected enabled", dummyAccount.isEnabled());

syncServiceMock.assertNotifySuccessOnly();

assertSteadyResource();
}

@Test
public void test155GetLockedoutAccount() throws Exception {
final String TEST_NAME = "test155GetLockedoutAccount";
Expand Down

0 comments on commit b2764c3

Please sign in to comment.