Skip to content

Commit

Permalink
Fixed support for searching for disabled and locked-out objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Aug 12, 2015
1 parent f1c8b01 commit 4c81ec3
Show file tree
Hide file tree
Showing 20 changed files with 1,553 additions and 493 deletions.
1 change: 1 addition & 0 deletions build-system/pom.xml
Expand Up @@ -828,6 +828,7 @@
</property>
</properties>
<systemPropertyVariables>
<javax.net.ssl.trustStore>src/test/resources/truststore.jks</javax.net.ssl.trustStore>
<midpoint.home>target/midpoint-home</midpoint.home>
<java.util.logging.config.file>${project.build.directory}/test-classes/logging.properties</java.util.logging.config.file>
</systemPropertyVariables>
Expand Down
Expand Up @@ -270,6 +270,9 @@ ActivationType.effectiveStatus=Effective status
ActivationType.validFrom=Valid from
ActivationType.validTo=Valid to

LockoutStatusType.NORMAL=Normal
LockoutStatusType.LOCKED=Locked

operation.com.evolveum.midpoint.common.operation.import.object=Import object
operation.com.evolveum.midpoint.common.validator.Validator.objectBasicsCheck=Basic checks
operation.com.evolveum.midpoint.common.validator.Validator.resourceNamespaceCheck=Resource namespace check
Expand Down
Expand Up @@ -124,10 +124,10 @@ public static <C extends Containerable, T> EqualFilter<T> createEqual(ItemPath p
return createEqual(parentPath, propertyDef, values);
}

