Skip to content

Commit

Permalink
feat(config-api): multiple pattern handling for search request (#2590)
Browse files Browse the repository at this point in the history
* feat(config-api): multiple search pattern handled

* feat(config-api): multiple search pattern handled

* feat(config-api): multiple search pattern handled
  • Loading branch information
pujavs authored Oct 11, 2022
1 parent 2fc3d6e commit 46886fb
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 64 deletions.
20 changes: 10 additions & 10 deletions jans-config-api/docs/jans-config-api-swagger-auto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2947,18 +2947,18 @@ components:
type: string
whitePagesCanView:
type: boolean
adminCanAccess:
type: boolean
userCanView:
type: boolean
adminCanView:
type: boolean
userCanAccess:
type: boolean
userCanEdit:
type: boolean
adminCanEdit:
type: boolean
userCanView:
type: boolean
userCanAccess:
type: boolean
adminCanAccess:
type: boolean
baseDn:
type: string
PatchRequest:
Expand Down Expand Up @@ -3386,24 +3386,24 @@ components:
type: array
items:
type: object
displayValue:
type: string
value:
type: object
displayValue:
type: string
LocalizedString:
type: object
properties:
values:
type: object
additionalProperties:
type: string
value:
type: string
languageTags:
uniqueItems: true
type: array
items:
type: string
value:
type: string
AppConfiguration:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ components:
type: array
items:
type: object
displayValue:
type: string
value:
type: object
displayValue:
type: string
CustomUser:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion jans-config-api/plugins/fido2-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<properties>
<httpcore.version>4.4.14</httpcore.version>
<httpclient.version>4.5.13</httpclient.version>
<jans.version>1.0.1</jans.version>
<jans.version>${project.version}</jans.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion jans-config-api/plugins/sample/demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<plugin.id>demo-plugin</plugin.id>
<plugin.version>0.1</plugin.version>

<jans.version>1.0.1</jans.version>
<jans.version>${project.version}</jans.version>
<weld.version>4.0.3.Final</weld.version>
<resteasy.version>4.5.7.Final</resteasy.version>
<log4j.version>2.17.1</log4j.version>
Expand Down
2 changes: 1 addition & 1 deletion jans-config-api/plugins/sample/helloworld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<plugin.id>hello-world-plugin</plugin.id>
<plugin.version>0.1</plugin.version>

<jans.version>1.0.1</jans.version>
<jans.version>${project.version}</jans.version>
<weld.version>4.0.3.Final</weld.version>
<resteasy.version>4.5.7.Final</resteasy.version>
<log4j.version>2.17.1</log4j.version>
Expand Down
2 changes: 1 addition & 1 deletion jans-config-api/plugins/user-mgt-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<properties>
<httpcore.version>4.4.14</httpcore.version>
<httpclient.version>4.5.13</httpclient.version>
<jans.version>1.0.1</jans.version>
<jans.version>${project.version}</jans.version>

<sonar.cpd.exclusions>src/main/java/io/jans/configapi/plugin/fido2/model/config/*</sonar.cpd.exclusions>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,22 @@ public PagedResult<User> searchUsers(SearchRequest searchRequest) {
if (logger.isDebugEnabled()) {
logger.debug("Search Users with searchRequest:{}", escapeLog(searchRequest));
}

Filter searchFilter = null;
if (StringUtils.isNotEmpty(searchRequest.getFilter())) {
String[] targetArray = new String[] { searchRequest.getFilter() };
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null, targetArray,
null);
Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null, targetArray,
null);
Filter inumFilter = Filter.createSubstringFilter(AttributeConstants.INUM, null, targetArray, null);
searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, inumFilter);
List<Filter> filters = new ArrayList<>();
if (searchRequest.getFilterAssertionValue() != null && !searchRequest.getFilterAssertionValue().isEmpty()) {

for (String assertionValue : searchRequest.getFilterAssertionValue()) {
String[] targetArray = new String[] { assertionValue };
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null,
targetArray, null);
Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null,
targetArray, null);
Filter uidFilter = Filter.createSubstringFilter("uid", null, targetArray, null);
Filter inumFilter = Filter.createSubstringFilter(AttributeConstants.INUM, null, targetArray, null);
filters.add(Filter.createORFilter(displayNameFilter, descriptionFilter, uidFilter, inumFilter));
}
searchFilter = Filter.createORFilter(filters);
}

return persistenceEntryManager.findPagedEntries(getPeopleBaseDn(), User.class, searchFilter, null,
Expand Down
8 changes: 4 additions & 4 deletions jans-config-api/profiles/local/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
test.scopes=https://jans.io/oauth/config/acrs.readonly https://jans.io/oauth/config/acrs.write https://jans.io/oauth/config/attributes.readonly https://jans.io/oauth/config/attributes.write https://jans.io/oauth/config/attributes.delete https://jans.io/oauth/config/cache.readonly https://jans.io/oauth/config/cache.write https://jans.io/oauth/config/openid/clients.readonly https://jans.io/oauth/config/openid/clients.write https://jans.io/oauth/config/openid/clients.delete https://jans.io/oauth/jans-auth-server/config/properties.readonly https://jans.io/oauth/jans-auth-server/config/properties.write https://jans.io/oauth/config/smtp.readonly https://jans.io/oauth/config/smtp.write https://jans.io/oauth/config/smtp.delete https://jans.io/oauth/config/database/couchbase.readonly https://jans.io/oauth/config/database/couchbase.write https://jans.io/oauth/config/database/couchbase.delete https://jans.io/oauth/config/scripts.readonly https://jans.io/oauth/config/scripts.write https://jans.io/oauth/config/scripts.delete https://jans.io/oauth/config/fido2.readonly https://jans.io/oauth/config/fido2.write https://jans.io/oauth/config/jwks.readonly https://jans.io/oauth/config/jwks.write https://jans.io/oauth/config/jwks.delete https://jans.io/oauth/config/database/ldap.readonly https://jans.io/oauth/config/database/ldap.write https://jans.io/oauth/config/database/ldap.delete https://jans.io/oauth/config/logging.readonly https://jans.io/oauth/config/logging.write https://jans.io/oauth/config/scopes.readonly https://jans.io/oauth/config/scopes.write https://jans.io/oauth/config/scopes.delete https://jans.io/oauth/config/uma/resources.readonly https://jans.io/oauth/config/uma/resources.write https://jans.io/oauth/config/uma/resources.delete https://jans.io/oauth/config/database/sql.readonly https://jans.io/oauth/config/database/sql.write https://jans.io/oauth/config/database/sql.delete https://jans.io/oauth/config/stats.readonly jans_stat https://jans.io/scim/users.read https://jans.io/scim/users.write https://jans.io/oauth/config/scim/users.read https://jans.io/oauth/config/scim/users.write https://jans.io/scim/config.readonly https://jans.io/scim/config.write https://jans.io/oauth/config/organization.readonly https://jans.io/oauth/config/organization.write https://jans.io/oauth/config/user.readonly https://jans.io/oauth/config/user.write https://jans.io/oauth/config/user.delete https://jans.io/oauth/config/agama.readonly https://jans.io/oauth/config/agama.write https://jans.io/oauth/config/agama.delete https://jans.io/oauth/jans-auth-server/session.readonly https://jans.io/oauth/jans-auth-server/session.delete revoke_session

# jans.server
token.endpoint=https://jans.server1/jans-auth/restv1/token
token.endpoint=https://jans.server2/jans-auth/restv1/token
token.grant.type=client_credentials
test.client.id=1800.ed3327bb-0924-44f9-84c7-6778b5479011
test.client.secret=enZafGCW9afd
test.issuer=https://jans.server1/
test.client.id=1800.c77a9cd0-112c-404a-ac6b-609cb1597630
test.client.secret=MtL8igXDeMpw
test.issuer=https://jans.server2/
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public PagedResult<GluuAttribute> searchGluuAttributes(SearchRequest searchReque
Filter searchFilter = null;
List<Filter> filters = new ArrayList<>();
if (searchRequest.getFilterAssertionValue() != null && !searchRequest.getFilterAssertionValue().isEmpty()) {

for (String assertionValue : searchRequest.getFilterAssertionValue()) {
String[] targetArray = new String[] { assertionValue };
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null,
Expand All @@ -45,12 +45,12 @@ public PagedResult<GluuAttribute> searchGluuAttributes(SearchRequest searchReque
targetArray, null);
Filter nameFilter = Filter.createSubstringFilter(AttributeConstants.JANS_ATTR_NAME, null, targetArray,
null);
filters.add(Filter.createORFilter(displayNameFilter, descriptionFilter, nameFilter));
Filter inumFilter = Filter.createSubstringFilter(AttributeConstants.INUM, null, targetArray, null);
filters.add(Filter.createORFilter(displayNameFilter, descriptionFilter, nameFilter, inumFilter));
}
searchFilter = Filter.createORFilter(filters);
}


if (activeFilter != null) {
searchFilter = Filter.createANDFilter(Filter.createORFilter(filters), activeFilter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,23 @@ public PagedResult<Client> getClients(SearchRequest searchRequest) {
logger.debug("Search Clients with searchRequest:{}", searchRequest);

Filter searchFilter = null;
if (StringUtils.isNotEmpty(searchRequest.getFilter())) {
String[] targetArray = new String[] { searchRequest.getFilter() };
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null, targetArray,
null);
Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null, targetArray,
null);
Filter inumFilter = Filter.createSubstringFilter(AttributeConstants.INUM, null, targetArray, null);
searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, inumFilter);
List<Filter> filters = new ArrayList<>();
if (searchRequest.getFilterAssertionValue() != null && !searchRequest.getFilterAssertionValue().isEmpty()) {

for (String assertionValue : searchRequest.getFilterAssertionValue()) {
String[] targetArray = new String[] { assertionValue };
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null,
targetArray, null);
Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null,
targetArray, null);
Filter inumFilter = Filter.createSubstringFilter(AttributeConstants.INUM, null, targetArray, null);
filters.add(Filter.createORFilter(displayNameFilter, descriptionFilter, inumFilter));
}
searchFilter = Filter.createORFilter(filters);
}

logger.debug("Clients searchFilter:{}", searchFilter);

return persistenceEntryManager.findPagedEntries(getDnForClient(null), Client.class, searchFilter, null,
searchRequest.getSortBy(), SortOrder.getByValue(searchRequest.getSortOrder()),
searchRequest.getStartIndex() - 1, searchRequest.getCount(), searchRequest.getMaxCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,29 @@ public PagedResult<CustomScope> getScopeResult(SearchRequest searchRequest, Stri
logger.debug("Search Scope with searchRequest:{}, scopeType:{}, withAssociatedClients:{}", searchRequest,
scopeType, withAssociatedClients);

String[] targetArray = new String[] { searchRequest.getFilter() };
Filter searchFilter = null;
List<Filter> filters = new ArrayList<>();
if (searchRequest.getFilterAssertionValue() != null && !searchRequest.getFilterAssertionValue().isEmpty()) {

for (String assertionValue : searchRequest.getFilterAssertionValue()) {
String[] targetArray = new String[] { assertionValue };
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null,
targetArray, null);
Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null,
targetArray, null);
Filter nameFilter = Filter.createSubstringFilter(AttributeConstants.JANS_ID, null, targetArray, null);
Filter inumFilter = Filter.createSubstringFilter(AttributeConstants.INUM, null, targetArray, null);
filters.add(Filter.createORFilter(displayNameFilter, descriptionFilter, nameFilter, inumFilter));
}
searchFilter = Filter.createORFilter(filters);
}

Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null, targetArray,
null);
Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null, targetArray,
null);
Filter searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter);
if (StringHelper.isNotEmpty(scopeType)) {
searchFilter = Filter.createANDFilter(Filter.createEqualityFilter(JANS_SCOPE_TYP, scopeType), searchFilter);
searchFilter = Filter.createANDFilter(Filter.createORFilter(filters),
Filter.createEqualityFilter(JANS_SCOPE_TYP, scopeType));
}
logger.debug("Search Scope with searchFilter:{}", searchFilter);

logger.debug("Final Scope searchFilter:{}", searchFilter);

PagedResult<CustomScope> pagedResult = persistenceEntryManager.findPagedEntries(getDnForScope(null),
CustomScope.class, searchFilter, null, searchRequest.getSortBy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -141,12 +142,23 @@ public String getBaseDnForResource() {
public PagedResult<UmaResource> searchUmaResource(SearchRequest searchRequest) {
logger.debug("Search UmaResource with searchRequest:{}", searchRequest);

String[] targetArray = new String[] { searchRequest.getFilter() };
Filter jsIdFilter = Filter.createSubstringFilter("jansId", null, targetArray, null);
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null, targetArray,
null);
Filter searchFilter = Filter.createORFilter(jsIdFilter, displayNameFilter);
logger.debug("Search UmaResources with searchFilter:{}", searchFilter);
Filter searchFilter = null;
List<Filter> filters = new ArrayList<>();
if (searchRequest.getFilterAssertionValue() != null && !searchRequest.getFilterAssertionValue().isEmpty()) {

for (String assertionValue : searchRequest.getFilterAssertionValue()) {
String[] targetArray = new String[] { assertionValue };
Filter displayNameFilter = Filter.createSubstringFilter(AttributeConstants.DISPLAY_NAME, null,
targetArray, null);
Filter descriptionFilter = Filter.createSubstringFilter(AttributeConstants.DESCRIPTION, null,
targetArray, null);
Filter inumFilter = Filter.createSubstringFilter(AttributeConstants.JANS_ID, null, targetArray, null);
filters.add(Filter.createORFilter(displayNameFilter, descriptionFilter, inumFilter));
}
searchFilter = Filter.createORFilter(filters);
}

logger.debug("UmaResources searchFilter:{}", searchFilter);

return persistenceEntryManager.findPagedEntries(getBaseDnForResource(), UmaResource.class, searchFilter, null,
searchRequest.getSortBy(), SortOrder.getByValue(searchRequest.getSortOrder()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,35 @@

@ApplicationScoped
public class Util {

@Inject
Logger log;

public static String escapeLog(Object param) {
if (param == null)
return "";
return param.toString().replaceAll("[\n\r\t]", "_");
}

public List<String> getTokens(String str, String format) {
log.debug(" String to get tokens - str:{}, format:{}", str, format);

ArrayList<String> list = new ArrayList<>();
if (StringUtils.isBlank(str)) {
return Collections.emptyList();
list.add("");
return list;
}

log.debug("str.contains(format):{}", str.contains(format));
if( !str.contains(format)) {
ArrayList<String> list = new ArrayList<>();
if (!str.contains(format)) {

list.add(str);
log.debug(" Not tokenized - list:{}", list);
return (list);
return list;
}
log.debug("final tokenized list:{}", Collections.list(new StringTokenizer(str, format)).stream().map(token -> (String) token)
.collect(Collectors.toList()));

log.debug("final tokenized list:{}", Collections.list(new StringTokenizer(str, format)).stream()
.map(token -> (String) token).collect(Collectors.toList()));
return Collections.list(new StringTokenizer(str, format)).stream().map(token -> (String) token)
.collect(Collectors.toList());
}
Expand Down

0 comments on commit 46886fb

Please sign in to comment.