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
katkav committed Mar 20, 2017
2 parents 419a45c + cc6b020 commit 934b36b
Show file tree
Hide file tree
Showing 78 changed files with 1,592 additions and 576 deletions.
Expand Up @@ -1214,7 +1214,7 @@ public static String createUserIcon(PrismObject<UserType> object) {

boolean isManager = false;
for (ObjectReferenceType parentOrgRef : user.getParentOrgRef()) {
if (SchemaConstants.ORG_MANAGER.equals(parentOrgRef.getRelation())) {
if (ObjectTypeUtil.isManagerRelation(parentOrgRef.getRelation())) {
isManager = true;
break;
}
Expand Down Expand Up @@ -1529,7 +1529,7 @@ public static boolean isObjectOrgManager(PrismObject<? extends ObjectType> objec
List<ObjectReferenceType> parentOrgRefs = objectType.getParentOrgRef();

for (ObjectReferenceType ref : parentOrgRefs) {
if (ref.getRelation() != null && ref.getRelation().equals(SchemaConstants.ORG_MANAGER)) {
if (ObjectTypeUtil.isManagerRelation(ref.getRelation())) {
return true;
}
}
Expand Down
Expand Up @@ -24,6 +24,7 @@

import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.web.page.admin.users.component.AssignmentsPreviewDto;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
Expand Down Expand Up @@ -227,11 +228,11 @@ private List<AssignmentsPreviewDto> getAssignmentPrivilegesList(AssignmentType a
private Boolean determineUserOrgRelation(AssignmentType assignment) {

if (assignment == null || assignment.getTargetRef() == null
|| assignment.getTargetRef().getRelation() == null) {
|| ObjectTypeUtil.isDefaultRelation(assignment.getTargetRef().getRelation())) {
return Boolean.FALSE;
}

if (SchemaConstants.ORG_MANAGER.equals(assignment.getTargetRef().getRelation())) {
if (ObjectTypeUtil.isManagerRelation(assignment.getTargetRef().getRelation())) {
return Boolean.TRUE;
}

Expand Down Expand Up @@ -581,7 +582,7 @@ public QName getFocusType() {
public String getRelation() {
ObjectReferenceType ref = newAssignment.getTargetRef();
if (ref == null || ref.getRelation() == null) {
return null;
return null; // TODO member vs. null ?
}

return ref.getRelation().getLocalPart();
Expand Down
Expand Up @@ -421,7 +421,7 @@ public boolean isVisible() {
IModel<RelationTypes> relationModel = new IModel<RelationTypes>() {
@Override
public RelationTypes getObject() {
if (getModelObject().getTargetRef() == null){
if (getModelObject().getTargetRef() == null) {
return RelationTypes.MEMBER;
}
return RelationTypes.getRelationType(getModelObject().getTargetRef().getRelation());
Expand Down
Expand Up @@ -17,6 +17,8 @@
package com.evolveum.midpoint.web.component.assignment;

import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.QNameUtil;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -47,12 +49,12 @@ public String getHeaderLabel() {
return headerLabel;
}

public static RelationTypes getRelationType(QName relation){
if (relation == null){
public static RelationTypes getRelationType(QName relation) {
if (ObjectTypeUtil.isDefaultRelation(relation)) {
return RelationTypes.MEMBER;
}
for (RelationTypes relationTypes : RelationTypes.values()){
if (relation.equals(relationTypes.getRelation())){
for (RelationTypes relationTypes : RelationTypes.values()) {
if (QNameUtil.match(relation, relationTypes.getRelation())) {
return relationTypes;
}
}
Expand Down
Expand Up @@ -19,6 +19,7 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
Expand Down Expand Up @@ -97,7 +98,7 @@ protected void initialize(ObjectWrapper<UserType> wrapper) {
boolean isManager = false;
boolean isMember = false;
for (ObjectReferenceType parentOrgRef: wrapper.getObject().asObjectable().getParentOrgRef()) {
if (SchemaConstants.ORG_MANAGER.equals(parentOrgRef.getRelation())) {
if (ObjectTypeUtil.isManagerRelation(parentOrgRef.getRelation())) {
isManager = true;
} else {
isMember = true;
Expand Down
Expand Up @@ -64,8 +64,8 @@ public Authentication authenticate(Authentication authentication) throws Authent

MidPointPrincipal principal = (MidPointPrincipal)token.getPrincipal();

LOGGER.debug("User '{}' authenticated ({}), authorities: {}", new Object[]{authentication.getPrincipal(),
authentication.getClass().getSimpleName(), principal.getAuthorities()});
LOGGER.debug("User '{}' authenticated ({}), authorities: {}", authentication.getPrincipal(),
authentication.getClass().getSimpleName(), principal.getAuthorities());
return token;
}

Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
Expand Down Expand Up @@ -71,6 +72,7 @@ public static boolean matches(PrismObject<ShadowType> shadowToMatch,

public boolean matches(PrismObject<ShadowType> shadowToMatch, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException {
if (objectFilter != null) {
ObjectTypeUtil.normalizeFilter(objectFilter); // we suppose references in shadowToMatch are normalized (on return from repo)
return ObjectQuery.match(shadowToMatch, objectFilter, matchingRuleRegistry);
} else {
// Deprecated method
Expand Down
Expand Up @@ -230,5 +230,8 @@ <C extends Containerable, O extends Objectable> void adopt(PrismContainerValue<C

void setMonitor(PrismMonitor monitor);


/**
* If defined, it is considered to be the same as the relation of 'null'. Currently in midPoint, it is the value of org:default.
*/
QName getDefaultRelation();
}
Expand Up @@ -71,6 +71,8 @@ public class PrismContextImpl implements PrismContext {
// We need to keep this because of deprecated methods and various hacks
@NotNull private final JaxbDomHack jaxbDomHack;

private QName defaultRelation;

//region Standard overhead
private PrismContextImpl(@NotNull SchemaRegistryImpl schemaRegistry) {
this.schemaRegistry = schemaRegistry;
Expand Down Expand Up @@ -213,7 +215,14 @@ public void setMonitor(PrismMonitor monitor) {
this.monitor = monitor;
}

//endregion
public QName getDefaultRelation() {
return defaultRelation;
}

public void setDefaultRelation(QName defaultRelation) {
this.defaultRelation = defaultRelation;
}
//endregion

//region Parsing
@NotNull
Expand Down
Expand Up @@ -31,7 +31,6 @@

import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -380,10 +379,8 @@ public PrismReferenceValue toCanonical() {

@Override
public boolean equalsComplex(PrismValue other, boolean ignoreMetadata, boolean isLiteral) {
if (other == null || !(other instanceof PrismReferenceValue)) {
return false;
}
return equalsComplex((PrismReferenceValue)other, ignoreMetadata, isLiteral);
return other instanceof PrismReferenceValue
&& equalsComplex((PrismReferenceValue) other, ignoreMetadata, isLiteral);
}

public boolean equalsComplex(PrismReferenceValue other, boolean ignoreMetadata, boolean isLiteral) {
Expand All @@ -410,14 +407,24 @@ public boolean equalsComplex(PrismReferenceValue other, boolean ignoreMetadata,
if (!equalsTargetType(other)) {
return false;
}
if (this.relation == null) {
if (other.relation != null)
return false;
} else if (!this.relation.equals(other.relation))
if (!relationsEquivalent(relation, other.relation)) {
return false;
}
return true;
}

private boolean relationsEquivalent(QName r1, QName r2) {
return QNameUtil.match(normalizedRelation(r1), normalizedRelation(r2));
}

private QName normalizedRelation(QName r) {
if (r != null) {
return r;
}
PrismContext prismContext = getPrismContext();
return prismContext != null ? prismContext.getDefaultRelation() : null;
}

private boolean equalsTargetType(PrismReferenceValue other) {
QName otherTargetType = other.getTargetType();
if (otherTargetType == null && other.getDefinition() != null) {
Expand Down Expand Up @@ -463,7 +470,7 @@ public boolean representsSameValue(PrismValue other, boolean lax) {

public boolean representsSameValue(PrismReferenceValue other) {
if (this.getOid() != null && other.getOid() != null) {
return this.getOid().equals(other.getOid()) && Objects.equals(this.getRelation(), other.getRelation());
return this.getOid().equals(other.getOid()) && relationsEquivalent(this.getRelation(), other.getRelation());
}
return false;
}
Expand Down
Expand Up @@ -412,7 +412,7 @@ public static <T> PropertyDelta<T> findPropertyDelta(Collection<? extends ItemDe
public static <T> PropertyDelta<T> findPropertyDelta(Collection<? extends ItemDelta> modifications, QName propertyName) {
for (ItemDelta delta: modifications) {
if (delta instanceof PropertyDelta && delta.getParentPath().isEmpty() &&
QNameUtil.match(delta.getElementName(),propertyName)) {
QNameUtil.match(delta.getElementName(), propertyName)) {
return (PropertyDelta) delta;
}
}
Expand Down
Expand Up @@ -112,12 +112,12 @@ public static ReferenceDelta createModificationReplace(ItemPath path, PrismObjec

public static <O extends Objectable> ReferenceDelta createModificationReplace(QName refName, Class<O> type, PrismContext ctx , String oid) {
PrismObjectDefinition<O> objectDefinition = ctx.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
return createModificationReplace(refName, objectDefinition, new PrismReferenceValue(oid));
return createModificationReplace(refName, objectDefinition, oid==null?null:new PrismReferenceValue(oid));
}

public static <O extends Objectable> ReferenceDelta createModificationReplace(ItemPath path, Class<O> type, PrismContext ctx, String oid) {
PrismObjectDefinition<O> objectDefinition = ctx.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
return createModificationReplace(path, objectDefinition, new PrismReferenceValue(oid));
return createModificationReplace(path, objectDefinition, oid==null?null:new PrismReferenceValue(oid));
}

public static ReferenceDelta createModificationReplace(ItemPath path, PrismObjectDefinition<?> objectDefinition,
Expand All @@ -144,7 +144,11 @@ public static ReferenceDelta createModificationReplace(QName refName, PrismObjec
PrismReferenceValue refValue) {
PrismReferenceDefinition referenceDefinition = objectDefinition.findItemDefinition(refName, PrismReferenceDefinition.class);
ReferenceDelta referenceDelta = new ReferenceDelta(refName, referenceDefinition, objectDefinition.getPrismContext()); // hoping the prismContext is there
referenceDelta.setValueToReplace(refValue);
if (refValue == null) {
referenceDelta.setValueToReplace();
} else {
referenceDelta.setValueToReplace(refValue);
}
return referenceDelta;
}

Expand Down
Expand Up @@ -31,12 +31,12 @@
*/
public class MatchingRuleRegistry {

@NotNull public final MatchingRule <? extends Object> defaultMatchingRule;
public Map<QName, ? extends MatchingRule<?>> matchingRules = new HashMap<QName, MatchingRule<?>>();
@NotNull public final MatchingRule<?> defaultMatchingRule;
public Map<QName, ? extends MatchingRule<?>> matchingRules = new HashMap<>();

public MatchingRuleRegistry() {
super();
this.defaultMatchingRule = new DefaultMatchingRule<Object>();
this.defaultMatchingRule = new DefaultMatchingRule<>();
}

public MatchingRuleRegistry(Collection<? extends MatchingRule<?>> matchingRules) {
Expand Down
Expand Up @@ -28,6 +28,8 @@

public abstract class ObjectFilter implements DebugDumpable, Serializable, Revivable {

transient private PrismContext prismContext;

/**
* Does a SHALLOW clone.
*/
Expand All @@ -42,9 +44,18 @@ public void accept(Visitor visitor) {
@Override
public void revive(PrismContext prismContext) throws SchemaException {
QueryConvertor.revive(this, prismContext);
this.prismContext = prismContext;
}

public abstract void checkConsistence(boolean requireDefinitions);

public abstract boolean equals(Object o, boolean exact);

public PrismContext getPrismContext() {
return prismContext;
}

public void setPrismContext(PrismContext prismContext) {
this.prismContext = prismContext;
}
}
Expand Up @@ -91,11 +91,15 @@ public static ObjectQuery createObjectQuery(ObjectFilter filter, ObjectPaging pa
query.setPaging(paging);
return query;
}


// although we do our best to match even incomplete relations (null, unqualified), ultimately
// it is the client's responsibility to ensure relations in object and filter are normalized (namely: null -> org:default)
public static <T extends Objectable> boolean match(PrismObject<T> object, ObjectFilter filter, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException{
return filter.match(object.getValue(), matchingRuleRegistry);
}

// although we do our best to match even incomplete relations (null, unqualified), ultimately
// it is the client's responsibility to ensure relations in object and filter are normalized (namely: null -> org:default)
public static boolean match(Containerable object, ObjectFilter filter, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException{
return filter.match(object.asPrismContainerValue(), matchingRuleRegistry);
}
Expand Down
Expand Up @@ -15,16 +15,15 @@
*/
package com.evolveum.midpoint.prism.query;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.match.MatchingRuleRegistry;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -74,7 +73,7 @@ public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRul
}

assert !filterItemIsEmpty; // if both are empty, the previous statement causes 'return true'
assert !objectItemIsEmpty; // if only one of them is empty, the super.match() returnsed false
assert !objectItemIsEmpty; // if only one of them is empty, the super.match() returned false

List<Object> objectValues = objectItem.getValues();
for (Object v : objectValues) {
Expand All @@ -95,14 +94,38 @@ private boolean isInFilterItem(PrismReferenceValue v, Item filterItem) {
throw new IllegalArgumentException("Not supported prism value for ref equals filter. It must be an instance of PrismReferenceValue but it is " + v.getClass());
}
PrismReferenceValue filterRV = (PrismReferenceValue) filterValue;
if (filterRV.getOid().equals(v.getOid())) {
if (valuesMatch(v, filterRV)) {
return true;
}
// TODO compare relation and target type as well (see repo implementation in ReferenceRestriction)
}
return false;
}

private boolean valuesMatch(PrismReferenceValue value, PrismReferenceValue filterValue) {
if (!value.getOid().equals(filterValue.getOid())) {
return false;
}
if (!QNameUtil.match(PrismConstants.Q_ANY, filterValue.getRelation())) {
// similar to relation-matching code in PrismReferenceValue (but awkward to unify, so keeping separate)
PrismContext prismContext = getPrismContext();
QName thisRelation = value.getRelation();
QName filterRelation = filterValue.getRelation();
if (prismContext != null) {
if (thisRelation == null) {
thisRelation = prismContext.getDefaultRelation();
}
if (filterRelation == null) {
filterRelation = prismContext.getDefaultRelation();
}
}
if (!QNameUtil.match(thisRelation, filterRelation)) {
return false;
}
}
// TODO treat also targetType (see ReferenceRestriction in repo)
return true;
}

@Override
public boolean equals(Object obj, boolean exact) {
return obj instanceof RefFilter && super.equals(obj, exact);
Expand Down

0 comments on commit 934b36b

Please sign in to comment.