public static <C extends Containerable, T> EqualFilter<T> createEqual(ItemPath parentPath, PrismContainerDefinition<C> containerDef,
public static <C extends Containerable, T> EqualFilter<T> createEqual(ItemPath itemPath, PrismContainerDefinition<C> containerDef,
T realValues) throws SchemaException {
PrismPropertyDefinition<T> propertyDef = (PrismPropertyDefinition) findItemDefinition(parentPath, containerDef);
return createEqual(parentPath, propertyDef, realValues);
PrismPropertyDefinition<T> propertyDef = (PrismPropertyDefinition) findItemDefinition(itemPath, containerDef);
return createEqual(itemPath, propertyDef, realValues);
}

public static <C extends Containerable, T> EqualFilter<T> createEqual(QName propertyName, Class<C> type, PrismContext prismContext, T realValues)
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -119,10 +119,10 @@ public MatchingRule getMatchingRuleFromRegistry(MatchingRuleRegistry matchingRul

}

static ItemDefinition findItemDefinition(ItemPath parentPath, PrismContainerDefinition<? extends Containerable> containerDef) {
ItemDefinition itemDef = containerDef.findItemDefinition(parentPath);
static ItemDefinition findItemDefinition(ItemPath itemPath, PrismContainerDefinition<? extends Containerable> containerDef) {
ItemDefinition itemDef = containerDef.findItemDefinition(itemPath);
if (itemDef == null) {
throw new IllegalStateException("No definition for item " + parentPath + " in container definition "
throw new IllegalStateException("No definition for item " + itemPath + " in container definition "
+ containerDef);
}

Expand Down
Expand Up @@ -17,6 +17,7 @@

import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

/**
Expand Down Expand Up @@ -57,5 +58,21 @@ public static boolean hasValidTo(ShadowType objectType) {
ActivationType activation = objectType.getActivation();
return activation != null && activation.getValidTo() != null;
}

public static boolean hasLockoutStatus(ShadowType objectType) {
ActivationType activation = objectType.getActivation();
return activation != null && activation.getLockoutStatus() != null;
}

public static boolean isLockedOut(ShadowType objectType) {
return isLockedOut(objectType.getActivation());
}

public static boolean isLockedOut(ActivationType activation) {
if (activation == null) {
return false;
}
return activation.getLockoutStatus() == LockoutStatusType.LOCKED;
}

}
3 changes: 3 additions & 0 deletions model/model-intest/testng.xml
Expand Up @@ -16,6 +16,9 @@
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="unit" parallel="false">
<listeners>
<listener class-name="com.evolveum.midpoint.tools.testng.AlphabeticalMethodInterceptor"/>
</listeners>
<test name="Model Integration" preserve-order="true" parallel="false" verbose="10">
<classes>
<class name="com.evolveum.midpoint.model.intest.TestModelServiceContract"/>
Expand Down
Expand Up @@ -1308,6 +1308,10 @@ public Collection<ResourceAttribute<?>> addObject(PrismObject<? extends ShadowTy
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{}", IcfUtil.dump(attributes));
}
Expand Down
Expand Up @@ -23,8 +23,10 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.PrismPropertyValue;

import org.identityconnectors.framework.common.objects.Attribute;
import org.identityconnectors.framework.common.objects.AttributeBuilder;
import org.identityconnectors.framework.common.objects.OperationalAttributes;
import org.identityconnectors.framework.common.objects.filter.Filter;
import org.identityconnectors.framework.common.objects.filter.FilterBuilder;

Expand All @@ -39,6 +41,9 @@
import com.evolveum.midpoint.provisioning.ucf.util.UcfUtil;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

public class ValueOperation extends Operation {
Expand All @@ -53,8 +58,10 @@ public <T> Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp
OperationResult parentResult = new OperationResult("interpret");

ValueFilter valueFilter= (ValueFilter) objectFilter;
if (valueFilter.getParentPath() != null && !valueFilter.getParentPath().isEmpty()
&& valueFilter.getParentPath().equivalent(new ItemPath(ShadowType.F_ATTRIBUTES))) {
if (valueFilter.getParentPath() == null || valueFilter.getParentPath().isEmpty()) {
throw new UnsupportedOperationException("Empty path is not supported (filter: " + objectFilter+")");
}
if (valueFilter.getParentPath().equivalent(new ItemPath(ShadowType.F_ATTRIBUTES))) {
try {
QName propName = valueFilter.getDefinition().getName();
String icfName = icfNameMapper.convertAttributeNameToIcf(propName, getInterpreter()
Expand Down Expand Up @@ -100,14 +107,45 @@ public <T> Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp
return FilterBuilder.contains(AttributeBuilder.build(icfName, convertedValues.iterator().next()));
}
} else {
throw new UnsupportedOperationException("Unsupported filter type: " + objectFilter.debugDump());
throw new UnsupportedOperationException("Unsupported filter type: " + objectFilter);
}
} catch (SchemaException ex) {
throw ex;

}
} else if (valueFilter.getParentPath().equivalent(new ItemPath(ShadowType.F_ACTIVATION))) {

if (objectFilter instanceof EqualFilter) {
QName propName = valueFilter.getDefinition().getName();
EqualFilter<T> eq = (EqualFilter<T>) objectFilter;
List<PrismPropertyValue<T>> values = eq.getValues();
if (values.size() != 1) {
throw new SchemaException("Unexpected number of values in filter "+objectFilter);
}
PrismPropertyValue<T> pval = values.get(0);
String icfName;
Object convertedValue;
if (propName.equals(ActivationType.F_ADMINISTRATIVE_STATUS)) {
icfName = OperationalAttributes.ENABLE_NAME;
convertedValue = pval.getValue() == ActivationStatusType.ENABLED;
} else if (propName.equals(ActivationType.F_LOCKOUT_STATUS)) {
icfName = OperationalAttributes.LOCK_OUT_NAME;
convertedValue = pval.getValue() == LockoutStatusType.LOCKED;
} else {
throw new UnsupportedOperationException("Unsupported activation property "+propName+" in filter: " + objectFilter);
}
Attribute attr = AttributeBuilder.build(icfName, convertedValue);
if (valueFilter.getDefinition().isSingleValue()) {
return FilterBuilder.equalTo(attr);
} else {
return FilterBuilder.containsAllValues(attr);
}

} else {
throw new UnsupportedOperationException("Unsupported filter type in filter: " + objectFilter);
}
} else {
throw new UnsupportedOperationException("Unsupported parent path "+valueFilter.getParentPath()+" in filter: " + objectFilter.debugDump());
throw new UnsupportedOperationException("Unsupported parent path "+valueFilter.getParentPath()+" in filter: " + objectFilter);
}
}

Expand Down

0 comments on commit 4c81ec3

Please sign in to comment.