public static <T> ValueMatcher<T> createDefaultMatcher(QName type, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { MatchingRule<Object> matchingRule = matchingRuleRegistry.getMatchingRule(null, type); return new ValueMatcher<>((MatchingRule<T>) matchingRule); }
@NotNull MatchingRule getMatchingRuleFromRegistry(MatchingRuleRegistry matchingRuleRegistry, Item filterItem) { try { return matchingRuleRegistry.getMatchingRule(matchingRule, filterItem.getDefinition().getTypeName()); } catch (SchemaException ex){ throw new IllegalArgumentException(ex.getMessage(), ex); } }
@NotNull private MatchingRule<Object> getMatchingRuleForTargetNamingIdentifier(RefinedAssociationDefinition associationDefinition) throws SchemaException { RefinedAttributeDefinition<Object> targetNamingAttributeDef = associationDefinition.getAssociationTarget().getNamingAttribute(); if (targetNamingAttributeDef != null) { QName matchingRuleName = targetNamingAttributeDef.getMatchingRuleQName(); return matchingRuleRegistry.getMatchingRule(matchingRuleName, null); } else { throw new IllegalStateException( "Couldn't evaluate tolerant/intolerant value patterns, because naming attribute is not known for " + associationDefinition.getAssociationTarget()); } }
@Override public void initSystem(Task initTask, OperationResult initResult) throws Exception { super.initSystem(initTask, initResult); uidMatchingRule = matchingRuleRegistry.getMatchingRule(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME, DOMUtil.XSD_STRING); }
private <T> Collection<T> getNormalizedAttributeValues(ResourceAttribute<T> attribute, RefinedAttributeDefinition rAttrDef) throws SchemaException { MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(rAttrDef.getMatchingRuleQName(), rAttrDef.getTypeName()); if (matchingRule == null) { return attribute.getRealValues(); } else { Collection<T> normalizedValues = new ArrayList<>(); for (PrismPropertyValue<T> pval: attribute.getValues()) { T normalizedRealValue = matchingRule.normalize(pval.getValue()); normalizedValues.add(normalizedRealValue); } return normalizedValues; } }
<T> T getNormalizedAttributeValue(PrismPropertyValue<T> pval, RefinedAttributeDefinition rAttrDef) throws SchemaException { MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(rAttrDef.getMatchingRuleQName(), rAttrDef.getTypeName()); if (matchingRule != null) { T normalizedRealValue = matchingRule.normalize(pval.getValue()); return normalizedRealValue; } else { return pval.getValue(); } }
private <T> List<PrismPropertyValue<T>> getNormalizedValue(PrismProperty<T> attr, RefinedObjectClassDefinition rObjClassDef) throws SchemaException { RefinedAttributeDefinition<T> refinedAttributeDefinition = rObjClassDef.findAttributeDefinition(attr.getElementName()); QName matchingRuleQName = refinedAttributeDefinition.getMatchingRuleQName(); MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, refinedAttributeDefinition.getTypeName()); List<PrismPropertyValue<T>> normalized = new ArrayList<>(); for (PrismPropertyValue<T> origPValue : attr.getValues()){ T normalizedValue = matchingRule.normalize(origPValue.getValue()); PrismPropertyValue<T> normalizedPValue = origPValue.clone(); normalizedPValue.setValue(normalizedValue); normalized.add(normalizedPValue); } return normalized; }
private void checkMatchingRule(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType, ResourceAttributeDefinitionType attributeDef, QName ref, ResourceAttributeDefinition<?> rad) { QName matchingRule = attributeDef.getMatchingRule(); if (matchingRule == null) { return; } try { matchingRuleRegistry.getMatchingRule(matchingRule, rad != null ? rad.getTypeName() : null); } catch (Throwable t) { ctx.validationResult.add(Issue.Severity.WARNING, CAT_SCHEMA_HANDLING, C_WRONG_MATCHING_RULE, getString(CLASS_DOT + C_WRONG_MATCHING_RULE, getName(objectType), prettyPrintUsingStandardPrefix(ref), t.getMessage()), ctx.resourceRef, path.append(ResourceItemDefinitionType.F_MATCHING_RULE)); } }
private <T> void normalizeAttribute(ResourceAttribute<T> attribute, RefinedAttributeDefinition rAttrDef) throws SchemaException { MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(rAttrDef.getMatchingRuleQName(), rAttrDef.getTypeName()); if (matchingRule != null) { for (PrismPropertyValue<T> pval: attribute.getValues()) { T normalizedRealValue = matchingRule.normalize(pval.getValue()); pval.setValue(normalizedRealValue); } } }
public static <T> ValueMatcher<T> createMatcher(RefinedAttributeDefinition rAttrDef, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { QName matchingRuleQName = rAttrDef.getMatchingRuleQName(); MatchingRule<T> matchingRule; try { matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName()); } catch (SchemaException e) { throw new SchemaException(e.getMessage()+", defined for attribute "+rAttrDef.getName(), e); } return new ValueMatcher<>(matchingRule); }
public static <T> PropertyDelta<T> narrowPropertyDelta(PropertyDelta<T> propertyDelta, PrismObject<ShadowType> currentShadow, QName overridingMatchingRuleQName, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { QName matchingRuleQName = overridingMatchingRuleQName; ItemDefinition propertyDef = propertyDelta.getDefinition(); if (matchingRuleQName == null && propertyDef instanceof RefinedAttributeDefinition) { matchingRuleQName = ((RefinedAttributeDefinition)propertyDef).getMatchingRuleQName(); } MatchingRule<T> matchingRule = null; if (matchingRuleQName != null && propertyDef != null) { matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, propertyDef.getTypeName()); } LOGGER.trace("Narrowing attr def={}, matchingRule={} ({})", propertyDef, matchingRule, matchingRuleQName); PropertyDelta<T> filteredDelta = propertyDelta.narrow(currentShadow, matchingRule); if (LOGGER.isTraceEnabled() && (filteredDelta == null || !filteredDelta.equals(propertyDelta))) { LOGGER.trace("Narrowed delta: {}", filteredDelta==null?null:filteredDelta.debugDump()); } return filteredDelta; }
@Override public void initSystem(Task initTask, OperationResult initResult) throws Exception { // We need to switch off the encryption checks. Some values cannot be encrypted as we do // not have a definition here InternalsConfig.encryptionChecks = false; provisioningService.postInit(initResult); resource = addResourceFromFile(getResourceOpenDjFile(), IntegrationTestTools.CONNECTOR_LDAP_TYPE, initResult); repoAddShadowFromFile(ACCOUNT_BAD_FILE, initResult); dnMatchingRule = matchingRuleRegistry.getMatchingRule(PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, DOMUtil.XSD_STRING); }
@Test public void testStringDefault() throws Exception { // GIVEN MatchingRule<String> rule = matchingRuleRegistry.getMatchingRule(null, DOMUtil.XSD_STRING); // WHEN, THEN assertMatch(rule, "foo", "foo"); assertNoMatch(rule, "foo", "bar"); assertNoMatch(rule, "foo", "Foo"); assertNoMatch(rule, "FOO", "Foo"); assertNormalized(rule, "Foo", "Foo"); assertNormalized(rule, "baR", "baR"); }
private boolean matches(ResourceAttribute<?> identifier, ResourceAttribute<?> attributeToMatch, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { if (!identifier.getElementName().equals(attributeToMatch.getElementName())) { return false; } RefinedAttributeDefinition rAttrDef = rOcDef.findAttributeDefinition(identifier.getElementName()); QName matchingRuleQName = rAttrDef.getMatchingRuleQName(); if (matchingRuleQName == null || matchingRuleRegistry == null) { return identifier.equals(attributeToMatch, EquivalenceStrategy.REAL_VALUE); } MatchingRule<Object> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName()); return matchingRule.match(identifier.getRealValue(), attributeToMatch.getRealValue()); }
private <T> void normalizeDelta(ItemDelta<PrismPropertyValue<T>,PrismPropertyDefinition<T>> delta, RefinedAttributeDefinition rAttrDef) throws SchemaException{ MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(rAttrDef.getMatchingRuleQName(), rAttrDef.getTypeName()); if (matchingRule != null) { if (delta.getValuesToReplace() != null){ normalizeValues(delta.getValuesToReplace(), matchingRule); } if (delta.getValuesToAdd() != null){ normalizeValues(delta.getValuesToAdd(), matchingRule); } if (delta.getValuesToDelete() != null){ normalizeValues(delta.getValuesToDelete(), matchingRule); } } }
@Test public void testStringCaseInsensitive() throws Exception { // GIVEN MatchingRule<String> rule = matchingRuleRegistry.getMatchingRule(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME, DOMUtil.XSD_STRING); // WHEN, THEN assertMatch(rule, "foo", "foo"); assertNoMatch(rule, "foo", "bar"); assertMatch(rule, "foo", "Foo"); assertMatch(rule, "FOO", "Foo"); assertNormalized(rule, "bar", "baR"); assertNormalized(rule, "foo", "FoO"); assertNormalized(rule, "foobar", "foobar"); }
@Test public void testPolyStringStrict() throws Exception { // GIVEN MatchingRule<PolyString> rule = matchingRuleRegistry.getMatchingRule(PrismConstants.POLY_STRING_STRICT_MATCHING_RULE_NAME, PolyStringType.COMPLEX_TYPE); // WHEN, THEN assertMatch(rule, new PolyString("Bar", "bar"), new PolyString("Bar", "bar")); assertNoMatch(rule, new PolyString("BAR", "bar"), new PolyString("Foo", "bar")); assertNoMatch(rule, new PolyString("Bar", "bar"), new PolyString("bAR", "bar")); assertNoMatch(rule, new PolyString("Bar", "bar"), new PolyString("Bar", "barbar")); }
@Test public void testPolyStringOrig() throws Exception { // GIVEN MatchingRule<PolyString> rule = matchingRuleRegistry.getMatchingRule(PrismConstants.POLY_STRING_ORIG_MATCHING_RULE_NAME, PolyStringType.COMPLEX_TYPE); // WHEN, THEN assertMatch(rule, new PolyString("Bar", "bar"), new PolyString("Bar", "bar")); assertNoMatch(rule, new PolyString("BAR", "bar"), new PolyString("Foo", "bar")); assertNoMatch(rule, new PolyString("Bar", "bar"), new PolyString("bAR", "bar")); assertMatch(rule, new PolyString("Bar", "bar"), new PolyString("Bar", "barbar")); }
@Test public void testPolyStringNorm() throws Exception { // GIVEN MatchingRule<PolyString> rule = matchingRuleRegistry.getMatchingRule(PrismConstants.POLY_STRING_NORM_MATCHING_RULE_NAME, PolyStringType.COMPLEX_TYPE); // WHEN, THEN assertMatch(rule, new PolyString("Bar", "bar"), new PolyString("Bar", "bar")); assertMatch(rule, new PolyString("BAR", "bar"), new PolyString("Foo", "bar")); assertMatch(rule, new PolyString("Bar", "bar"), new PolyString("bAR", "bar")); assertNoMatch(rule, new PolyString("Bar", "bar"), new PolyString("Bar", "barbar")); }
@Override public void initSystem(Task initTask, OperationResult initResult) throws Exception { super.initSystem(initTask, initResult); caseIgnoreMatchingRule = matchingRuleRegistry.getMatchingRule(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME, DOMUtil.XSD_STRING); preTestCleanup(AssignmentPolicyEnforcementType.FULL); repoAddObjectFromFile(ROLE_X_FILE, initResult); repoAddObjectFromFile(ROLE_JOKER_FILE, initResult); repoAddObjectFromFile(ROLE_UPCASE_BASIC_FILE, initResult); repoAddObjectFromFile(ROLE_FOOL_FILE, initResult); InternalMonitor.reset(); InternalMonitor.setTrace(InternalOperationClasses.SHADOW_FETCH_OPERATIONS, false); InternalMonitor.setTrace(InternalOperationClasses.RESOURCE_SCHEMA_OPERATIONS, false); }