executeList(CommandContext commandContext, Page page) {
+ final LdapIdentityProviderSession provider = getLdapIdentityProvider(commandContext);
+ return provider.findUserByQueryCriteria(this);
+ }
+
+ protected LdapIdentityProviderSession getLdapIdentityProvider(CommandContext commandContext) {
+ return (LdapIdentityProviderSession) commandContext.getReadOnlyIdentityProvider();
+ }
+
+ @Override
+ public UserQuery desc() {
+ // provide this exception then a popup will be visible in the admin task, but display will run correctly
+ if (ldapConfiguration != null && !ldapConfiguration.isSortControlSupported()) {
+ throw new UnsupportedOperationException("The LDAP identity provider does not support descending search order.");
+ }
+
+ return this;
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/plugin/LdapIdentityProviderPlugin.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/plugin/LdapIdentityProviderPlugin.java
new file mode 100644
index 0000000000000000000000000000000000000000..d6c80d2e77be619940a16e928d863ecc29ef2ccb
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/plugin/LdapIdentityProviderPlugin.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap.plugin;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.camunda.bpm.engine.ProcessEngine;
+import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
+import org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin;
+import org.camunda.bpm.identity.impl.ldap.LdapConfiguration;
+import org.camunda.bpm.identity.impl.ldap.LdapIdentityProviderFactory;
+import org.camunda.bpm.identity.impl.ldap.util.CertificateHelper;
+import org.camunda.bpm.identity.impl.ldap.util.LdapPluginLogger;
+
+/**
+ * {@link ProcessEnginePlugin} providing Ldap Identity Provider support
+ *
+ * This class extends {@link LdapConfiguration} such that the configuration properties
+ * can be set directly on this class vie the <properties .../> element
+ * in bpm-platform.xml / processes.xml
+ *
+ * @author Daniel Meyer
+ *
+ */
+public class LdapIdentityProviderPlugin extends LdapConfiguration implements ProcessEnginePlugin {
+
+ protected boolean acceptUntrustedCertificates = false;
+
+ public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
+
+ LdapPluginLogger.INSTANCE.pluginActivated(getClass().getSimpleName(), processEngineConfiguration.getProcessEngineName());
+
+ if(acceptUntrustedCertificates) {
+ CertificateHelper.acceptUntrusted();
+ LdapPluginLogger.INSTANCE.acceptingUntrustedCertificates();
+ }
+
+ LdapIdentityProviderFactory ldapIdentityProviderFactory = new LdapIdentityProviderFactory();
+ ldapIdentityProviderFactory.setLdapConfiguration(this);
+ processEngineConfiguration.setIdentityProviderSessionFactory(ldapIdentityProviderFactory);
+
+ }
+
+ public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
+ // nothing to do
+ }
+
+ public void postProcessEngineBuild(ProcessEngine processEngine) {
+ // nothing to do
+ }
+
+ public void setAcceptUntrustedCertificates(boolean acceptUntrustedCertificates) {
+ this.acceptUntrustedCertificates = acceptUntrustedCertificates;
+ }
+
+ public boolean isAcceptUntrustedCertificates() {
+ return acceptUntrustedCertificates;
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/util/CertificateHelper.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/util/CertificateHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..0209a426c60e46b0e536ae1c6aa7ef438dc56020
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/util/CertificateHelper.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap.util;
+
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+
+public class CertificateHelper {
+
+ public static void acceptUntrusted() {
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
+ SSLContext.setDefault(sslContext);
+ } catch (Exception ex) {
+ throw new RuntimeException("Could not change SSL TrustManager to accept arbitrary certificates", ex);
+ }
+ }
+
+ private static class DefaultTrustManager implements X509TrustManager {
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+
+ }
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/util/LdapPluginLogger.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/util/LdapPluginLogger.java
new file mode 100644
index 0000000000000000000000000000000000000000..e52c6dd5ce165c8aeae2543107df9dd9039d9ec4
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/main/java/org/camunda/bpm/identity/impl/ldap/util/LdapPluginLogger.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap.util;
+
+import javax.naming.directory.SearchResult;
+
+import org.camunda.bpm.engine.impl.db.DbEntity;
+import org.camunda.bpm.engine.impl.persistence.entity.UserEntity;
+import org.camunda.commons.logging.BaseLogger;
+
+/**
+ * @author Thorben Lindhauer
+ *
+ */
+public class LdapPluginLogger extends BaseLogger {
+
+ public static final String PROJECT_CODE = "LDAP";
+
+ public static final LdapPluginLogger INSTANCE = BaseLogger.createLogger(
+ LdapPluginLogger.class, PROJECT_CODE, "org.camunda.bpm.identity.impl.ldap", "00");
+
+ public void pluginActivated(String pluginClassName, String engineName) {
+ logInfo("001", "PLUGIN {} activated on process engine {}", pluginClassName, engineName);
+ }
+
+ public void acceptingUntrustedCertificates() {
+ logWarn("002", "Enabling accept of untrusted certificates. Use at own risk.");
+ }
+
+ public void exceptionWhenClosingLdapContext(Exception e) {
+ logDebug("003", "exception while closing LDAP DIR CTX", e);
+ }
+
+ public void invalidLdapEntityReturned(E entity, SearchResult searchResult) {
+ String entityType = entity instanceof UserEntity ? "user" : "group";
+ logError("004", "LDAP {} query returned a {} with id null. This {} will be ignored. "
+ + "This indicates a misconfiguration of the LDAP plugin or a problem with the LDAP service."
+ + " Enable DEBUG/FINE logging for details.", entityType, entityType, entityType);
+ // log sensitive data only on FINE
+ logDebug("004", "Invalid {}: {} based on search result {}", entityType, entity, searchResult);
+ }
+
+ public void queryResult(String summary) {
+ // log sensitive data only on FINE
+ logDebug("005", summary);
+ }
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapDisableAuthorizationCheckTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapDisableAuthorizationCheckTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..16c0a94c0499adcea1033a582c904c688484621b
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapDisableAuthorizationCheckTest.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.camunda.bpm.engine.authorization.Authorization.AUTH_TYPE_GRANT;
+import static org.camunda.bpm.engine.authorization.Permissions.READ;
+import static org.camunda.bpm.engine.authorization.Resources.GROUP;
+import static org.camunda.bpm.engine.authorization.Resources.USER;
+import static org.camunda.bpm.identity.ldap.util.LdapTestUtilities.testGroupPaging;
+import static org.camunda.bpm.identity.ldap.util.LdapTestUtilities.testUserPaging;
+
+import org.camunda.bpm.engine.AuthorizationService;
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.ProcessEngineConfiguration;
+import org.camunda.bpm.engine.authorization.Authorization;
+import org.camunda.bpm.engine.authorization.Permission;
+import org.camunda.bpm.engine.authorization.Resource;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironment;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestUtilities;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * @author Roman Smirnov
+ *
+ */
+public class LdapDisableAuthorizationCheckTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule("camunda.ldap.disable.authorization.check.cfg.xml");
+
+ ProcessEngineConfiguration processEngineConfiguration;
+ IdentityService identityService;
+ AuthorizationService authorizationService;
+ LdapTestEnvironment ldapTestEnvironment;
+
+ @Before
+ public void setup() {
+ processEngineConfiguration = engineRule.getProcessEngineConfiguration();
+ identityService = engineRule.getIdentityService();
+ authorizationService = engineRule.getAuthorizationService();
+ ldapTestEnvironment = ldapRule.getLdapTestEnvironment();
+ }
+
+ @Test
+ public void testUserQueryPagination() {
+ LdapTestUtilities.testUserPaging(identityService, ldapTestEnvironment);
+ }
+
+ @Test
+ public void testUserQueryPaginationWithAuthenticatedUserWithoutAuthorizations() {
+ try {
+ processEngineConfiguration.setAuthorizationEnabled(true);
+
+ identityService.setAuthenticatedUserId("oscar");
+ testUserPaging(identityService, ldapTestEnvironment);
+
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+ }
+ }
+
+ @Test
+ public void testUserQueryPaginationWithAuthenticatedUserWithAuthorizations() {
+ createGrantAuthorization(USER, "roman", "oscar", READ);
+ createGrantAuthorization(USER, "daniel", "oscar", READ);
+ createGrantAuthorization(USER, "monster", "oscar", READ);
+ createGrantAuthorization(USER, "ruecker", "oscar", READ);
+
+ try {
+ processEngineConfiguration.setAuthorizationEnabled(true);
+
+ identityService.setAuthenticatedUserId("oscar");
+ testUserPaging(identityService, ldapTestEnvironment);
+
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+
+ for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
+ authorizationService.deleteAuthorization(authorization.getId());
+ }
+
+ }
+ }
+
+ @Test
+ public void testGroupQueryPagination() {
+ testGroupPaging(identityService);
+ }
+
+ @Test
+ public void testGroupQueryPaginationWithAuthenticatedUserWithoutAuthorizations() {
+ try {
+ processEngineConfiguration.setAuthorizationEnabled(true);
+
+ identityService.setAuthenticatedUserId("oscar");
+ testGroupPaging(identityService);
+
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+ }
+ }
+
+ @Test
+ public void testGroupQueryPaginationWithAuthenticatedUserWithAuthorizations() {
+ createGrantAuthorization(GROUP, "management", "oscar", READ);
+ createGrantAuthorization(GROUP, "consulting", "oscar", READ);
+ createGrantAuthorization(GROUP, "external", "oscar", READ);
+
+ try {
+ processEngineConfiguration.setAuthorizationEnabled(true);
+
+ identityService.setAuthenticatedUserId("oscar");
+ testGroupPaging(identityService);
+
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+
+ for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
+ authorizationService.deleteAuthorization(authorization.getId());
+ }
+
+ }
+ }
+
+ protected void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
+ Authorization authorization = createAuthorization(AUTH_TYPE_GRANT, resource, resourceId);
+ authorization.setUserId(userId);
+ for (Permission permission : permissions) {
+ authorization.addPermission(permission);
+ }
+ authorizationService.saveAuthorization(authorization);
+ }
+
+ protected Authorization createAuthorization(int type, Resource resource, String resourceId) {
+ Authorization authorization = authorizationService.createNewAuthorization(type);
+
+ authorization.setResource(resource);
+ if (resourceId != null) {
+ authorization.setResourceId(resourceId);
+ }
+
+ return authorization;
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapEnableSortControlSupportTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapEnableSortControlSupportTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f72b43ed7b59e1ffbf2cc4131e62a6a779acdabc
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapEnableSortControlSupportTest.java
@@ -0,0 +1,273 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.identity.Group;
+import org.camunda.bpm.engine.identity.User;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironment;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Represents a test case where the sortControlSupport property is enabled.
+ *
+ * @author Christopher Zell
+ */
+public class LdapEnableSortControlSupportTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule("camunda.ldap.enable.sort.control.support.cfg.xml");
+
+ IdentityService identityService;
+ LdapTestEnvironment ldapTestEnvironment;
+
+ @Before
+ public void setup() {
+ identityService = engineRule.getIdentityService();
+ ldapTestEnvironment = ldapRule.getLdapTestEnvironment();
+ }
+
+ /**
+ * FirstName
+ */
+ @Test
+ public void testOrderByUserFirstNameAsc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserFirstName().asc().list();
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getFirstName))
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getId()).isEqualTo(manualOrderedUsers.get(i).getId());
+ }
+ }
+
+ @Test
+ public void testOrderByUserFirstNameDesc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserFirstName().desc().list();
+
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getFirstName).reversed())
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getId()).isEqualTo(manualOrderedUsers.get(i).getId());
+ }
+ }
+
+ /**
+ * LastName
+ */
+ @Test
+ public void testOrderByUserLastNameAsc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserLastName().asc().list();
+
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getLastName))
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getLastName()).isEqualTo(manualOrderedUsers.get(i).getLastName());
+ }
+ }
+
+ @Test
+ public void testOrderByUserLastNameDesc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserLastName().desc().list();
+
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getLastName).reversed())
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getLastName()).isEqualTo(manualOrderedUsers.get(i).getLastName());
+ }
+ }
+
+ /**
+ * EMAIL
+ */
+ @Test
+ public void testOrderByUserEmailAsc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserEmail().asc().list();
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getEmail))
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getId()).isEqualTo(manualOrderedUsers.get(i).getId());
+ }
+ }
+
+ @Test
+ public void testOrderByUserEmailDesc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserEmail().desc().list();
+
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getEmail).reversed())
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getId()).isEqualTo(manualOrderedUsers.get(i).getId());
+ }
+ }
+
+ /**
+ * ID
+ */
+ @Test
+ public void testOrderByUserIdAsc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserId().asc().list();
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getId))
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getId()).isEqualTo(manualOrderedUsers.get(i).getId());
+ }
+ }
+
+ @Test
+ public void testOrderByUserIdDesc() {
+ List orderedUsers = identityService.createUserQuery().orderByUserId().desc().list();
+
+ List manualOrderedUsers = identityService.createUserQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(User::getId).reversed())
+ .collect(Collectors.toList());
+
+ assertThat(orderedUsers.size()).isEqualTo(manualOrderedUsers.size());
+
+ for (int i = 0; i < orderedUsers.size(); i++) {
+ assertThat(orderedUsers.get(i).getId()).isEqualTo(manualOrderedUsers.get(i).getId());
+ }
+ }
+
+ /**
+ * Group ID Ordering
+ */
+ @Test
+ public void testOrderByGroupIdAsc() {
+ List orderedGroup = identityService.createGroupQuery().orderByGroupId().asc().list();
+ List manualOrderedGroups = identityService.createGroupQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(Group::getId))
+ .collect(Collectors.toList());
+
+ assertThat(orderedGroup.size()).isEqualTo(manualOrderedGroups.size());
+
+ for (int i = 0; i < orderedGroup.size(); i++) {
+ assertThat(orderedGroup.get(i).getId()).isEqualTo(manualOrderedGroups.get(i).getId());
+ }
+ }
+
+ @Test
+ public void testOrderByGroupIdDesc() {
+ List orderedGroup = identityService.createGroupQuery().orderByGroupId().desc().list();
+ List manualOrderedGroups = identityService.createGroupQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(Group::getId).reversed())
+ .collect(Collectors.toList());
+
+ assertThat(orderedGroup.size()).isEqualTo(manualOrderedGroups.size());
+
+ for (int i = 0; i < orderedGroup.size(); i++) {
+ assertThat(orderedGroup.get(i).getId()).isEqualTo(manualOrderedGroups.get(i).getId());
+ }
+ }
+
+ /**
+ * Group Name Ordering
+ */
+ @Test
+ public void testOrderByGroupNameAsc() {
+ List orderedGroup = identityService.createGroupQuery().orderByGroupName().asc().list();
+ List manualOrderedGroups = identityService.createGroupQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(Group::getName))
+ .collect(Collectors.toList());
+
+ assertThat(orderedGroup.size()).isEqualTo(manualOrderedGroups.size());
+
+ for (int i = 0; i < orderedGroup.size(); i++) {
+ assertThat(orderedGroup.get(i).getId()).isEqualTo(manualOrderedGroups.get(i).getId());
+ }
+ }
+
+ @Test
+ public void testOrderByGroupNameDesc() {
+ List orderedGroup = identityService.createGroupQuery().orderByGroupName().desc().list();
+ List manualOrderedGroups = identityService.createGroupQuery()
+ .list()
+ .stream()
+ .sorted(Comparator.comparing(Group::getName).reversed())
+ .collect(Collectors.toList());
+
+ assertThat(orderedGroup.size()).isEqualTo(manualOrderedGroups.size());
+
+ for (int i = 0; i < orderedGroup.size(); i++) {
+ assertThat(orderedGroup.get(i).getId()).isEqualTo(manualOrderedGroups.get(i).getId());
+ }
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapGroupLargeQueryTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapGroupLargeQueryTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..c423d7eceba12622c5a55b0f1f07d8be101a732a
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapGroupLargeQueryTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.identity.Group;
+import org.camunda.bpm.engine.identity.GroupQuery;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironment;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class LdapGroupLargeQueryTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule().additionalNumberOfUsers(5).additionnalNumberOfGroups(5).additionalNumberOfRoles(80); // the TestEnvironment creates groups for roles. Attention, stay under 80, there is a limitation in the query on 100
+
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule("camunda.ldap.pages.cfg.xml"); // pageSize = 3 in this configuration
+
+ IdentityService identityService;
+ LdapTestEnvironment ldapTestEnvironment;
+
+ @Before
+ public void setup() {
+ identityService = engineRule.getIdentityService();
+ ldapTestEnvironment = ldapRule.getLdapTestEnvironment();
+ }
+
+ @Test
+ public void testAllGroupsQuery() {
+ List listGroups = identityService.createGroupQuery().list();
+
+ // In this group, we expect more than a page size
+ // Attention, in the test environment, a Role is implemented by a groupOfNames. the groupQuery search for groups
+ // So the comparison must be done via the Roles name
+ assertThat(listGroups).hasSize(ldapTestEnvironment.getTotalNumberOfRolesCreated());
+ }
+
+ @Test
+ public void testPagesAllGroupsQuery() {
+ List listGroups = identityService.createGroupQuery().list();
+
+ assertThat(listGroups).hasSize(ldapTestEnvironment.getTotalNumberOfRolesCreated());
+
+ // ask 3 pages
+ for (int firstResult = 2; firstResult < 10; firstResult += 4) {
+ List listPages = identityService.createGroupQuery().listPage(firstResult, 5);
+ assertThat(listPages.size()).as("Maximum 5 results expected").isLessThanOrEqualTo(5);
+
+ for (int i = 0; i < listPages.size(); i++) {
+ assertThat(listPages.get(i).getId()).isEqualTo(listGroups.get(firstResult + i).getId());
+ assertThat(listPages.get(i).getName()).isEqualTo(listGroups.get(firstResult + i).getName());
+ }
+
+ }
+ }
+
+ @Test
+ public void testQueryPaging() {
+ GroupQuery query = identityService.createGroupQuery();
+
+ assertThat(query.listPage(0, Integer.MAX_VALUE)).hasSize(86);
+
+ // Verifying the un-paged results
+ assertThat(query.count()).isEqualTo(86);
+ assertThat(query.list()).hasSize(86);
+
+ // Verifying paged results
+ assertThat(query.listPage(0, 2)).hasSize(2);
+ assertThat(query.listPage(2, 2)).hasSize(2);
+ assertThat(query.listPage(4, 3)).hasSize(3);
+ assertThat(query.listPage(85, 3)).hasSize(1);
+ assertThat(query.listPage(85, 1)).hasSize(1);
+
+ // Verifying odd usages
+ assertThat(query.listPage(-1, -1)).hasSize(0);
+ assertThat(query.listPage(86, 2)).hasSize(0); // 86 is the last index with a result
+ assertThat(query.listPage(0, 87)).hasSize(86); // there are only 86 groups
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapGroupQueryTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapGroupQueryTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..026b033ecfd08b37652cb0e18602b5e28290a985
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapGroupQueryTest.java
@@ -0,0 +1,361 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.camunda.bpm.engine.authorization.Authorization.AUTH_TYPE_GRANT;
+import static org.camunda.bpm.engine.authorization.Permissions.READ;
+import static org.camunda.bpm.engine.authorization.Resources.GROUP;
+import static org.camunda.bpm.identity.ldap.util.LdapTestUtilities.checkPagingResults;
+import static org.camunda.bpm.identity.ldap.util.LdapTestUtilities.testGroupPaging;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.camunda.bpm.engine.AuthorizationService;
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.ProcessEngineConfiguration;
+import org.camunda.bpm.engine.authorization.Authorization;
+import org.camunda.bpm.engine.authorization.Permission;
+import org.camunda.bpm.engine.authorization.Resource;
+import org.camunda.bpm.engine.identity.Group;
+import org.camunda.bpm.engine.identity.GroupQuery;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironment;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+
+public class LdapGroupQueryTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule();
+
+ ProcessEngineConfiguration processEngineConfiguration;
+ IdentityService identityService;
+ AuthorizationService authorizationService;
+ LdapTestEnvironment ldapTestEnvironment;
+
+ @Before
+ public void setup() {
+ processEngineConfiguration = engineRule.getProcessEngineConfiguration();
+ identityService = engineRule.getIdentityService();
+ authorizationService = engineRule.getAuthorizationService();
+ ldapTestEnvironment = ldapRule.getLdapTestEnvironment();
+ }
+
+ @Test
+ public void testCountGroups() {
+ // given
+
+ // when
+ GroupQuery groupQuery = identityService.createGroupQuery();
+
+ // then
+ assertThat(groupQuery.listPage(0, Integer.MAX_VALUE).size()).isEqualTo(6);
+ assertThat(groupQuery.count()).isEqualTo(6);
+ }
+
+ @Test
+ public void testQueryNoFilter() {
+ // given
+
+ // when
+ List groupList = identityService.createGroupQuery().list();
+
+ // then
+ assertThat(groupList.size()).isEqualTo(6);
+ }
+
+ @Test
+ public void testFilterByGroupId() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupId("management").singleResult();
+
+ // then
+ assertThat(group).isNotNull();
+ // validate result
+ assertThat(group.getId()).isEqualTo("management");
+ assertThat(group.getName()).isEqualTo("management");
+ }
+
+ @Test
+ public void testFilterByNonexistingGroupId() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupId("whatever").singleResult();
+
+ // then
+ assertThat(group).isNull();
+ }
+
+ @Test
+ public void testFilterByGroupIdIn() {
+ // given
+
+ // when
+ List groups = identityService.createGroupQuery().groupIdIn("external", "management").list();
+
+ // then
+ assertThat(groups.size()).isEqualTo(2);
+ assertThat(groups).extracting("id").containsOnly("external", "management");
+ }
+
+ @Test
+ public void testFilterByGroupName() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupName("management").singleResult();
+
+ // then
+ assertThat(group).isNotNull();
+ // validate result
+ assertThat(group.getId()).isEqualTo("management");
+ assertThat(group.getName()).isEqualTo("management");
+ }
+
+ @Test
+ public void testFilterByNonexistingGroupName() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupName("whatever").singleResult();
+
+ // then
+ assertThat(group).isNull();
+ }
+
+ @Test
+ public void testFilterByGroupNameLikeTrailingWildcard() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupNameLike("manage*").singleResult();
+
+ // then
+ assertThat(group).isNotNull();
+ assertThat(group.getId()).isEqualTo("management");
+ assertThat(group.getName()).isEqualTo("management");
+ }
+
+ @Test
+ public void testFilterByGroupNameLikeLeadingWildcard() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupNameLike("*agement").singleResult();
+
+ // then
+ assertThat(group).isNotNull();
+ assertThat(group.getId()).isEqualTo("management");
+ assertThat(group.getName()).isEqualTo("management");
+ }
+
+ @Test
+ public void testFilterByGroupNameLikeLeadingAndTrailingWildCard() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupNameLike("*ageme*").singleResult();
+
+ // then
+ assertThat(group).isNotNull();
+ assertThat(group.getId()).isEqualTo("management");
+ assertThat(group.getName()).isEqualTo("management");
+ }
+
+ @Test
+ public void testFilterByGroupNameLikeMIddleWildCard() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupNameLike("man*nt").singleResult();
+
+ // then
+ assertThat(group).isNotNull();
+ assertThat(group.getId()).isEqualTo("management");
+ assertThat(group.getName()).isEqualTo("management");
+ }
+
+ @Test
+ public void testFilterByNonexistingGroupNameLike() {
+ // given
+
+ // when
+ Group group = identityService.createGroupQuery().groupNameLike("what*").singleResult();
+
+ // then
+ assertThat(group).isNull();
+ }
+
+ @Test
+ public void testFilterByGroupNameLikeConvertFromDbWildcard() {
+ // given
+
+ // when using the SQL wildcard (%) instead of LDAP (*)
+ Group group = identityService.createGroupQuery().groupNameLike("manage%").singleResult();
+
+ // then
+ assertThat(group).isNotNull();
+ assertThat(group.getId()).isEqualTo("management");
+ assertThat(group.getName()).isEqualTo("management");
+ }
+
+ @Test
+ public void testFilterByGroupMember() {
+ // given
+
+ // when
+ List list = identityService.createGroupQuery().groupMember("daniel").list();
+
+ // then
+ assertThat(list).hasSize(3);
+ assertThat(list).extracting("name").containsOnly("development", "management", "all");
+ }
+
+ @Test
+ public void testFilterByNonexistingGroupMember() {
+ // given
+
+ // when
+ List list = identityService.createGroupQuery().groupMember("non-existing").list();
+
+ // then
+ assertThat(list).isEmpty();
+ }
+
+ @Test
+ public void testFilterByGroupMemberSpecialCharacter() {
+ // given
+
+ // when
+ List list = identityService.createGroupQuery().groupMember("david(IT)").list();
+
+ // then
+ assertThat(list).hasSize(2);
+ assertThat(list).extracting("name").containsOnly("sales", "all");
+ }
+
+ @Test
+ public void testFilterByGroupMemberPosix() {
+ // given
+ // by default the configuration does not use posix groups
+ LdapConfiguration ldapConfiguration = new LdapConfiguration();
+ ldapConfiguration.setGroupMemberAttribute("memberUid");
+ ldapConfiguration.setGroupSearchFilter("(someFilter)");
+
+ LdapIdentityProviderSession session = new LdapIdentityProviderSession(ldapConfiguration) {
+ // mock getDnForUser
+ protected String getDnForUser(String userId) {
+ return userId+ ", fullDn";
+ }
+ };
+
+ // when I query for groups by group member
+ LdapGroupQuery query = new LdapGroupQuery();
+ query.groupMember("jonny");
+
+ // then the full DN is requested. This is the default behavior.
+ String filter = session.getGroupSearchFilter(query);
+ assertThat(filter).isEqualTo("(&(someFilter)(memberUid=jonny, fullDn))");
+
+ // If I turn on posix groups
+ ldapConfiguration.setUsePosixGroups(true);
+
+ // then the filter string does not contain the full DN for the
+ // user but the simple (unqualified) userId as provided in the query
+ filter = session.getGroupSearchFilter(query);
+ assertThat(filter).isEqualTo("(&(someFilter)(memberUid=jonny))");
+ }
+
+
+ @Test
+ public void testPagination() {
+ testGroupPaging(identityService);
+ }
+
+ @Test
+ public void testPaginationWithAuthenticatedUser() {
+ createGrantAuthorization(GROUP, "management", "oscar", READ);
+ createGrantAuthorization(GROUP, "consulting", "oscar", READ);
+ createGrantAuthorization(GROUP, "external", "oscar", READ);
+
+ try {
+ processEngineConfiguration.setAuthorizationEnabled(true);
+
+ identityService.setAuthenticatedUserId("oscar");
+
+ Set groupNames = new HashSet<>();
+ List groups = identityService.createGroupQuery().listPage(0, 2);
+ assertThat(groups).hasSize(2);
+ checkPagingResults(groupNames, groups.get(0).getId(), groups.get(1).getId());
+
+ groups = identityService.createGroupQuery().listPage(2, 2);
+ assertThat(groups).hasSize(1);
+ assertThat(groupNames).doesNotContain(groups.get(0).getId());
+ groupNames.add(groups.get(0).getId());
+
+ groups = identityService.createGroupQuery().listPage(4, 2);
+ assertThat(groups).hasSize(0);
+
+ identityService.setAuthenticatedUserId("daniel");
+
+ groups = identityService.createGroupQuery().listPage(0, 2);
+ assertThat(groups).hasSize(0);
+
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+
+ for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
+ authorizationService.deleteAuthorization(authorization.getId());
+ }
+
+ }
+ }
+
+ protected void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
+ Authorization authorization = createAuthorization(AUTH_TYPE_GRANT, resource, resourceId);
+ authorization.setUserId(userId);
+ for (Permission permission : permissions) {
+ authorization.addPermission(permission);
+ }
+ authorizationService.saveAuthorization(authorization);
+ }
+
+ protected Authorization createAuthorization(int type, Resource resource, String resourceId) {
+ Authorization authorization = authorizationService.createNewAuthorization(type);
+
+ authorization.setResource(resource);
+ if (resourceId != null) {
+ authorization.setResourceId(resourceId);
+ }
+
+ return authorization;
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapLoginCatchAuthenticationExceptionTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapLoginCatchAuthenticationExceptionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5583eb4dd68b9d1cbb9a22fda5d87b056e67b58c
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapLoginCatchAuthenticationExceptionTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class LdapLoginCatchAuthenticationExceptionTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule("camunda.ldap.disable.catch.authentication.exception.cfg.xml");
+
+ IdentityService identityService;
+
+ @Before
+ public void setup() {
+ identityService = engineRule.getIdentityService();
+ }
+
+ @Test
+ public void shouldThrowExceptionOnFailedLogin() {
+ // given config passwordCheckCatchAuthenticationException=false
+
+ // when
+ assertThatThrownBy(() -> identityService.checkPassword("roman", "wrongPW"))
+ .isInstanceOf(LdapAuthenticationException.class)
+ .hasMessage("Could not authenticate with LDAP server");
+ }
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapLoginTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapLoginTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..dd453d0e2a74201fa65a80eec3a8e0fb6563299d
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapLoginTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * @author Daniel Meyer
+ *
+ */
+public class LdapLoginTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule();
+
+ IdentityService identityService;
+
+ @Before
+ public void setup() {
+ identityService = engineRule.getIdentityService();
+ }
+
+ @Test
+ public void testLdapLoginSuccess() {
+ assertThat(identityService.checkPassword("roman", "roman")).isTrue();
+ }
+
+ @Test
+ public void testLdapLoginCapitalization() {
+ assertThat(identityService.checkPassword("Roman", "roman")).isTrue();
+ }
+
+ @Test
+ public void testLdapLoginFailure() {
+ assertThat(identityService.checkPassword("roman", "ro")).isFalse();
+ assertThat(identityService.checkPassword("r", "roman")).isFalse();
+ }
+
+ @Test
+ public void testLdapLoginNullValues() {
+ assertThat(identityService.checkPassword(null, "roman")).isFalse();
+ assertThat(identityService.checkPassword("roman", null)).isFalse();
+ assertThat(identityService.checkPassword(null, null)).isFalse();
+ }
+
+ @Test
+ public void testLdapLoginEmptyPassword() {
+ assertThat(identityService.checkPassword("roman", "")).isTrue();
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapQueryToleranceTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapQueryToleranceTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..ff30deb8955b85df623bd9ac7ae7d89c54f0958a
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapQueryToleranceTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import org.camunda.bpm.engine.ProcessEngine;
+import org.camunda.bpm.engine.identity.Group;
+import org.camunda.bpm.engine.identity.User;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironment;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.camunda.commons.testing.ProcessEngineLoggingRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+
+
+/**
+ * @author Thorben Lindhauer
+ *
+ */
+public class LdapQueryToleranceTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule("invalid-id-attributes.cfg.xml");
+ @Rule
+ public ProcessEngineLoggingRule loggingRule = new ProcessEngineLoggingRule().level(Level.ERROR).watch("org.camunda.bpm.identity.impl.ldap");
+
+ ProcessEngine processEngine;
+ LdapTestEnvironment ldapTestEnvironment;
+
+ @Before
+ public void setup() {
+ processEngine = engineRule.getProcessEngine();
+ ldapTestEnvironment = ldapRule.getLdapTestEnvironment();
+ }
+
+ @Test
+ public void testNotReturnGroupsWithNullId() {
+ // given
+ // LdapTestEnvironment creates six roles (groupOfNames) by default;
+ // these won't return a group id, because they do not have the group id attribute
+ // defined in the ldap plugin config
+ // the plugin should not return such groups and instead log an error
+
+ // when
+ List groups = processEngine.getIdentityService().createGroupQuery().list();
+ long count = processEngine.getIdentityService().createGroupQuery().count();
+
+ // then
+ // groups with id null were not returned
+ assertThat(groups).hasSize(0);
+ assertThat(count).isEqualTo(0);
+ List filteredLog = loggingRule.getFilteredLog("LDAP-00004 LDAP group query returned a group with id null.");
+ assertThat(filteredLog).hasSize(12); // 2 queries * 6 roles (groupOfNames)
+ }
+
+ @Test
+ public void testNotReturnUsersWithNullId() {
+ // given
+ // LdapTestEnvironment creates 12 users by default;
+ // these won't return a group id, because they do not have the group id attribute
+ // defined in the ldap plugin config
+ // the plugin should not return such groups and instead log an error
+
+ // when
+ List users = processEngine.getIdentityService().createUserQuery().list();
+ long count = processEngine.getIdentityService().createUserQuery().count();
+
+ // then
+ // groups with id null were not returned
+ assertThat(users).hasSize(0);
+ assertThat(count).isEqualTo(0);
+ List filteredLog = loggingRule.getFilteredLog("LDAP-00004 LDAP user query returned a user with id null.");
+ assertThat(filteredLog).hasSize(24); // 2 queries * 12 users
+ }
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapUserLargeQueryTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapUserLargeQueryTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..b83bd9c5c9fdee58109fd668f909cc9081e0457d
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapUserLargeQueryTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.ProcessEngineConfiguration;
+import org.camunda.bpm.engine.identity.User;
+import org.camunda.bpm.engine.identity.UserQuery;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironment;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class LdapUserLargeQueryTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule().additionalNumberOfUsers(80).additionnalNumberOfGroups(5).additionalNumberOfRoles(5); // Attention, stay under 80, there is a limitation in the query on 100
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule("camunda.ldap.pages.cfg.xml"); // pageSize = 3 in this configuration
+
+ ProcessEngineConfiguration processEngineConfiguration;
+ IdentityService identityService;
+ LdapTestEnvironment ldapTestEnvironment;
+
+ @Before
+ public void setup() {
+ processEngineConfiguration = engineRule.getProcessEngineConfiguration();
+ identityService = engineRule.getIdentityService();
+ ldapTestEnvironment = ldapRule.getLdapTestEnvironment();
+ }
+
+ @Test
+ public void testAllUsersQuery() {
+ List listUsers = identityService.createUserQuery().list();
+
+ // In this group, we expect more than a page size
+ assertThat(listUsers).hasSize(ldapTestEnvironment.getTotalNumberOfUsersCreated());
+ }
+
+ @Test
+ public void testPagesAllUsersQuery() {
+ List listUsers = identityService.createUserQuery().list();
+
+ assertThat(listUsers).hasSize(ldapTestEnvironment.getTotalNumberOfUsersCreated());
+
+ // ask 3 pages
+ for (int firstResult = 0; firstResult < 10; firstResult += 4) {
+ List listPages = identityService.createUserQuery().listPage(firstResult, 5);
+ for (int i = 0; i < listPages.size(); i++) {
+ assertThat(listPages.get(i).getId()).isEqualTo(listUsers.get(firstResult + i).getId());
+ assertThat(listPages.get(i).getLastName()).isEqualTo(listUsers.get(firstResult + i).getLastName());
+ }
+
+ }
+ }
+
+ @Test
+ public void testQueryPaging() {
+ UserQuery query = identityService.createUserQuery();
+
+ assertThat(query.listPage(0, Integer.MAX_VALUE)).hasSize(92);
+
+ // Verifying the un-paged results
+ assertThat(query.count()).isEqualTo(92);
+ assertThat(query.list()).hasSize(92);
+
+ // Verifying paged results
+ assertThat(query.listPage(0, 2)).hasSize(2);
+ assertThat(query.listPage(2, 2)).hasSize(2);
+ assertThat(query.listPage(4, 3)).hasSize(3);
+ assertThat(query.listPage(91, 3)).hasSize(1);
+ assertThat(query.listPage(91, 1)).hasSize(1);
+
+ // Verifying odd usages
+ assertThat(query.listPage(-1, -1)).hasSize(0);
+ assertThat(query.listPage(92, 2)).hasSize(0); // 92 is the last index with a result
+ assertThat(query.listPage(0, 93)).hasSize(92); // there are only 92 groups
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapUserQueryTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapUserQueryTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..45716b5437838ee0598170bd30040a3c8cc8cafc
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/LdapUserQueryTest.java
@@ -0,0 +1,674 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.camunda.bpm.engine.authorization.Authorization.AUTH_TYPE_GRANT;
+import static org.camunda.bpm.engine.authorization.Permissions.READ;
+import static org.camunda.bpm.engine.authorization.Resources.USER;
+import static org.camunda.bpm.identity.ldap.util.LdapTestUtilities.checkPagingResults;
+import static org.camunda.bpm.identity.ldap.util.LdapTestUtilities.testUserPaging;
+import static org.camunda.bpm.identity.ldap.util.LdapTestUtilities.testUserPagingWithMemberOfGroup;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.camunda.bpm.engine.AuthorizationService;
+import org.camunda.bpm.engine.BadUserRequestException;
+import org.camunda.bpm.engine.IdentityService;
+import org.camunda.bpm.engine.ProcessEngineConfiguration;
+import org.camunda.bpm.engine.authorization.Authorization;
+import org.camunda.bpm.engine.authorization.Permission;
+import org.camunda.bpm.engine.authorization.Resource;
+import org.camunda.bpm.engine.identity.User;
+import org.camunda.bpm.engine.identity.UserQuery;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironment;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class LdapUserQueryTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule();
+
+ ProcessEngineConfiguration processEngineConfiguration;
+ IdentityService identityService;
+ AuthorizationService authorizationService;
+ LdapTestEnvironment ldapTestEnvironment;
+
+ @Before
+ public void setup() {
+ processEngineConfiguration = engineRule.getProcessEngineConfiguration();
+ identityService = engineRule.getIdentityService();
+ authorizationService = engineRule.getAuthorizationService();
+ ldapTestEnvironment = ldapRule.getLdapTestEnvironment();
+ }
+
+ @Test
+ public void testCountUsers() {
+ // given
+
+ // when
+ UserQuery userQuery = identityService.createUserQuery();
+
+ // then
+ assertThat(userQuery.listPage(0, Integer.MAX_VALUE)).hasSize(12);
+ assertThat(userQuery.count()).isEqualTo(12);
+ }
+
+ @Test
+ public void testQueryNoFilter() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery().list();
+
+ // then
+ assertThat(result).hasSize(ldapTestEnvironment.getTotalNumberOfUsersCreated());
+ }
+
+ @Test
+ public void testFilterByUserId() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userId("oscar").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+
+ // validate user
+ assertThat(user.getId()).isEqualTo("oscar");
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByNonexistentUserId() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userId("non-existing").singleResult();
+
+ // then
+ assertThat(user).isNull();
+ }
+
+ @Test
+ public void testFilterByUserIdIn() {
+ // given
+
+ // when
+ List users = identityService.createUserQuery().userIdIn("oscar", "monster").list();
+
+ // then
+ assertThat(users).hasSize(2);
+ assertThat(users).extracting("id").containsOnly("oscar", "monster");
+ }
+
+ @Test
+ public void testFilterByNonExistingUserIdIn() {
+ // given
+
+ // when
+ List users = identityService.createUserQuery().userIdIn("oscar", "monster", "daniel", "non-existing").list();
+
+ // then
+ assertThat(users).isNotNull();
+ assertThat(users).hasSize(3);
+ assertThat(users).extracting("id").containsOnly("oscar", "monster", "daniel");
+ }
+
+ @Test
+ public void testFilterByUserIdWithCapitalization() {
+ try {
+ // given
+ processEngineConfiguration.setAuthorizationEnabled(true);
+ identityService.setAuthenticatedUserId("Oscar");
+
+ // when
+ User user = identityService.createUserQuery().userId("Oscar").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+
+ // validate user
+ assertThat(user.getId()).isEqualTo("oscar");
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+ }
+ }
+
+ @Test
+ public void testFilterByFirstname() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userFirstName("Oscar").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ }
+
+ @Test
+ public void testFilterByNonexistingFirstname() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userFirstName("non-existing").singleResult();
+
+ // then
+ assertThat(user).isNull();
+ }
+
+ @Test
+ public void testFilterByFirstnameLikeTrailingWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userFirstNameLike("Osc*").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ }
+
+ @Test
+ public void testFilterByFirstnameLikeLeadingWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userFirstNameLike("*car").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ }
+
+ @Test
+ public void testFilterByFirstnameLikeLeadingAndTrailingWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userFirstNameLike("*sca*").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ }
+
+ @Test
+ public void testFilterByFirstnameLikeMiddleWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userFirstNameLike("O*ar").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ }
+
+ @Test
+ public void testFilterByFirstnameLikeConvertFromDbWildcard() {
+ // given
+
+ // when using the SQL wildcard (%) instead of LDAP (*)
+ User user = identityService.createUserQuery().userFirstNameLike("Osc%").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getFirstName()).isEqualTo("Oscar");
+ }
+
+ @Test
+ public void testFilterByNonexistingFirstnameLike() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userFirstNameLike("non-exist*").singleResult();
+
+ // then
+ assertThat(user).isNull();
+ }
+
+ @Test
+ public void testFilterByLastname() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userLastName("The Crouch").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ }
+
+ @Test
+ public void testFilterByNonexistingLastname() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userLastName("non-existing").singleResult();
+
+ // then
+ assertThat(user).isNull();
+ }
+
+ @Test
+ public void testFilterByLastnameLikeTrailingWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userLastNameLike("The Cro*").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ }
+
+ @Test
+ public void testFilterByLastnameLikeLeadingWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userLastNameLike("* Crouch").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ }
+
+ @Test
+ public void testFilterByLastnameLikeLeadingAndTrailingWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userLastNameLike("* Cro*").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ }
+
+ @Test
+ public void testFilterByLastnameLikeMiddleWildcard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userLastNameLike("The *uch").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ }
+
+ @Test
+ public void testFilterByNonexistingLastnameLike() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userLastNameLike("non-exist*").singleResult();
+
+ // then
+ assertThat(user).isNull();
+ }
+
+ @Test
+ public void testFilterByLastnameLikeConvertFromDbWildcard() {
+ // given
+
+ // when using the SQL wildcard (%) instead of LDAP (*)
+ User user = identityService.createUserQuery().userLastNameLike("The Cro%").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getLastName()).isEqualTo("The Crouch");
+ }
+
+ @Test
+ public void testFilterByEmail() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userEmail("oscar@camunda.org").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByNonexistingEmail() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userEmail("non-exist").singleResult();
+
+ // then
+ assertThat(user).isNull();
+ }
+
+ @Test
+ public void testFilterByEmailLikeTrailingWildCard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userEmailLike("oscar@*").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByEmailLikeLeadingWildCard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userEmailLike("*car@camunda.org").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByEmailLikeLeadingAndTrailingWildCard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userEmailLike("*car@*").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByEmailLikeMiddleWildCard() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userEmailLike("oscar@*.org").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByNonexistingEmailLike() {
+ // given
+
+ // when
+ User user = identityService.createUserQuery().userEmailLike("non-exist*").singleResult();
+
+ // then
+ assertThat(user).isNull();
+ }
+
+ @Test
+ public void testFilterByEmailLikeConvertFromDbWildcard() {
+ // given
+
+ // when using the SQL wildcard (%) instead of LDAP (*)
+ User user = identityService.createUserQuery().userEmailLike("oscar@%").singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByGroupId() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery().memberOfGroup("development").list();
+
+ // then
+ assertThat(result).hasSize(3);
+ assertThat(result).extracting("id").containsOnly("roman", "daniel", "oscar");
+ }
+
+ @Test
+ public void testFilterByGroupIdAndFirstname() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery()
+ .memberOfGroup("development")
+ .userFirstName("Oscar")
+ .list();
+
+ // then
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getFirstName()).isEqualTo("Oscar");
+ }
+
+ @Test
+ public void testFilterByGroupIdAndId() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery()
+ .memberOfGroup("development")
+ .userId("oscar")
+ .list();
+
+ // then
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getId()).isEqualTo("oscar");
+ }
+
+ @Test
+ public void testFilterByGroupIdAndLastname() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery()
+ .memberOfGroup("development")
+ .userLastName("The Crouch")
+ .list();
+
+ // then
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getLastName()).isEqualTo("The Crouch");
+ }
+
+ @Test
+ public void testFilterByGroupIdAndEmail() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery()
+ .memberOfGroup("development")
+ .userEmail("oscar@camunda.org")
+ .list();
+
+ // then
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getEmail()).isEqualTo("oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByGroupIdAndEmailLike() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery()
+ .memberOfGroup("development")
+ .userEmailLike("*@camunda.org")
+ .list();
+
+ // then
+ assertThat(result).hasSize(3);
+ assertThat(result).extracting("email").containsOnly("daniel@camunda.org", "roman@camunda.org", "oscar@camunda.org");
+ }
+
+ @Test
+ public void testFilterByGroupIdAndIdForDnUsingCn() {
+ // given
+
+ // when
+ List result = identityService.createUserQuery()
+ .memberOfGroup("external")
+ .userId("fozzie")
+ .list();
+
+ // then
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getId()).isEqualTo("fozzie");
+ }
+
+ @Test
+ public void testAuthenticatedUserSeesThemselve() {
+ try {
+ // given
+ processEngineConfiguration.setAuthorizationEnabled(true);
+ identityService.setAuthenticatedUserId("oscar");
+
+ // when
+ User user = identityService.createUserQuery().singleResult();
+
+ // then
+ assertThat(user).isNotNull();
+ assertThat(user.getId()).isEqualTo("oscar");
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+ }
+ }
+
+ @Test
+ public void testNonexistingAuthenticatedUserDoesNotSeeThemselve() {
+ try {
+ // given
+ processEngineConfiguration.setAuthorizationEnabled(true);
+ identityService.setAuthenticatedUserId("non-existing");
+
+ // when
+ User user = identityService.createUserQuery().singleResult();
+
+ // then
+ assertThat(user).isNull();
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+ }
+ }
+
+ @Test
+ public void testPagination() {
+ testUserPaging(identityService, ldapTestEnvironment);
+ }
+
+ @Test
+ public void testPaginationWithMemberOfGroup() {
+ testUserPagingWithMemberOfGroup(identityService);
+ }
+
+ @Test
+ public void testPaginationWithAuthenticatedUser() {
+ createGrantAuthorization(USER, "roman", "oscar", READ);
+ createGrantAuthorization(USER, "daniel", "oscar", READ);
+ createGrantAuthorization(USER, "monster", "oscar", READ);
+ createGrantAuthorization(USER, "ruecker", "oscar", READ);
+
+ try {
+ processEngineConfiguration.setAuthorizationEnabled(true);
+
+ identityService.setAuthenticatedUserId("oscar");
+
+ Set userNames = new HashSet<>();
+ List users = identityService.createUserQuery().listPage(0, 2);
+ assertThat(users).hasSize(2);
+ checkPagingResults(userNames, users.get(0).getId(), users.get(1).getId());
+
+ users = identityService.createUserQuery().listPage(2, 2);
+ assertThat(users).hasSize(2);
+ checkPagingResults(userNames, users.get(0).getId(), users.get(1).getId());
+
+ users = identityService.createUserQuery().listPage(4, 2);
+ assertThat(users).hasSize(1);
+ assertThat(userNames).doesNotContain(users.get(0).getId());
+ userNames.add(users.get(0).getId());
+
+ identityService.setAuthenticatedUserId("daniel");
+
+ users = identityService.createUserQuery().listPage(0, 2);
+ assertThat(users).hasSize(1);
+
+ assertThat(users.get(0).getId()).isEqualTo("daniel");
+
+ users = identityService.createUserQuery().listPage(2, 2);
+ assertThat(users).hasSize(0);
+
+ } finally {
+ processEngineConfiguration.setAuthorizationEnabled(false);
+ identityService.clearAuthentication();
+
+ for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
+ authorizationService.deleteAuthorization(authorization.getId());
+ }
+
+ }
+ }
+
+ @Test
+ public void testNativeQueryFail() {
+ assertThatThrownBy(() -> identityService.createNativeUserQuery())
+ .isInstanceOf(BadUserRequestException.class)
+ .hasMessageContaining("Native user queries are not supported for LDAP");
+ }
+
+ protected void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
+ Authorization authorization = createAuthorization(AUTH_TYPE_GRANT, resource, resourceId);
+ authorization.setUserId(userId);
+ for (Permission permission : permissions) {
+ authorization.addPermission(permission);
+ }
+ authorizationService.saveAuthorization(authorization);
+ }
+
+ protected Authorization createAuthorization(int type, Resource resource, String resourceId) {
+ Authorization authorization = authorizationService.createNewAuthorization(type);
+
+ authorization.setResource(resource);
+ if (resourceId != null) {
+ authorization.setResourceId(resourceId);
+ }
+
+ return authorization;
+ }
+
+}
diff --git a/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/ProcessDefinitionQueryWithCustomIdentityProviderTest.java b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/ProcessDefinitionQueryWithCustomIdentityProviderTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..72da1dce83e8aad02000365c29a44fd7291b036f
--- /dev/null
+++ b/source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/engine-plugins/identity-ldap/src/test/java/org/camunda/bpm/identity/impl/ldap/ProcessDefinitionQueryWithCustomIdentityProviderTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
+ * under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. Camunda licenses this file to you under the Apache License,
+ * Version 2.0; you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.camunda.bpm.identity.impl.ldap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+
+import org.camunda.bpm.engine.RepositoryService;
+import org.camunda.bpm.engine.repository.ProcessDefinition;
+import org.camunda.bpm.engine.test.Deployment;
+import org.camunda.bpm.engine.test.ProcessEngineRule;
+import org.camunda.bpm.identity.ldap.util.LdapTestEnvironmentRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+@Deployment
+public class ProcessDefinitionQueryWithCustomIdentityProviderTest {
+
+ @ClassRule
+ public static LdapTestEnvironmentRule ldapRule = new LdapTestEnvironmentRule();
+ @Rule
+ public ProcessEngineRule engineRule = new ProcessEngineRule();
+
+ RepositoryService repositoryService;
+
+ @Before
+ public void setup() {
+ repositoryService = engineRule.getRepositoryService();
+ }
+
+ @Test
+ public void test_shouldFindAllProcessesForCandidateUser() {
+ // given
+
+ // when
+ List processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("oscar").list();
+
+ // then
+ assertThat(processDefinitions).hasSize(2);
+ assertThat(processDefinitions.get(0).getKey()).isEqualTo("process1");
+ assertThat(processDefinitions.get(1).getKey()).isEqualTo("process2");
+ }
+
+ @Test
+ public void test_shouldFindNoProcessesForCandidateUser() {
+ // given
+
+ // when
+ List processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("pepe").list();
+ // then
+ assertThat(processDefinitions).hasSize(0);
+ }
+
+ @Test
+ public void test_shouldFindAllProcessesForUserInCandidateGroup() {
+ // given
+
+ // when
+ List processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("david(IT)").list();
+
+ // then
+ assertThat(processDefinitions).hasSize(1);
+ assertThat(processDefinitions.get(0).getKey()).isEqualTo("process3");
+ }
+
+ @Test
+ public void test_shouldFindAllProcessesForCandidateUserInCandidateGroup() {
+ // given
+
+ // when
+ List processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("monster").list();
+
+ // then
+ assertThat(processDefinitions).hasSize(2);
+ assertThat(processDefinitions.get(0).getKey()).isEqualTo("process1");
+ assertThat(processDefinitions.get(1).getKey()).isEqualTo("process3");
+ }
+
+ @Test
+ public void test_shouldFindNoDuplicateProcessesForCandidateUserInCandidateGroup() {
+ // given
+
+ // when
+ List