-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
@LdapEncode
annotation to configure encoding of LDAP parameters.
- Loading branch information
1 parent
c9a45fb
commit de3b8ff
Showing
6 changed files
with
252 additions
and
11 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/org/springframework/data/ldap/repository/LdapEncode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://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.springframework.data.ldap.repository; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.core.annotation.AliasFor; | ||
|
||
/** | ||
* Allows passing of custom {@link LdapEncoder}. | ||
* | ||
* @author Marcin Grzejszczak | ||
* @since 3.5.0 | ||
*/ | ||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface LdapEncode { | ||
|
||
/** | ||
* {@link LdapEncoder} to instantiate to encode query parameters. | ||
* | ||
* @return {@link LdapEncoder} class | ||
*/ | ||
@AliasFor("encoder") | ||
Class<? extends LdapEncoder> value(); | ||
|
||
/** | ||
* {@link LdapEncoder} to instantiate to encode query parameters. | ||
* | ||
* @return {@link LdapEncoder} class | ||
*/ | ||
@AliasFor("value") | ||
Class<? extends LdapEncoder> encoder() default LdapEncoder.class; | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/springframework/data/ldap/repository/LdapEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://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.springframework.data.ldap.repository; | ||
|
||
/** | ||
* Allows plugging in custom encoding for {@link LdapEncode}. | ||
* | ||
* @author Marcin Grzejszczak | ||
* @since 3.5.0 | ||
*/ | ||
public interface LdapEncoder { | ||
|
||
/** | ||
* Escape a value for use in a filter. | ||
* @param value the value to escape. | ||
* @return a properly escaped representation of the supplied value. | ||
*/ | ||
String filterEncode(String value); | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/org/springframework/data/ldap/repository/query/LdapParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://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.springframework.data.ldap.repository.query; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
import org.springframework.core.MethodParameter; | ||
import org.springframework.data.geo.Distance; | ||
import org.springframework.data.repository.query.Parameter; | ||
import org.springframework.data.repository.query.Parameters; | ||
import org.springframework.data.repository.query.ParametersSource; | ||
import org.springframework.data.util.TypeInformation; | ||
|
||
/** | ||
* Custom extension of {@link Parameters} discovering additional | ||
* | ||
* @author Marcin Grzejszczak | ||
* @since 3.5.0 | ||
*/ | ||
public class LdapParameters extends Parameters<LdapParameters, LdapParameters.LdapParameter> { | ||
|
||
private final TypeInformation<?> domainType; | ||
|
||
/** | ||
* Creates a new {@link LdapParameters} instance from the given {@link Method} and {@link LdapQueryMethod}. | ||
* | ||
* @param parametersSource must not be {@literal null}. | ||
*/ | ||
public LdapParameters(ParametersSource parametersSource) { | ||
|
||
super(parametersSource, methodParameter -> new LdapParameter(methodParameter, | ||
parametersSource.getDomainTypeInformation())); | ||
|
||
this.domainType = parametersSource.getDomainTypeInformation(); | ||
} | ||
|
||
private LdapParameters(List<LdapParameter> parameters, TypeInformation<?> domainType) { | ||
|
||
super(parameters); | ||
this.domainType = domainType; | ||
} | ||
|
||
@Override | ||
protected LdapParameters createFrom(List<LdapParameter> parameters) { | ||
return new LdapParameters(parameters, this.domainType); | ||
} | ||
|
||
|
||
/** | ||
* Custom {@link Parameter} implementation adding parameters of type {@link Distance} to the special ones. | ||
* | ||
* @author Marcin Grzejszczak | ||
*/ | ||
static class LdapParameter extends Parameter { | ||
|
||
final MethodParameter parameter; | ||
|
||
/** | ||
* Creates a new {@link LdapParameter}. | ||
* | ||
* @param parameter must not be {@literal null}. | ||
* @param domainType must not be {@literal null}. | ||
*/ | ||
LdapParameter(MethodParameter parameter, TypeInformation<?> domainType) { | ||
super(parameter, domainType); | ||
this.parameter = parameter; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters