Skip to content

Commit 9f9aa6c

Browse files
committed
[bugfix] Fix a number of issues in the LDAP Security Realm, including previously: not being able to authenticate, not being able to retrieve a group, missing metadata attributes, and a number of issues with qualified and unqualified principal names.
Closes #141
1 parent 65101af commit 9f9aa6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4926
-683
lines changed

elemental-parent/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
<form>XML_STYLE</form>
323323
<g>SLASHSTAR_STYLE</g>
324324
<java>SLASHSTAR_STYLE</java>
325+
<ldif>SCRIPT_STYLE</ldif>
325326
<plist>XML_STYLE</plist>
326327
<types>SCRIPT_STYLE</types>
327328
<xconf>XML_STYLE</xconf>

exist-core/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@
883883
<include>src/test/java/org/exist/collections/triggers/XQueryTriggerSetUidTest.java</include>
884884
<include>src/test/java/org/exist/collections/triggers/XQueryTriggerTest.java</include>
885885
<include>src/main/java/org/exist/config/Configuration.java</include>
886+
<include>src/main/java/org/exist/config/ConfigurationDocumentTrigger.java</include>
886887
<include>src/main/java/org/exist/config/ConfigurationImpl.java</include>
887888
<include>src/main/java/org/exist/config/Configurator.java</include>
888889
<include>src/test/java/org/exist/config/TwoDatabasesTest.java</include>
@@ -1003,10 +1004,14 @@
10031004
<include>src/main/java/org/exist/repo/ExistRepository.java</include>
10041005
<include>src/main/java/org/exist/scheduler/UserXQueryJob.java</include>
10051006
<include>src/main/java/org/exist/scheduler/impl/QuartzSchedulerImpl.java</include>
1007+
<include>src/main/java/org/exist/security/AbstractRealm.java</include>
1008+
<include>src/main/java/org/exist/security/AXSchemaType.java</include>
10061009
<include>src/main/java/org/exist/security/EffectiveSubject.java</include>
1010+
<include>src/main/java/org/exist/security/EXistSchemaType.java</include>
10071011
<include>src/test/java/org/exist/security/FnDocSecurityTest.java</include>
10081012
<include>src/main/java/org/exist/security/Permission.java</include>
10091013
<include>src/main/java/org/exist/security/PermissionRequired.java</include>
1014+
<include>src/main/java/org/exist/security/Principal.java</include>
10101015
<include>src/test/java/org/exist/security/RestApiSecurityTest.java</include>
10111016
<include>src/main/java/org/exist/security/SecurityManager.java</include>
10121017
<include>src/main/java/org/exist/security/SimpleACLPermissionInternal.java</include>
@@ -1015,7 +1020,11 @@
10151020
<include>src/test/java/org/exist/security/UnixStylePermissionTest.java</include>
10161021
<include>src/test/java/org/exist/security/XqueryApiTest.java</include>
10171022
<include>src/main/java/org/exist/security/internal/AccountImpl.java</include>
1023+
<include>src/main/java/org/exist/security/internal/RealmImpl.java</include>
1024+
<include>src/main/java/org/exist/security/internal/SecurityManagerImpl.java</include>
10181025
<include>src/main/java/org/exist/security/internal/aider/UnixStylePermissionAider.java</include>
1026+
<include>src/main/java/org/exist/security/management/AccountsManagement.java</include>
1027+
<include>src/main/java/org/exist/security/management/GroupsManagement.java</include>
10191028
<include>src/main/java/org/exist/source/Source.java</include>
10201029
<include>src/main/java/org/exist/source/SourceFactory.java</include>
10211030
<include>src/main/java/org/exist/source/URLSource.java</include>
@@ -1587,6 +1596,7 @@
15871596
<exclude>src/test/java/org/exist/collections/triggers/XQueryTriggerSetUidTest.java</exclude>
15881597
<exclude>src/test/java/org/exist/collections/triggers/XQueryTriggerTest.java</exclude>
15891598
<exclude>src/main/java/org/exist/config/Configuration.java</exclude>
1599+
<exclude>src/main/java/org/exist/config/ConfigurationDocumentTrigger.java</exclude>
15901600
<exclude>src/main/java/org/exist/config/ConfigurationImpl.java</exclude>
15911601
<exclude>src/main/java/org/exist/config/Configurator.java</exclude>
15921602
<exclude>src/test/java/org/exist/config/TwoDatabasesTest.java</exclude>
@@ -1722,11 +1732,15 @@
17221732
<exclude>src/main/java/org/exist/resolver/XercesXmlResolverAdapter.java</exclude>
17231733
<exclude>src/main/java/org/exist/scheduler/UserXQueryJob.java</exclude>
17241734
<exclude>src/main/java/org/exist/scheduler/impl/QuartzSchedulerImpl.java</exclude>
1735+
<exclude>src/main/java/org/exist/security/AbstractRealm.java</exclude>
1736+
<exclude>src/main/java/org/exist/security/AXSchemaType.java</exclude>
17251737
<exclude>src/main/java/org/exist/security/EffectiveSubject.java</exclude>
1738+
<exclude>src/main/java/org/exist/security/EXistSchemaType.java</exclude>
17261739
<exclude>src/test/java/org/exist/security/FnDocSecurityTest.java</exclude>
17271740
<exclude>src/main/java/org/exist/security/Permission.java</exclude>
17281741
<exclude>src/main/java/org/exist/security/PermissionRequired.java</exclude>
17291742
<exclude>src/main/java/org/exist/security/PermissionRequiredCheck.java</exclude>
1743+
<exclude>src/main/java/org/exist/security/Principal.java</exclude>
17301744
<exclude>src/test/java/org/exist/security/RestApiSecurityTest.java</exclude>
17311745
<exclude>src/main/java/org/exist/security/SecurityManager.java</exclude>
17321746
<exclude>src/main/java/org/exist/security/SimpleACLPermissionInternal.java</exclude>
@@ -1735,7 +1749,11 @@
17351749
<exclude>src/test/java/org/exist/security/UnixStylePermissionTest.java</exclude>
17361750
<exclude>src/test/java/org/exist/security/XqueryApiTest.java</exclude>
17371751
<exclude>src/main/java/org/exist/security/internal/AccountImpl.java</exclude>
1752+
<exclude>src/main/java/org/exist/security/internal/RealmImpl.java</exclude>
1753+
<exclude>src/main/java/org/exist/security/internal/SecurityManagerImpl.java</exclude>
17381754
<exclude>src/main/java/org/exist/security/internal/aider/UnixStylePermissionAider.java</exclude>
1755+
<exclude>src/main/java/org/exist/security/management/AccountsManagement.java</exclude>
1756+
<exclude>src/main/java/org/exist/security/management/GroupsManagement.java</exclude>
17391757
<exclude>src/main/java/org/exist/source/Source.java</exclude>
17401758
<exclude>src/main/java/org/exist/source/SourceFactory.java</exclude>
17411759
<exclude>src/main/java/org/exist/source/URLSource.java</exclude>

exist-core/src/main/java/org/exist/config/ConfigurationDocumentTrigger.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -332,9 +356,10 @@ private void processPrincipal(final PrincipalType principalType) throws SAXExcep
332356

333357
//check if there is a name collision, i.e. another principal with the same name
334358
final String principalName = findName();
335-
// first check if the account or group exists before trying to retrieve it
336-
// otherwise the LDAP realm will create a new user, leading to an endless loop
359+
360+
// NOTE(AR) first check if the account or group exists before trying to retrieve it otherwise a realm (e.g. LDAP) may create a new user, which could lead to an endless loop and eventually a StackOverflowError
337361
final boolean principalExists = principalName != null && principalType.hasPrincipal(sm, principalName);
362+
338363
Principal existingPrincipleByName = null;
339364
if (principalExists) {
340365
existingPrincipleByName = principalType.getPrincipal(sm, principalName);

exist-core/src/main/java/org/exist/config/Configurator.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.util.function.Predicate;
6767
import java.util.stream.Collectors;
6868
import java.util.stream.Stream;
69+
import javax.annotation.Nullable;
6970
import javax.xml.XMLConstants;
7071
import javax.xml.parsers.ParserConfigurationException;
7172
import javax.xml.parsers.SAXParser;
@@ -156,9 +157,15 @@ protected static <T extends Annotation> T getAnnotation(Field field, Class<T> an
156157
*
157158
* @return The Getter method for the property or null
158159
*/
159-
public static Method searchForGetMethod(final Class<?> clazz, final String property) {
160+
public static @Nullable Method searchForGetMethod(final Class<?> clazz, final String property) {
160161
try {
161-
final String methodName = ("get" + property).toLowerCase();
162+
String methodName = property;
163+
if (!methodName.startsWith("get-") && !methodName.startsWith("get_")) {
164+
methodName = "get" + methodName;
165+
}
166+
methodName = methodName.replace("-", "");
167+
methodName = methodName.replace("_", "");
168+
162169
for (final Method method : clazz.getMethods()) {
163170
if (method.getName().equalsIgnoreCase(methodName)) {
164171
return method;
@@ -178,9 +185,15 @@ public static Method searchForGetMethod(final Class<?> clazz, final String prope
178185
*
179186
* @return The Setter method for the field or null
180187
*/
181-
public static Method searchForSetMethod(final Class<?> clazz, final Field field) {
188+
public static @Nullable Method searchForSetMethod(final Class<?> clazz, final Field field) {
182189
try {
183-
final String methodName = ("set" + field.getName()).toLowerCase();
190+
String methodName = field.getName();
191+
if (!methodName.startsWith("set-") && !methodName.startsWith("set_")) {
192+
methodName = "set" + methodName;
193+
}
194+
methodName = methodName.replace("-", "");
195+
methodName = methodName.replace("_", "");
196+
184197
for (final Method method : clazz.getMethods()) {
185198
if (method.getName().equalsIgnoreCase(methodName)) {
186199
return method;
@@ -200,9 +213,14 @@ public static Method searchForSetMethod(final Class<?> clazz, final Field field)
200213
*
201214
* @return The Adder method for the property or null
202215
*/
203-
public static Method searchForAddMethod(final Class<?> clazz, final String property) {
216+
public static @Nullable Method searchForAddMethod(final Class<?> clazz, final String property) {
204217
try {
205-
final String methodName = ("add" + property).toLowerCase();
218+
String methodName = property;
219+
if (!methodName.startsWith("add-") && !methodName.startsWith("add_")) {
220+
methodName = "add" + methodName;
221+
}
222+
methodName = methodName.replace("-", "");
223+
methodName = methodName.replace("_", "");
206224
for (final Method method : clazz.getMethods()) {
207225
if (method.getName().equalsIgnoreCase(methodName)
208226
&& method.getParameterTypes().length == 1
@@ -216,9 +234,15 @@ public static Method searchForAddMethod(final Class<?> clazz, final String prope
216234
return null;
217235
}
218236

219-
public static Method searchForInsertMethod(final Class<?> clazz, final String property) {
237+
public static @Nullable Method searchForInsertMethod(final Class<?> clazz, final String property) {
220238
try {
221-
final String methodName = ("insert" + property).toLowerCase();
239+
String methodName = property;
240+
if (!methodName.startsWith("insert-") && !methodName.startsWith("insert_")) {
241+
methodName = "insert" + methodName;
242+
}
243+
methodName = methodName.replace("-", "");
244+
methodName = methodName.replace("_", "");
245+
222246
for (final Method method : clazz.getMethods()) {
223247
if (method.getName().equalsIgnoreCase(methodName)
224248
&& method.getParameterTypes().length == 2

exist-core/src/main/java/org/exist/security/AXSchemaType.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
* admin@evolvedbinary.com
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -21,6 +45,8 @@
2145
*/
2246
package org.exist.security;
2347

48+
import javax.annotation.Nullable;
49+
2450
/**
2551
*
2652
* @author <a href="mailto:adam.retter@googlemail.com">Adam Retter</a>
@@ -54,7 +80,7 @@ public String getAlias() {
5480
return alias;
5581
}
5682

57-
public static AXSchemaType valueOfNamespace(final String namespace) {
83+
public static @Nullable AXSchemaType valueOfNamespace(final String namespace) {
5884
for(final AXSchemaType axSchemaType : AXSchemaType.values()) {
5985
if(axSchemaType.getNamespace().equals(namespace)) {
6086
return axSchemaType;
@@ -63,7 +89,7 @@ public static AXSchemaType valueOfNamespace(final String namespace) {
6389
return null;
6490
}
6591

66-
public static AXSchemaType valueOfAlias(final String alias) {
92+
public static @Nullable AXSchemaType valueOfAlias(final String alias) {
6793
for(final AXSchemaType axSchemaType : AXSchemaType.values()) {
6894
if(axSchemaType.getAlias().equals(alias)) {
6995
return axSchemaType;

0 commit comments

Comments
 (0)