Skip to content

Commit

Permalink
Fixing case-insensitive matching in filters (MID-1925) + tests. Fixin…
Browse files Browse the repository at this point in the history
…g query schema.
  • Loading branch information
semancik committed May 30, 2014
1 parent 1ad9cd2 commit c28b77e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2014 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 @@ -15,6 +15,7 @@
*/
package com.evolveum.midpoint.prism.match;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.namespace.QName;
Expand Down Expand Up @@ -72,7 +73,9 @@ public boolean matches(String a, String regex) {
return false;
}

return Pattern.matches(regex, a.toLowerCase()) || Pattern.matches(regex, a.toUpperCase());
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(a);
return matcher.matches();
}

}
12 changes: 11 additions & 1 deletion infra/prism/src/main/resources/xml/ns/public/query-3.xsd
Expand Up @@ -293,7 +293,17 @@
<!-- Following element should be constrained a bit more, because their value
is always string respectively. But we don't know how to constrain it now
and we do not have the time to find out. Therefore it should be OK for now. -->
<xsd:element name="substring" substitutionGroup="tns:filterClause" type="tns:PropertySimpleValueFilterClauseType"/>
<xsd:complexType name="SubstringFilterClauseType">
<xsd:complexContent>
<xsd:extension base="tns:PropertySimpleValueFilterClauseType">
<xsd:sequence>
<xsd:element name="anchorStart" type="xsd:boolean" minOccurs="0" default="false"/>
<xsd:element name="anchorEnd" type="xsd:boolean" minOccurs="0" default="false"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="substring" substitutionGroup="tns:filterClause" type="tns:SubstringFilterClauseType"/>

<xsd:element name="org" substitutionGroup="tns:filterClause" type="tns:PropertyComplexValueFilterClauseType"/>
<xsd:element name="orgRef" substitutionGroup="tns:filterClause" type="tns:PropertySimpleValueFilterClauseType"/>
Expand Down
Expand Up @@ -3208,10 +3208,21 @@ public void test510AddProtectedAccounts() throws Exception {
// GIVEN
testAddProtectedAccount(TEST_NAME, "Xavier");
testAddProtectedAccount(TEST_NAME, "Xenophobia");
testAddProtectedAccount(TEST_NAME, "nobody-adm");
testAddAccount(TEST_NAME, "abcadm");
testAddAccount(TEST_NAME, "piXel");
testAddAccount(TEST_NAME, "supernaturalius");
}

@Test
public void test511AddProtectedAccountCaseIgnore() throws Exception {
final String TEST_NAME = "test511AddProtectedAccountCaseIgnore";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
testAddAccount(TEST_NAME, "xaxa");
testAddAccount(TEST_NAME, "somebody-ADM");
}

private PrismObject<ShadowType> createAccountShadow(String username) throws SchemaException {
ResourceSchema resourceSchema = RefinedResourceSchema.getResourceSchema(resource, prismContext);
ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
Expand All @@ -3229,7 +3240,7 @@ private PrismObject<ShadowType> createAccountShadow(String username) throws Sche
return shadow;
}

private void testAddProtectedAccount(final String TEST_NAME, String username) throws SchemaException, ObjectAlreadyExistsException, CommunicationException, ObjectNotFoundException, ConfigurationException {
protected void testAddProtectedAccount(final String TEST_NAME, String username) throws SchemaException, ObjectAlreadyExistsException, CommunicationException, ObjectNotFoundException, ConfigurationException {
Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
Expand Down
Expand Up @@ -98,5 +98,13 @@ public void test176SearchUidCaseNoFetch() throws Exception {
"Will");
}


@Test
public void test511AddProtectedAccountCaseIgnore() throws Exception {
final String TEST_NAME = "test511AddProtectedAccountCaseIgnore";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
testAddProtectedAccount(TEST_NAME, "xaxa");
testAddProtectedAccount(TEST_NAME, "somebody-ADM");
testAddProtectedAccount(TEST_NAME, "everybody-AdM");
}
}
Expand Up @@ -108,15 +108,30 @@
<protected>
<filter>
<q:substring>
<q:matching>stringIgnoreCase</q:matching>
<q:path>
declare namespace icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3";
attributes/icfs:name
</q:path>
<q:value>X</q:value>
<!-- This should also match accounts starting with capital X -->
<q:value>x</q:value>
<q:anchorStart>true</q:anchorStart>
</q:substring>
</filter>
</protected>
<protected>
<filter>
<q:substring>
<q:matching>stringIgnoreCase</q:matching>
<q:path>
declare namespace icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3";
attributes/icfs:name
</q:path>
<q:value>-aDm</q:value>
<q:anchorEnd>true</q:anchorEnd>
</q:substring>
</filter>
</protected>
</objectType>
<objectType>
<kind>entitlement</kind>
Expand Down
Expand Up @@ -157,6 +157,18 @@
</q:substring>
</filter>
</protected>
<protected>
<filter>
<q:substring>
<q:path>
declare namespace icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3";
attributes/icfs:name
</q:path>
<q:value>-adm</q:value>
<q:anchorEnd>true</q:anchorEnd>
</q:substring>
</filter>
</protected>
</objectType>
<objectType>
<kind>entitlement</kind>
Expand Down

0 comments on commit c28b77e

Please sign in to comment.