Skip to content

Commit 36ce15a

Browse files
committed
Polishing.
First round of polishing.
1 parent d3ffcf3 commit 36ce15a

File tree

7 files changed

+64
-195
lines changed

7 files changed

+64
-195
lines changed

src/main/java/org/springframework/data/ldap/repository/query/AnnotatedLdapRepositoryQuery.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public class AnnotatedLdapRepositoryQuery extends AbstractLdapRepositoryQuery {
4444
/**
4545
* Construct a new instance.
4646
*
47-
* @param queryMethod the QueryMethod.
48-
* @param entityType the managed class.
49-
* @param ldapOperations the LdapOperations instance to use.
50-
* @param mappingContext must not be {@literal null}.
51-
* @param instantiators must not be {@literal null}.
47+
* @param queryMethod the QueryMethod.
48+
* @param entityType the managed class.
49+
* @param ldapOperations the LdapOperations instance to use.
50+
* @param mappingContext must not be {@literal null}.
51+
* @param instantiators must not be {@literal null}.
5252
* @deprecated use the constructor with {@link ValueExpressionDelegate}
5353
*/
5454
@Deprecated(since = "3.4")
@@ -62,11 +62,11 @@ public AnnotatedLdapRepositoryQuery(LdapQueryMethod queryMethod, Class<?> entity
6262
/**
6363
* Construct a new instance.
6464
*
65-
* @param queryMethod the QueryMethod.
66-
* @param entityType the managed class.
67-
* @param ldapOperations the LdapOperations instance to use.
68-
* @param mappingContext must not be {@literal null}.
69-
* @param instantiators must not be {@literal null}.
65+
* @param queryMethod the QueryMethod.
66+
* @param entityType the managed class.
67+
* @param ldapOperations the LdapOperations instance to use.
68+
* @param mappingContext must not be {@literal null}.
69+
* @param instantiators must not be {@literal null}.
7070
* @param valueExpressionDelegate must not be {@literal null}
7171
* @since 3.4
7272
*/
@@ -87,10 +87,13 @@ public AnnotatedLdapRepositoryQuery(LdapQueryMethod queryMethod, Class<?> entity
8787

8888
@Override
8989
protected LdapQuery createQuery(LdapParameterAccessor parameters) {
90-
ValueEvaluationContextProvider valueContextProvider = valueExpressionDelegate.createValueContextProvider(
91-
getQueryMethod().getParameters());
92-
ValueEvaluationContext evaluationContext = valueContextProvider.getEvaluationContext(
93-
parameters.getBindableParameterValues(), stringBasedQuery.getExpressionDependencies());
90+
91+
ValueEvaluationContextProvider valueContextProvider = valueExpressionDelegate
92+
.createValueContextProvider(getQueryMethod().getParameters());
93+
94+
ValueEvaluationContext evaluationContext = valueContextProvider
95+
.getEvaluationContext(parameters.getBindableParameterValues(), stringBasedQuery.getExpressionDependencies());
96+
9497
String boundQuery = stringBasedQuery.bindQuery(parameters,
9598
new ContextualValueExpressionEvaluator(valueExpressionDelegate, evaluationContext));
9699

src/test/java/org/springframework/data/ldap/config/EmbeddedLdapProperties.java

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import org.springframework.core.io.Resource;
7-
import org.springframework.util.StringUtils;
8-
9-
/**
10-
* Configuration properties for Embedded LDAP. Taken from Spring Boot.
11-
*
12-
* @author Eddú Meléndez
13-
* @author Mathieu Ouellet
14-
*/
156
public class EmbeddedLdapProperties {
167

178
/**
189
* Embedded LDAP port.
1910
*/
2011
private int port = 0;
2112

22-
/**
23-
* Embedded LDAP credentials.
24-
*/
25-
private Credential credential = new Credential();
26-
2713
/**
2814
* List of base DNs.
2915
*/
@@ -34,11 +20,6 @@ public class EmbeddedLdapProperties {
3420
*/
3521
private String ldif = "classpath:schema.ldif";
3622

37-
/**
38-
* Schema validation.
39-
*/
40-
private final Validation validation = new Validation();
41-
4223
public int getPort() {
4324
return this.port;
4425
}
@@ -47,14 +28,6 @@ public void setPort(int port) {
4728
this.port = port;
4829
}
4930

50-
public Credential getCredential() {
51-
return this.credential;
52-
}
53-
54-
public void setCredential(Credential credential) {
55-
this.credential = credential;
56-
}
57-
5831
public List<String> getBaseDn() {
5932
return this.baseDn;
6033
}
@@ -71,72 +44,4 @@ public void setLdif(String ldif) {
7144
this.ldif = ldif;
7245
}
7346

74-
public Validation getValidation() {
75-
return this.validation;
76-
}
77-
78-
public static class Credential {
79-
80-
/**
81-
* Embedded LDAP username.
82-
*/
83-
private String username;
84-
85-
/**
86-
* Embedded LDAP password.
87-
*/
88-
private String password;
89-
90-
public String getUsername() {
91-
return this.username;
92-
}
93-
94-
public void setUsername(String username) {
95-
this.username = username;
96-
}
97-
98-
public String getPassword() {
99-
return this.password;
100-
}
101-
102-
public void setPassword(String password) {
103-
this.password = password;
104-
}
105-
106-
boolean isAvailable() {
107-
return StringUtils.hasText(this.username) && StringUtils.hasText(this.password);
108-
}
109-
110-
}
111-
112-
public static class Validation {
113-
114-
/**
115-
* Whether to enable LDAP schema validation.
116-
*/
117-
private boolean enabled = false;
118-
119-
/**
120-
* Path to the custom schema.
121-
*/
122-
private Resource schema;
123-
124-
public boolean isEnabled() {
125-
return this.enabled;
126-
}
127-
128-
public void setEnabled(boolean enabled) {
129-
this.enabled = enabled;
130-
}
131-
132-
public Resource getSchema() {
133-
return this.schema;
134-
}
135-
136-
public void setSchema(Resource schema) {
137-
this.schema = schema;
138-
}
139-
140-
}
141-
142-
}
47+
}

src/test/java/org/springframework/data/ldap/config/InMemoryLdapConfiguration.java

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 the original author or authors.
2+
* Copyright 2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,18 +15,12 @@
1515
*/
1616
package org.springframework.data.ldap.config;
1717

18+
import jakarta.annotation.PreDestroy;
19+
1820
import java.io.InputStream;
1921
import java.util.HashMap;
2022
import java.util.Map;
2123

22-
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
23-
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
24-
import com.unboundid.ldap.listener.InMemoryListenerConfig;
25-
import com.unboundid.ldap.sdk.LDAPException;
26-
import com.unboundid.ldap.sdk.schema.Schema;
27-
import com.unboundid.ldif.LDIFReader;
28-
import jakarta.annotation.PreDestroy;
29-
3024
import org.springframework.context.ApplicationContext;
3125
import org.springframework.context.ConfigurableApplicationContext;
3226
import org.springframework.context.annotation.Bean;
@@ -42,6 +36,12 @@
4236
import org.springframework.util.Assert;
4337
import org.springframework.util.StringUtils;
4438

39+
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
40+
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
41+
import com.unboundid.ldap.listener.InMemoryListenerConfig;
42+
import com.unboundid.ldap.sdk.LDAPException;
43+
import com.unboundid.ldif.LDIFReader;
44+
4545
/**
4646
* Taken from Spring Boot
4747
*/
@@ -63,10 +63,6 @@ public InMemoryDirectoryServer directoryServer(ApplicationContext applicationCon
6363
throws LDAPException {
6464
String[] baseDn = StringUtils.toStringArray(this.embeddedProperties.getBaseDn());
6565
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(baseDn);
66-
if (this.embeddedProperties.getCredential().isAvailable()) {
67-
config.addAdditionalBindCredentials(this.embeddedProperties.getCredential().getUsername(),
68-
this.embeddedProperties.getCredential().getPassword());
69-
}
7066
setSchema(config);
7167
InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("LDAP",
7268
this.embeddedProperties.getPort());
@@ -86,10 +82,6 @@ LdapContextSource ldapContextSource(Environment environment, EmbeddedLdapPropert
8682
LdapContextSource source = new LdapContextSource();
8783
Assert.notEmpty(properties.getBaseDn(), "Base DN must be set with at least one value");
8884
source.setBase(properties.getBaseDn().get(0));
89-
if (embeddedProperties.getCredential().isAvailable()) {
90-
source.setUserDn(embeddedProperties.getCredential().getUsername());
91-
source.setPassword(embeddedProperties.getCredential().getPassword());
92-
}
9385
source.setUrls(determineUrls(environment, properties.getPort()));
9486
return source;
9587
}
@@ -104,25 +96,7 @@ private String[] determineUrls(Environment environment, int port) {
10496
}
10597

10698
private void setSchema(InMemoryDirectoryServerConfig config) {
107-
if (!this.embeddedProperties.getValidation().isEnabled()) {
10899
config.setSchema(null);
109-
return;
110-
}
111-
Resource schema = this.embeddedProperties.getValidation().getSchema();
112-
if (schema != null) {
113-
setSchema(config, schema);
114-
}
115-
}
116-
117-
private void setSchema(InMemoryDirectoryServerConfig config, Resource resource) {
118-
try {
119-
Schema defaultSchema = Schema.getDefaultStandardSchema();
120-
Schema schema = Schema.getSchema(resource.getInputStream());
121-
config.setSchema(Schema.mergeSchemas(defaultSchema, schema));
122-
}
123-
catch (Exception ex) {
124-
throw new IllegalStateException("Unable to load schema " + resource.getDescription(), ex);
125-
}
126100
}
127101

128102
private void importLdif(ApplicationContext applicationContext) {

src/test/java/org/springframework/data/ldap/repository/SimpleLdapRepositoryTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class SimpleLdapRepositoryTests {
6060
@BeforeEach
6161
void prepareTestedInstance() {
6262
tested = new SimpleLdapRepository<>(ldapOperationsMock, odmMock, Object.class);
63-
64-
6563
}
6664

6765
@Test

src/test/java/org/springframework/data/ldap/repository/query/PartTreeLdapRepositoryQueryTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.data.projection.ProjectionFactory;
3030
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
3131
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
32-
import org.springframework.data.repository.query.ValueExpressionDelegate;
3332
import org.springframework.ldap.core.LdapTemplate;
3433
import org.springframework.ldap.query.LdapQuery;
3534
import org.springframework.test.context.ContextConfiguration;

src/test/java/org/springframework/data/ldap/repository/query/QueryRepository.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)