├── .gitignore
├── .travis.yml
├── README.adoc
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── ldap-spring-boot-autoconfigure
├── build.gradle
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── eddumelendez
│ │ │ └── autoconfigure
│ │ │ ├── data
│ │ │ └── ldap
│ │ │ │ ├── LdapDataAutoConfiguration.java
│ │ │ │ ├── LdapRepositoriesAutoConfiguration.java
│ │ │ │ ├── LdapRepositoriesRegistrar.java
│ │ │ │ └── package-info.java
│ │ │ └── ldap
│ │ │ ├── LdapAutoConfiguration.java
│ │ │ ├── LdapProperties.java
│ │ │ ├── embedded
│ │ │ ├── EmbeddedLdapAutoConfiguration.java
│ │ │ └── EmbeddedLdapProperties.java
│ │ │ └── package-info.java
│ └── resources
│ │ └── META-INF
│ │ └── spring.factories
│ └── test
│ ├── java
│ └── com
│ │ └── github
│ │ └── eddumelendez
│ │ └── autoconfigure
│ │ ├── TestAutoConfigurationPackage.java
│ │ ├── TestAutoConfigurationPackageRegistrar.java
│ │ ├── data
│ │ ├── alt
│ │ │ └── PersonLdapRepository.java
│ │ ├── empty
│ │ │ └── EmptyDataPackage.java
│ │ └── ldap
│ │ │ ├── LdapDataAutoConfigurationTests.java
│ │ │ ├── LdapRepositoriesAutoConfigurationTests.java
│ │ │ └── person
│ │ │ ├── Person.java
│ │ │ └── PersonRepository.java
│ │ └── ldap
│ │ ├── LdapAutoConfigurationTests.java
│ │ └── embedded
│ │ └── EmbeddedLdapAutoConfigurationTests.java
│ └── resources
│ └── schema.ldif
├── ldap-spring-boot-samples
├── odm
│ ├── build.gradle
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── eddumelendez
│ │ │ └── sample
│ │ │ ├── Application.java
│ │ │ ├── Person.java
│ │ │ └── PersonRepository.java
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── eddumelendez
│ │ │ └── sample
│ │ │ └── ApplicationTests.java
│ │ └── resources
│ │ ├── application.properties
│ │ └── schema.ldif
└── plain
│ ├── build.gradle
│ └── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── github
│ │ └── eddumelendez
│ │ └── sample
│ │ └── Application.java
│ └── test
│ ├── java
│ └── com
│ │ └── github
│ │ └── eddumelendez
│ │ └── sample
│ │ └── ApplicationTests.java
│ └── resources
│ ├── application.properties
│ └── schema.ldif
├── ldap-spring-boot-starter
├── build.gradle
└── src
│ └── main
│ └── resources
│ └── META-INF
│ └── spring.provides
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .gradle/
3 | build/
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | sudo: false
3 |
4 | jdk:
5 | - oraclejdk8
6 | - oraclejdk7
7 |
8 | os:
9 | - linux
10 |
11 | branches:
12 | only:
13 | - master
14 |
15 | before_cache:
16 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
17 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
18 | cache:
19 | directories:
20 | - $HOME/.gradle/caches/
21 | - $HOME/.gradle/wrapper/
22 |
23 | script: ./gradlew clean build -Dscan
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | == Spring LDAP integration with Spring Boot
2 |
3 | image:https://travis-ci.org/eddumelendez/ldap-spring-boot.svg?branch=master["Build Status", link="https://travis-ci.org/eddumelendez/ldap-spring-boot"]
4 |
5 | NOTE: This project is not under development. Spring LDAP support is provided by Spring Boot out-of-the-box since 1.5.0.RELEASE. For more info visit https://docs.spring.io/spring-boot/docs/1.5.0.RELEASE/reference/htmlsingle/#boot-features-ldap[LDAP support in Spring Boot]
6 |
7 | This project is built on top of http://projects.spring.io/spring-ldap/[spring-ldap] project.
8 | This project provide auto-configuration for `spring-ldap`.
9 |
10 | === Dependency
11 |
12 | Maven:
13 |
14 | [source, xml]
15 | ----
16 |
17 | com.github.eddumelendez.ldap
18 | ldap-spring-boot-starter
19 | 1.0.0.RELEASE
20 |
21 | ----
22 |
23 | Gradle:
24 | [source, groovy]
25 | ----
26 | compile "com.github.eddumelendez.ldap:ldap-spring-boot-starter:1.0.0.RELEASE"
27 | ----
28 |
29 | === Properties
30 |
31 | The following properties are available to customize the `ContextSource`.
32 |
33 | [source, properties]
34 | ----
35 | ldap.urls= # LDAP urls
36 | ldap.base= # Base suffix from which all operations should originate.
37 | ldap.username= # Login user of the LDAP.
38 | ldap.password= # Login password of the LDAP.
39 | ldap.base-environment.*= # LDAP custom environment properties.
40 | ----
41 |
42 | === Using Embedded LDAP server
43 |
44 | https://www.ldap.com/unboundid-ldap-sdk-for-java[Unboundid SDK LDAP] is provided
45 | as a embedded LDAP server and it's auto-configured if the dependency is detected.
46 |
47 | Add the following dependency:
48 |
49 | Maven:
50 |
51 | [source, xml]
52 | ----
53 |
54 | com.unboundid
55 | unboundid-ldapsdk
56 | 3.1.1
57 | test
58 |
59 | ----
60 |
61 | Gradle:
62 | [source, groovy]
63 | ----
64 | testCompile "com.unboundid:unboundid-ldapsdk:3.1.1"
65 | ----
66 |
67 | You can use the following properties to customize the embedded server:
68 |
69 | [source, properties]
70 | ----
71 | ldap.embedded.port= # Embedded LDAP port. Use 0 for random port.
72 | ldap.embedded.credential.username= # Embedded LDAP username.
73 | ldap.embedded.credential.passwod= # Embedded LDAP password.
74 | ldap.embedded.partitionSuffix= # LDAP partition suffix.
75 | ldap.embedded.ldif= # Schema (LDIF) script resource reference.
76 | ----
77 |
78 | === Examples
79 |
80 | You can check the examples https://github.com/eddumelendez/ldap-spring-boot/tree/master/ldap-spring-boot-samples[here].
81 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | maven {
5 | url 'http://repo.spring.io/plugins-release'
6 | }
7 | maven {
8 | url 'https://plugins.gradle.org/m2/'
9 | }
10 | }
11 | dependencies {
12 | classpath "com.gradle:build-scan-plugin:1.6"
13 | classpath "org.springframework.build.gradle:propdeps-plugin:0.0.7"
14 | classpath "io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE"
15 | classpath "com.bmuschko:gradle-nexus-plugin:2.3.1"
16 | }
17 | }
18 |
19 | apply plugin: 'com.gradle.build-scan'
20 |
21 | buildScan {
22 | licenseAgreementUrl = 'https://gradle.com/terms-of-service'
23 | licenseAgree = 'yes'
24 | tag 'CI'
25 | link 'VCS', 'https://github.com/eddumelendez/ldap-spring-boot'
26 | }
27 |
28 | description = "LDAP integration with Spring Boot"
29 |
30 | ext.sampleModules = subprojects.findAll { project -> project.name.endsWith('plain') || project.name.endsWith('odm') }
31 | ext.coreModules = subprojects - sampleModules
32 |
33 | configure(coreModules) {
34 |
35 | apply plugin: "java"
36 | apply plugin: "propdeps-maven"
37 | apply plugin: "com.bmuschko.nexus"
38 |
39 | group='com.github.eddumelendez.ldap'
40 |
41 | sourceCompatibility=1.6
42 | targetCompatibility=1.6
43 |
44 | repositories {
45 | mavenCentral()
46 | }
47 |
48 | modifyPom {
49 | project {
50 | def generatedDeps = dependencies
51 | dependencies {
52 | generatedDeps.removeAll { dep ->
53 | dep.scope == "optional" || dep.scope == "test"
54 | }
55 | generatedDeps.each { dep ->
56 | dependency {
57 | groupId dep.groupId
58 | artifactId dep.artifactId
59 | if (dep.version)
60 | version dep.version
61 | scope dep.scope
62 | }
63 | }
64 | }
65 |
66 | name project.description
67 | description = project.description
68 | url = "https://github.com/eddumelendez/ldap-spring-boot"
69 | licenses {
70 | license {
71 | name "The Apache Software License, Version 2.0"
72 | url "http://www.apache.org/licenses/LICENSE-2.0.txt"
73 | distribution "repo"
74 | }
75 | }
76 | scm {
77 | url = "https://github.com/eddumelendez/ldap-spring-boot"
78 | connection = "scm:git:git://github.com/eddumelendez/ldap-spring-boot"
79 | developerConnection = "scm:git:git://github.com/eddumelendez/ldap-spring-boot"
80 | }
81 | developers {
82 | developer {
83 | id = "eddumelendez"
84 | name = "Eddú Meléndez"
85 | email = "eddu.melendez@gmail.com"
86 | }
87 | }
88 | issueManagement {
89 | system = "GitHub"
90 | url = "https://github.com/eddumelendez/ldap-spring-boot/issues"
91 | }
92 | }
93 | }
94 |
95 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | version=1.0.1.SNAPSHOT
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eddumelendez/ldap-spring-boot/f07fbb3babe5ddeafef1219f367eb8c77e6b6051/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Aug 15 12:40:09 PET 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
165 | if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
166 | cd "$(dirname "$0")"
167 | fi
168 |
169 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
170 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "propdeps"
2 | apply plugin: "io.spring.dependency-management"
3 |
4 | ext.springBootVersion='1.4.2.RELEASE'
5 | ext.springLdapVersion='2.2.0.RELEASE'
6 | ext.unboundidVersion='3.2.0'
7 |
8 | description = "Spring Boot LDAP AutoConfigure"
9 |
10 | dependencies {
11 | compile "org.springframework.boot:spring-boot"
12 | compile "org.springframework.boot:spring-boot-autoconfigure"
13 | compile "org.springframework.data:spring-data-commons"
14 | compile("org.springframework.ldap:spring-ldap-core:${springLdapVersion}") {
15 | exclude group: "org.slf4j", module: "slf4j-api"
16 | }
17 | optional "com.unboundid:unboundid-ldapsdk:${unboundidVersion}"
18 | optional "org.springframework.boot:spring-boot-configuration-processor"
19 |
20 | testCompile "org.springframework.boot:spring-boot-starter-test"
21 | }
22 |
23 | dependencyManagement {
24 | dependencies {
25 | imports {
26 | mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/data/ldap/LdapDataAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.ldap;
18 |
19 | import javax.naming.ldap.LdapContext;
20 |
21 | import com.github.eddumelendez.autoconfigure.ldap.LdapAutoConfiguration;
22 |
23 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
24 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
28 | import org.springframework.context.annotation.Bean;
29 | import org.springframework.context.annotation.Configuration;
30 | import org.springframework.ldap.core.ContextSource;
31 | import org.springframework.ldap.core.LdapOperations;
32 | import org.springframework.ldap.core.LdapTemplate;
33 | import org.springframework.ldap.repository.LdapRepository;
34 |
35 | /**
36 | * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's LDAP support.
37 | *
38 | * @author Eddú Meléndez
39 | * @since 1.0.0
40 | */
41 | @Configuration
42 | @ConditionalOnClass({ LdapContext.class, LdapRepository.class })
43 | @AutoConfigureAfter(LdapAutoConfiguration.class)
44 | public class LdapDataAutoConfiguration {
45 |
46 | @Bean
47 | @ConditionalOnMissingBean(LdapOperations.class)
48 | @ConditionalOnSingleCandidate(ContextSource.class)
49 | public LdapTemplate ldapTemplate(ContextSource contextSource) {
50 | return new LdapTemplate(contextSource);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/data/ldap/LdapRepositoriesAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.ldap;
18 |
19 | import javax.naming.ldap.LdapContext;
20 |
21 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
25 | import org.springframework.context.annotation.Configuration;
26 | import org.springframework.context.annotation.Import;
27 | import org.springframework.ldap.repository.LdapRepository;
28 | import org.springframework.ldap.repository.support.LdapRepositoryFactoryBean;
29 |
30 | /**
31 | * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Couchbase
32 | * Repositories.
33 | *
34 | * @author Eddú Meléndez
35 | * @since 1.0.0
36 | */
37 | @Configuration
38 | @ConditionalOnClass({ LdapContext.class, LdapRepository.class })
39 | @ConditionalOnProperty(prefix = "ldap.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
40 | @ConditionalOnMissingBean(LdapRepositoryFactoryBean.class)
41 | @Import(LdapRepositoriesRegistrar.class)
42 | public class LdapRepositoriesAutoConfiguration {
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/data/ldap/LdapRepositoriesRegistrar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.ldap;
18 |
19 | import java.lang.annotation.Annotation;
20 |
21 | import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport;
22 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
23 | import org.springframework.data.repository.config.RepositoryConfigurationExtension;
24 | import org.springframework.ldap.repository.config.EnableLdapRepositories;
25 | import org.springframework.ldap.repository.config.LdapRepositoryConfigurationExtension;
26 |
27 |
28 | /**
29 | * {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data LDAP
30 | * Repositories.
31 | *
32 | * @author Eddú Meléndez
33 | * @since 1.0.0
34 | */
35 | class LdapRepositoriesRegistrar
36 | extends AbstractRepositoryConfigurationSourceSupport {
37 |
38 | @Override
39 | protected Class extends Annotation> getAnnotation() {
40 | return EnableLdapRepositories.class;
41 | }
42 |
43 | @Override
44 | protected Class> getConfiguration() {
45 | return EnableLdapRepositoriesConfiguration.class;
46 | }
47 |
48 | @Override
49 | protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() {
50 | return new LdapRepositoryConfigurationExtension();
51 | }
52 |
53 | @EnableLdapRepositories
54 | private static class EnableLdapRepositoriesConfiguration {
55 |
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/data/ldap/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.github.eddumelendez.autoconfigure.data.ldap;
17 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/ldap/LdapAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.ldap;
18 |
19 | import java.util.Collections;
20 |
21 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
24 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
25 | import org.springframework.context.annotation.Bean;
26 | import org.springframework.context.annotation.Configuration;
27 | import org.springframework.core.env.Environment;
28 | import org.springframework.ldap.core.ContextSource;
29 | import org.springframework.ldap.core.support.LdapContextSource;
30 |
31 | /**
32 | * {@link EnableAutoConfiguration Auto-configuration} for LDAP.
33 | *
34 | * @author Eddú Meléndez
35 | * @since 1.0.0
36 | */
37 | @Configuration
38 | @ConditionalOnClass(ContextSource.class)
39 | @EnableConfigurationProperties(LdapProperties.class)
40 | public class LdapAutoConfiguration {
41 |
42 | private LdapProperties properties;
43 |
44 | private Environment environment;
45 |
46 | public LdapAutoConfiguration(LdapProperties properties,
47 | Environment environment) {
48 | this.properties = properties;
49 | this.environment = environment;
50 | }
51 |
52 | @Bean
53 | @ConditionalOnMissingBean
54 | public ContextSource contextSource() {
55 | LdapContextSource contextSource = new LdapContextSource();
56 | contextSource.setUserDn(this.properties.getUsername());
57 | contextSource.setPassword(this.properties.getPassword());
58 | contextSource.setBase(this.properties.getBase());
59 | contextSource.setUrls(this.properties.determineUrls(this.environment));
60 | contextSource.setBaseEnvironmentProperties(Collections
61 | .unmodifiableMap(this.properties.getBaseEnvironment()));
62 | return contextSource;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/ldap/LdapProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.ldap;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | import org.springframework.boot.context.properties.ConfigurationProperties;
23 | import org.springframework.core.env.Environment;
24 | import org.springframework.ldap.core.LdapTemplate;
25 |
26 | /**
27 | * Configuration properties to configure {@link LdapTemplate}.
28 | *
29 | * @author Eddú Meléndez
30 | * @since 1.0.0
31 | */
32 | @ConfigurationProperties(prefix = "ldap")
33 | public class LdapProperties {
34 |
35 | private static final int DEFAULT_PORT = 389;
36 |
37 | /**
38 | * LDAP urls.
39 | */
40 | private String[] urls = new String[0];
41 |
42 | /**
43 | * Base suffix from which all operations should originate.
44 | */
45 | private String base;
46 |
47 | /**
48 | * Login user of the LDAP.
49 | */
50 | private String username;
51 |
52 | /**
53 | * Login password of the LDAP.
54 | */
55 | private String password;
56 |
57 | /**
58 | * LDAP custom environment properties.
59 | */
60 | private Map baseEnvironment = new HashMap();
61 |
62 | public String[] getUrls() {
63 | return this.urls;
64 | }
65 |
66 | public void setUrls(String[] urls) {
67 | this.urls = urls;
68 | }
69 |
70 | public String getBase() {
71 | return this.base;
72 | }
73 |
74 | public void setBase(String base) {
75 | this.base = base;
76 | }
77 |
78 | public String getUsername() {
79 | return this.username;
80 | }
81 |
82 | public void setUsername(String username) {
83 | this.username = username;
84 | }
85 |
86 | public String getPassword() {
87 | return this.password;
88 | }
89 |
90 | public void setPassword(String password) {
91 | this.password = password;
92 | }
93 |
94 | public Map getBaseEnvironment() {
95 | return this.baseEnvironment;
96 | }
97 |
98 | public void setBaseEnvironment(Map baseEnvironment) {
99 | this.baseEnvironment = baseEnvironment;
100 | }
101 |
102 | public String[] determineUrls(Environment environment) {
103 | if (this.urls.length == 0) {
104 | String protocol = "ldap://";
105 | String host = "localhost";
106 | int port = determinePort(environment);
107 | String[] ldapUrls = new String[1];
108 | ldapUrls[0] = protocol + host + ":" + port;
109 | return ldapUrls;
110 | }
111 | return this.urls;
112 | }
113 |
114 | private int determinePort(Environment environment) {
115 | if (environment != null) {
116 | String localPort = environment.getProperty("local.ldap.port");
117 | if (localPort != null) {
118 | return Integer.valueOf(localPort);
119 | }
120 | else {
121 | return DEFAULT_PORT;
122 | }
123 | }
124 | throw new IllegalStateException(
125 | "No local ldap port configuration is available");
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.ldap.embedded;
18 |
19 | import java.io.File;
20 | import java.io.FileOutputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | import javax.annotation.PreDestroy;
27 |
28 | import com.github.eddumelendez.autoconfigure.ldap.LdapAutoConfiguration;
29 | import com.github.eddumelendez.autoconfigure.ldap.LdapProperties;
30 | import com.unboundid.ldap.listener.InMemoryDirectoryServer;
31 | import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
32 | import com.unboundid.ldap.listener.InMemoryListenerConfig;
33 | import com.unboundid.ldap.sdk.LDAPException;
34 | import com.unboundid.ldif.LDIFReader;
35 |
36 | import org.springframework.boot.autoconfigure.AutoConfigureBefore;
37 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
38 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
39 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
40 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
41 | import org.springframework.context.ApplicationContext;
42 | import org.springframework.context.ConfigurableApplicationContext;
43 | import org.springframework.context.annotation.Bean;
44 | import org.springframework.context.annotation.Configuration;
45 | import org.springframework.context.annotation.DependsOn;
46 | import org.springframework.core.env.Environment;
47 | import org.springframework.core.env.MapPropertySource;
48 | import org.springframework.core.env.MutablePropertySources;
49 | import org.springframework.core.env.PropertySource;
50 | import org.springframework.core.io.Resource;
51 | import org.springframework.ldap.core.ContextSource;
52 | import org.springframework.ldap.core.support.LdapContextSource;
53 | import org.springframework.util.FileCopyUtils;
54 | import org.springframework.util.StringUtils;
55 |
56 | /**
57 | * {@link EnableAutoConfiguration Auto-configuration} for Embedded LDAP.
58 | *
59 | * @author Eddú Meléndez
60 | * @since 1.0.0
61 | */
62 | @Configuration
63 | @EnableConfigurationProperties({LdapProperties.class, EmbeddedLdapProperties.class })
64 | @AutoConfigureBefore(LdapAutoConfiguration.class)
65 | @ConditionalOnClass(InMemoryDirectoryServer.class)
66 | public class EmbeddedLdapAutoConfiguration {
67 |
68 | private InMemoryDirectoryServer server;
69 |
70 | private EmbeddedLdapProperties embeddedProperties;
71 |
72 | private LdapProperties properties;
73 |
74 | private ConfigurableApplicationContext applicationContext;
75 |
76 | private Environment environment;
77 |
78 | public EmbeddedLdapAutoConfiguration(EmbeddedLdapProperties embeddedProperties,
79 | LdapProperties properties,
80 | ConfigurableApplicationContext applicationContext,
81 | Environment environment) {
82 | this.embeddedProperties = embeddedProperties;
83 | this.properties = properties;
84 | this.applicationContext = applicationContext;
85 | this.environment = environment;
86 | }
87 |
88 | @Bean
89 | @DependsOn("directoryServer")
90 | @ConditionalOnMissingBean
91 | public ContextSource contextSource() {
92 | LdapContextSource contextSource = new LdapContextSource();
93 |
94 | EmbeddedLdapProperties.Credential credential = this.embeddedProperties
95 | .getCredential();
96 | if (StringUtils.hasText(credential.getUsername()) &&
97 | StringUtils.hasText(credential.getPassword())) {
98 | contextSource.setUserDn(credential.getUsername());
99 | contextSource.setPassword(credential.getPassword());
100 | }
101 | contextSource.setUrls(this.properties.determineUrls(this.environment));
102 | return contextSource;
103 | }
104 |
105 | @Bean
106 | public InMemoryDirectoryServer directoryServer() throws LDAPException {
107 | InMemoryDirectoryServerConfig config =
108 | new InMemoryDirectoryServerConfig(this.embeddedProperties
109 | .getPartitionSuffix());
110 |
111 | EmbeddedLdapProperties.Credential credential = this.embeddedProperties
112 | .getCredential();
113 | if (StringUtils.hasText(credential.getUsername()) &&
114 | StringUtils.hasText(credential.getPassword())) {
115 | config.addAdditionalBindCredentials(credential
116 | .getUsername(), credential.getPassword());
117 | }
118 |
119 | config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP",
120 | this.embeddedProperties.getPort()));
121 |
122 | this.server = new InMemoryDirectoryServer(config);
123 |
124 | populateDirectoryServer();
125 |
126 | this.server.startListening();
127 | publishPortInfo(this.server.getListenPort());
128 | return this.server;
129 | }
130 |
131 | private void publishPortInfo(int port) {
132 | setPortProperty(this.applicationContext, port);
133 | }
134 |
135 | private void setPortProperty(ApplicationContext currentContext,
136 | int port) {
137 | if (currentContext instanceof ConfigurableApplicationContext) {
138 | MutablePropertySources sources = ((ConfigurableApplicationContext)
139 | currentContext).getEnvironment().getPropertySources();
140 | getLdapPorts(sources).put("local.ldap.port", port);
141 | }
142 | if (currentContext.getParent() != null) {
143 | setPortProperty(currentContext.getParent(), port);
144 | }
145 | }
146 |
147 | private Map getLdapPorts(MutablePropertySources sources) {
148 | PropertySource> propertySource = sources.get("ldap.ports");
149 | if (propertySource == null) {
150 | propertySource = new MapPropertySource("ldap.ports",
151 | new HashMap());
152 | sources.addFirst(propertySource);
153 | }
154 | return (Map) propertySource.getSource();
155 | }
156 |
157 | private void populateDirectoryServer() throws LDAPException {
158 | String location = this.embeddedProperties.getLdif();
159 | if (StringUtils.hasText(location)) {
160 | try {
161 | Resource resource = this.applicationContext.getResource(
162 | this.embeddedProperties.getLdif());
163 | if (resource.exists()) {
164 | File tempFile = File.createTempFile("ldap_test_data", ".ldif");
165 | try {
166 | InputStream inputStream = resource.getInputStream();
167 | FileCopyUtils.copy(inputStream, new FileOutputStream(tempFile));
168 | this.server.importFromLDIF(true, new LDIFReader(tempFile));
169 | }
170 | catch (LDAPException e) {
171 | e.printStackTrace();
172 | }
173 | finally {
174 | tempFile.delete();
175 | }
176 | }
177 | }
178 | catch (IOException ex) {
179 | throw new IllegalStateException(
180 | "Unable to load resource from " + location, ex);
181 | }
182 | }
183 | }
184 |
185 | @PreDestroy
186 | public void close() {
187 | if (this.server != null) {
188 | this.server.shutDown(true);
189 | }
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/ldap/embedded/EmbeddedLdapProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.ldap.embedded;
18 |
19 | import org.springframework.boot.context.properties.ConfigurationProperties;
20 |
21 | /**
22 | * Configuration properties for Embedded LDAP.
23 | *
24 | * @author Eddú Meléndez
25 | * @since 1.0.0
26 | */
27 | @ConfigurationProperties(prefix = "ldap.embedded")
28 | public class EmbeddedLdapProperties {
29 |
30 | /**
31 | * Embedded LDAP port.
32 | */
33 | private int port = 0;
34 |
35 | /**
36 | * Embedded LDAP credentials.
37 | */
38 | private Credential credential = new Credential();
39 |
40 | /**
41 | * LDAP partition suffix.
42 | */
43 | private String partitionSuffix;
44 |
45 | /**
46 | * Schema (LDIF) script resource reference.
47 | */
48 | private String ldif;
49 |
50 | public int getPort() {
51 | return this.port;
52 | }
53 |
54 | public void setPort(int port) {
55 | this.port = port;
56 | }
57 |
58 | public Credential getCredential() {
59 | return this.credential;
60 | }
61 |
62 | public void setCredential(Credential credential) {
63 | this.credential = credential;
64 | }
65 |
66 | public String getPartitionSuffix() {
67 | return this.partitionSuffix;
68 | }
69 |
70 | public void setPartitionSuffix(String partitionSuffix) {
71 | this.partitionSuffix = partitionSuffix;
72 | }
73 |
74 | public String getLdif() {
75 | return this.ldif;
76 | }
77 |
78 | public void setLdif(String ldif) {
79 | this.ldif = ldif;
80 | }
81 |
82 | static class Credential {
83 |
84 | /**
85 | * Embedded LDAP username.
86 | */
87 | private String username;
88 |
89 | /**
90 | * Embedded LDAP password.
91 | */
92 | private String password;
93 |
94 | public String getUsername() {
95 | return this.username;
96 | }
97 |
98 | public void setUsername(String username) {
99 | this.username = username;
100 | }
101 |
102 | public String getPassword() {
103 | return this.password;
104 | }
105 |
106 | public void setPassword(String password) {
107 | this.password = password;
108 | }
109 |
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/java/com/github/eddumelendez/autoconfigure/ldap/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.ldap;
18 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | # Auto Configure
2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
3 | com.github.eddumelendez.autoconfigure.data.ldap.LdapDataAutoConfiguration,\
4 | com.github.eddumelendez.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\
5 | com.github.eddumelendez.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\
6 | com.github.eddumelendez.autoconfigure.ldap.LdapAutoConfiguration
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/TestAutoConfigurationPackage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
26 | import org.springframework.context.annotation.Import;
27 |
28 | /**
29 | * Test annotation to configure the {@link AutoConfigurationPackages} to an arbitrary
30 | * value.
31 | *
32 | * @author Phillip Webb
33 | */
34 | @Target(ElementType.TYPE)
35 | @Retention(RetentionPolicy.RUNTIME)
36 | @Documented
37 | @Import(TestAutoConfigurationPackageRegistrar.class)
38 | public @interface TestAutoConfigurationPackage {
39 |
40 | Class> value();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/TestAutoConfigurationPackageRegistrar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure;
18 |
19 | import org.springframework.beans.factory.support.BeanDefinitionRegistry;
20 | import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
21 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
22 | import org.springframework.core.Ordered;
23 | import org.springframework.core.annotation.AnnotationAttributes;
24 | import org.springframework.core.annotation.Order;
25 | import org.springframework.core.type.AnnotationMetadata;
26 | import org.springframework.util.ClassUtils;
27 |
28 | /**
29 | * {@link ImportBeanDefinitionRegistrar} to store the base package for tests.
30 | *
31 | * @author Phillip Webb
32 | */
33 | @Order(Ordered.HIGHEST_PRECEDENCE)
34 | public class TestAutoConfigurationPackageRegistrar
35 | implements ImportBeanDefinitionRegistrar {
36 |
37 | @Override
38 | public void registerBeanDefinitions(AnnotationMetadata metadata,
39 | BeanDefinitionRegistry registry) {
40 | AnnotationAttributes attributes = AnnotationAttributes
41 | .fromMap(metadata.getAnnotationAttributes(
42 | TestAutoConfigurationPackage.class.getName(), true));
43 | AutoConfigurationPackages.register(registry,
44 | ClassUtils.getPackageName(attributes.getString("value")));
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/data/alt/PersonLdapRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.alt;
18 |
19 | import javax.naming.Name;
20 |
21 | import com.github.eddumelendez.autoconfigure.data.ldap.person.Person;
22 |
23 | import org.springframework.data.repository.Repository;
24 |
25 | public interface PersonLdapRepository extends Repository {
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/data/empty/EmptyDataPackage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.empty;
18 |
19 | public class EmptyDataPackage {
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/data/ldap/LdapDataAutoConfigurationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.ldap;
18 |
19 | import com.github.eddumelendez.autoconfigure.ldap.LdapAutoConfiguration;
20 | import org.junit.After;
21 | import org.junit.Test;
22 |
23 | import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
24 | import org.springframework.boot.test.util.EnvironmentTestUtils;
25 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
26 | import org.springframework.context.annotation.Bean;
27 | import org.springframework.context.annotation.Configuration;
28 | import org.springframework.ldap.core.ContextSource;
29 | import org.springframework.ldap.core.LdapTemplate;
30 | import org.springframework.ldap.core.support.LdapContextSource;
31 |
32 | import static org.assertj.core.api.Assertions.assertThat;
33 | import static org.mockito.Mockito.mock;
34 |
35 | /**
36 | * Tests for {@link LdapDataAutoConfiguration}
37 | *
38 | * @author Eddú Meléndez
39 | */
40 | public class LdapDataAutoConfigurationTests {
41 |
42 | private AnnotationConfigApplicationContext context;
43 |
44 | @After
45 | public void close() {
46 | this.context.close();
47 | }
48 |
49 | @Test
50 | public void templateExists() {
51 | this.context = new AnnotationConfigApplicationContext();
52 | EnvironmentTestUtils.addEnvironment(this.context,
53 | "spring.ldap.urls:ldap://localhost:389");
54 | this.context.register(PropertyPlaceholderAutoConfiguration.class,
55 | LdapAutoConfiguration.class, LdapDataAutoConfiguration.class);
56 | this.context.refresh();
57 | assertThat(this.context.getBeanNamesForType(LdapTemplate.class).length)
58 | .isEqualTo(1);
59 | }
60 |
61 | @Test
62 | public void resolvePrimaryContextSourceBean() {
63 | this.context = new AnnotationConfigApplicationContext();
64 | EnvironmentTestUtils.addEnvironment(this.context,
65 | "spring.ldap.urls:ldap://localhost:389");
66 | this.context.register(PropertyPlaceholderAutoConfiguration.class,
67 | LdapCustomConfiguration.class, LdapAutoConfiguration.class,
68 | LdapDataAutoConfiguration.class);
69 | this.context.refresh();
70 | assertThat(this.context.getBeanNamesForType(LdapTemplate.class).length)
71 | .isEqualTo(0);
72 | }
73 |
74 |
75 | @Configuration
76 | static class LdapCustomConfiguration {
77 |
78 | @Bean
79 | public ContextSource contextSource1() {
80 | return mock(LdapContextSource.class);
81 | }
82 |
83 | @Bean
84 | public ContextSource contextSource2() {
85 | return mock(LdapContextSource.class);
86 | }
87 |
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/data/ldap/LdapRepositoriesAutoConfigurationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.ldap;
18 |
19 | import com.github.eddumelendez.autoconfigure.TestAutoConfigurationPackage;
20 | import com.github.eddumelendez.autoconfigure.ldap.LdapAutoConfiguration;
21 | import com.github.eddumelendez.autoconfigure.data.alt.PersonLdapRepository;
22 | import com.github.eddumelendez.autoconfigure.data.empty.EmptyDataPackage;
23 | import com.github.eddumelendez.autoconfigure.data.ldap.person.Person;
24 | import com.github.eddumelendez.autoconfigure.data.ldap.person.PersonRepository;
25 | import org.junit.After;
26 | import org.junit.Test;
27 |
28 | import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
29 | import org.springframework.boot.test.util.EnvironmentTestUtils;
30 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
31 | import org.springframework.context.annotation.Configuration;
32 | import org.springframework.ldap.repository.config.EnableLdapRepositories;
33 |
34 | import static org.assertj.core.api.Assertions.assertThat;
35 |
36 | /**
37 | * Tests for {@link LdapRepositoriesAutoConfiguration}
38 | *
39 | * @author Eddú Meléndez
40 | */
41 | public class LdapRepositoriesAutoConfigurationTests {
42 |
43 | private AnnotationConfigApplicationContext context;
44 |
45 | @After
46 | public void close() {
47 | if (this.context != null) {
48 | this.context.close();
49 | }
50 | }
51 |
52 | @Test
53 | public void testDefaultRepositoryConfiguration() throws Exception {
54 | load(TestConfiguration.class);
55 | assertThat(this.context.getBean(PersonRepository.class)).isNotNull();
56 | }
57 |
58 | @Test
59 | public void testNoRepositoryConfiguration() throws Exception {
60 | load(EmptyConfiguration.class);
61 |
62 | assertThat(this.context.getBeanNamesForType(PersonRepository.class).length)
63 | .isEqualTo(0);
64 | }
65 |
66 | @Test
67 | public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
68 | load(CustomizedConfiguration.class);
69 | assertThat(this.context.getBean(PersonLdapRepository.class)).isNotNull();
70 | }
71 |
72 | private void load(Class>... configurationClasses) {
73 | this.context = new AnnotationConfigApplicationContext();
74 | EnvironmentTestUtils.addEnvironment(this.context,
75 | "spring.ldap.urls:ldap://localhost:389");
76 | this.context.register(configurationClasses);
77 | this.context.register(LdapAutoConfiguration.class,
78 | LdapDataAutoConfiguration.class,
79 | LdapRepositoriesAutoConfiguration.class,
80 | PropertyPlaceholderAutoConfiguration.class);
81 | this.context.refresh();
82 | }
83 |
84 | @Configuration
85 | @TestAutoConfigurationPackage(Person.class)
86 | protected static class TestConfiguration {
87 |
88 | }
89 |
90 | @Configuration
91 | @TestAutoConfigurationPackage(EmptyDataPackage.class)
92 | protected static class EmptyConfiguration {
93 |
94 | }
95 |
96 | @Configuration
97 | @TestAutoConfigurationPackage(LdapRepositoriesAutoConfigurationTests.class)
98 | @EnableLdapRepositories(basePackageClasses = PersonLdapRepository.class)
99 | protected static class CustomizedConfiguration {
100 |
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/data/ldap/person/Person.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.ldap.person;
18 |
19 | import javax.naming.Name;
20 |
21 | import org.springframework.ldap.odm.annotations.Attribute;
22 | import org.springframework.ldap.odm.annotations.DnAttribute;
23 | import org.springframework.ldap.odm.annotations.Entry;
24 | import org.springframework.ldap.odm.annotations.Id;
25 |
26 | @Entry(objectClasses = {"person", "top"}, base = "ou=someOu")
27 | public class Person {
28 |
29 | @Id
30 | private Name dn;
31 |
32 | @Attribute(name = "cn")
33 | @DnAttribute(value = "cn", index = 1)
34 | private String fullName;
35 |
36 | public Name getDn() {
37 | return this.dn;
38 | }
39 |
40 | public void setDn(Name dn) {
41 | this.dn = dn;
42 | }
43 |
44 | public String getFullName() {
45 | return this.fullName;
46 | }
47 |
48 | public void setFullName(String fullName) {
49 | this.fullName = fullName;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/data/ldap/person/PersonRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.data.ldap.person;
18 |
19 | import javax.naming.Name;
20 |
21 | import org.springframework.data.repository.Repository;
22 |
23 | public interface PersonRepository extends Repository {
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/ldap/LdapAutoConfigurationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.ldap;
18 |
19 | import org.assertj.core.api.Assertions;
20 | import org.junit.After;
21 | import org.junit.Before;
22 | import org.junit.Test;
23 |
24 | import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
25 | import org.springframework.boot.test.util.EnvironmentTestUtils;
26 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
27 | import org.springframework.ldap.core.ContextSource;
28 | import org.springframework.test.util.ReflectionTestUtils;
29 |
30 | import static org.assertj.core.api.Assertions.assertThat;
31 |
32 | /**
33 | * Tests for {@link LdapAutoConfiguration}.
34 | *
35 | * @author Eddú Meléndez
36 | */
37 | public class LdapAutoConfigurationTests {
38 |
39 | private AnnotationConfigApplicationContext context;
40 |
41 | @Before
42 | public void setUp() {
43 | this.context = new AnnotationConfigApplicationContext();
44 | }
45 |
46 | @After
47 | public void close() {
48 | if (this.context != null) {
49 | this.context.close();
50 | }
51 | }
52 |
53 | @Test
54 | public void testDefaultUrl() {
55 | load();
56 | assertThat(this.context.getBeanNamesForType(ContextSource.class).length)
57 | .isEqualTo(1);
58 | assertThat(ReflectionTestUtils.getField(this.context.getBean(ContextSource.class),
59 | "urls")).isEqualTo(new String[]{"ldap://localhost:389"});
60 | }
61 |
62 | @Test
63 | public void testContextSourceSetOneUrl() {
64 | load("ldap.urls:ldap://localhost:123");
65 | assertThat(this.context.getBeanNamesForType(ContextSource.class).length)
66 | .isEqualTo(1);
67 | assertThat(ReflectionTestUtils.getField(this.context.getBean(ContextSource.class),
68 | "urls")).isEqualTo(new String[]{"ldap://localhost:123"});
69 | }
70 |
71 | @Test
72 | public void testContextSourceSetTwoUrls() {
73 | load("ldap.urls:ldap://localhost:123,ldap://mycompany:123");
74 | assertThat(this.context.getBeanNamesForType(ContextSource.class).length)
75 | .isEqualTo(1);
76 | Assertions.assertThat(this.context.getBean(LdapProperties.class).getUrls().length)
77 | .isEqualTo(2);
78 | assertThat(ReflectionTestUtils.getField(this.context.getBean(ContextSource.class),
79 | "urls"))
80 | .isEqualTo(new String[]{"ldap://localhost:123", "ldap://mycompany:123"});
81 | }
82 |
83 | @Test
84 | public void testContextSourceWithMoreProperties() {
85 | load("ldap.urls:ldap://localhost:123",
86 | "ldap.username:root",
87 | "ldap.password:root",
88 | "ldap.base:cn=SpringDevelopers",
89 | "ldap.baseEnvironment.java.naming.security.authentication:DIGEST-MD5");
90 | assertThat(this.context.getBeanNamesForType(ContextSource.class).length)
91 | .isEqualTo(1);
92 | assertThat(this.context.getBean(LdapProperties.class).getBaseEnvironment())
93 | .containsEntry("java.naming.security.authentication", "DIGEST-MD5");
94 | }
95 |
96 | private void load(String... properties) {
97 | EnvironmentTestUtils.addEnvironment(this.context, properties);
98 | this.context
99 | .register(LdapAutoConfiguration.class,
100 | PropertyPlaceholderAutoConfiguration.class);
101 | this.context.refresh();
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/java/com/github/eddumelendez/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.autoconfigure.ldap.embedded;
18 |
19 | import com.github.eddumelendez.autoconfigure.ldap.LdapAutoConfiguration;
20 | import com.github.eddumelendez.autoconfigure.data.ldap.LdapDataAutoConfiguration;
21 | import com.unboundid.ldap.listener.InMemoryDirectoryServer;
22 | import com.unboundid.ldap.sdk.BindResult;
23 | import com.unboundid.ldap.sdk.DN;
24 | import com.unboundid.ldap.sdk.LDAPConnection;
25 | import com.unboundid.ldap.sdk.LDAPException;
26 | import org.junit.After;
27 | import org.junit.Before;
28 | import org.junit.Test;
29 |
30 | import org.springframework.beans.factory.annotation.Value;
31 | import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
32 | import org.springframework.boot.test.util.EnvironmentTestUtils;
33 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
34 | import org.springframework.context.annotation.Bean;
35 | import org.springframework.context.annotation.Configuration;
36 | import org.springframework.ldap.core.LdapTemplate;
37 |
38 | import static org.assertj.core.api.Assertions.assertThat;
39 |
40 | /**
41 | * Tests for {@link EmbeddedLdapAutoConfiguration}
42 | *
43 | * @author Eddú Meléndez
44 | */
45 | public class EmbeddedLdapAutoConfigurationTests {
46 |
47 | private AnnotationConfigApplicationContext context;
48 |
49 | @Before
50 | public void setUp() {
51 | this.context = new AnnotationConfigApplicationContext();
52 | }
53 |
54 | @After
55 | public void close() {
56 | if (this.context != null) {
57 | this.context.close();
58 | }
59 | }
60 |
61 | @Test
62 | public void testSetDefaultPort() throws LDAPException {
63 | load("ldap.embedded.port:1234",
64 | "ldap.embedded.partitionSuffix:dc=spring,dc=org");
65 | InMemoryDirectoryServer server = this.context
66 | .getBean(InMemoryDirectoryServer.class);
67 | assertThat(server.getListenPort()).isEqualTo(1234);
68 | }
69 |
70 | @Test
71 | public void testRandomPortWithEnvironment() throws LDAPException {
72 | load("ldap.embedded.partitionSuffix:dc=spring,dc=org");
73 | InMemoryDirectoryServer server = this.context
74 | .getBean(InMemoryDirectoryServer.class);
75 | assertThat(server.getListenPort()).isEqualTo(this.context.getEnvironment()
76 | .getProperty("local.ldap.port", Integer.class));
77 | }
78 |
79 | @Test
80 | public void testRandomPortWithValueAnnotation() throws LDAPException {
81 | EnvironmentTestUtils.addEnvironment(this.context,
82 | "ldap.embedded.partitionSuffix:dc=spring,dc=org");
83 | this.context.register(EmbeddedLdapAutoConfiguration.class,
84 | LdapClientConfiguration.class,
85 | PropertyPlaceholderAutoConfiguration.class);
86 | this.context.refresh();
87 | LDAPConnection connection = this.context
88 | .getBean(LDAPConnection.class);
89 | assertThat(connection.getConnectedPort())
90 | .isEqualTo(this.context.getEnvironment()
91 | .getProperty("local.ldap.port", Integer.class));
92 | }
93 |
94 | @Test
95 | public void testSetCredentials() throws LDAPException {
96 | load("ldap.embedded.partitionSuffix:dc=spring,dc=org",
97 | "ldap.embedded.credential.username:uid=root",
98 | "ldap.embedded.credential.password:boot");
99 | InMemoryDirectoryServer server = this.context
100 | .getBean(InMemoryDirectoryServer.class);
101 | BindResult result = server.bind("uid=root", "boot");
102 | assertThat(result).isNotNull();
103 | }
104 |
105 | @Test
106 | public void testSetPartitionSuffix() throws LDAPException {
107 | load("ldap.embedded.partitionSuffix:dc=spring,dc=org");
108 | InMemoryDirectoryServer server = this.context
109 | .getBean(InMemoryDirectoryServer.class);
110 | assertThat(server.getBaseDNs()).containsExactly(new DN("dc=spring,dc=org"));
111 | }
112 |
113 | @Test
114 | public void testSetLdifFile() throws LDAPException {
115 | load("ldap.embedded.partitionSuffix:dc=spring,dc=org",
116 | "ldap.embedded.ldif:classpath:schema.ldif");
117 | InMemoryDirectoryServer server = this.context
118 | .getBean(InMemoryDirectoryServer.class);
119 | assertThat(server.countEntriesBelow("ou=company1,c=Sweden,dc=spring,dc=org"))
120 | .isEqualTo(5);
121 | }
122 | @Test
123 | public void testQueryEmbeddedLdap() throws LDAPException {
124 | EnvironmentTestUtils.addEnvironment(this.context,
125 | "ldap.embedded.partitionSuffix:dc=spring,dc=org",
126 | "ldap.embedded.ldif:classpath:schema.ldif");
127 | this.context.register(EmbeddedLdapAutoConfiguration.class,
128 | LdapAutoConfiguration.class,
129 | LdapDataAutoConfiguration.class,
130 | PropertyPlaceholderAutoConfiguration.class);
131 | this.context.refresh();
132 | assertThat(this.context.getBeanNamesForType(LdapTemplate.class).length)
133 | .isEqualTo(1);
134 | LdapTemplate ldapTemplate = this.context
135 | .getBean(LdapTemplate.class);
136 | assertThat(ldapTemplate.list("ou=company1,c=Sweden,dc=spring,dc=org").size())
137 | .isEqualTo(4);
138 | }
139 |
140 | private void load(String... properties) {
141 | EnvironmentTestUtils.addEnvironment(this.context, properties);
142 | this.context.register(EmbeddedLdapAutoConfiguration.class,
143 | PropertyPlaceholderAutoConfiguration.class);
144 | this.context.refresh();
145 | }
146 |
147 | @Configuration
148 | static class LdapClientConfiguration {
149 |
150 | @Bean
151 | public LDAPConnection ldapConnection(@Value("${local.ldap.port}") int port)
152 | throws LDAPException {
153 | LDAPConnection con = new LDAPConnection();
154 | con.connect("localhost", port);
155 | return con;
156 | }
157 |
158 | }
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/ldap-spring-boot-autoconfigure/src/test/resources/schema.ldif:
--------------------------------------------------------------------------------
1 | dn: dc=spring,dc=org
2 | objectclass: top
3 | objectclass: domain
4 | objectclass: extensibleObject
5 | dc: spring
6 |
7 | dn: ou=groups,dc=spring,dc=org
8 | objectclass: top
9 | objectclass: organizationalUnit
10 | ou: groups
11 |
12 | dn: cn=ROLE_USER,ou=groups,dc=spring,dc=org
13 | objectclass: top
14 | objectclass: groupOfUniqueNames
15 | cn: ROLE_USER
16 | uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
17 | uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
18 | uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
19 | uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org
20 |
21 | dn: cn=ROLE_ADMIN,ou=groups,dc=spring,dc=org
22 | objectclass: top
23 | objectclass: groupOfUniqueNames
24 | cn: ROLE_ADMIN
25 | uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
26 |
27 | dn: c=Sweden,dc=spring,dc=org
28 | objectclass: top
29 | objectclass: country
30 | c: Sweden
31 | description: The country of Sweden
32 |
33 | dn: ou=company1,c=Sweden,dc=spring,dc=org
34 | objectclass: top
35 | objectclass: organizationalUnit
36 | ou: company1
37 | description: First company in Sweden
38 |
39 | dn: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
40 | objectclass: top
41 | objectclass: person
42 | objectclass: organizationalPerson
43 | objectclass: inetOrgPerson
44 | uid: some.person
45 | userPassword: password
46 | cn: Some Person
47 | sn: Person
48 | description: Sweden, Company1, Some Person
49 | telephoneNumber: +46 555-123456
50 |
51 | dn: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
52 | objectclass: top
53 | objectclass: person
54 | objectclass: organizationalPerson
55 | objectclass: inetOrgPerson
56 | uid: some.person2
57 | userPassword: password
58 | cn: Some Person2
59 | sn: Person2
60 | description: Sweden, Company1, Some Person2
61 | telephoneNumber: +46 555-654321
62 |
63 | dn: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org
64 | objectclass: top
65 | objectclass: person
66 | objectclass: organizationalPerson
67 | objectclass: inetOrgPerson
68 | uid: some.person3
69 | userPassword: password
70 | cn: Some Person3
71 | sn: Person3
72 | description: Sweden, Company1, Some Person3
73 | telephoneNumber: +46 555-123654
74 |
75 | dn: cn=Some Person4,ou=company1,c=Sweden,dc=spring,dc=org
76 | objectclass: top
77 | objectclass: person
78 | objectclass: organizationalPerson
79 | objectclass: inetOrgPerson
80 | uid: some.person4
81 | userPassword: password
82 | cn: Some Person
83 | sn: Person
84 | description: Sweden, Company1, Some Person
85 | telephoneNumber: +46 555-456321
86 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/odm/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | springBootVersion = '1.4.2.RELEASE'
4 | }
5 | repositories {
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
10 | }
11 | }
12 |
13 | apply plugin: 'java'
14 | apply plugin: 'eclipse'
15 | apply plugin: 'org.springframework.boot'
16 |
17 | jar {
18 | baseName = 'demo'
19 | version = '0.0.1-SNAPSHOT'
20 | }
21 | sourceCompatibility = 1.6
22 | targetCompatibility = 1.6
23 |
24 | repositories {
25 | mavenCentral()
26 | }
27 |
28 |
29 | dependencies {
30 | compile project(':ldap-spring-boot-starter')
31 | testCompile "org.springframework.boot:spring-boot-starter-test"
32 | testCompile "com.unboundid:unboundid-ldapsdk:3.2.0"
33 | }
34 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/odm/src/main/java/com/github/eddumelendez/sample/Application.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.sample;
18 |
19 | import org.springframework.boot.CommandLineRunner;
20 | import org.springframework.boot.SpringApplication;
21 | import org.springframework.boot.autoconfigure.SpringBootApplication;
22 |
23 | /**
24 | * @author Eddú Meléndez
25 | */
26 | @SpringBootApplication
27 | public class Application implements CommandLineRunner {
28 |
29 | private PersonRepository repository;
30 |
31 | public Application(PersonRepository repository) {
32 | this.repository = repository;
33 | }
34 |
35 | public static void main(String[] args) {
36 | SpringApplication.run(Application.class);
37 | }
38 |
39 | @Override
40 | public void run(String... args) throws Exception {
41 | Person person = this.repository.findByUid("some.person2");
42 | System.out.println(person);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/odm/src/main/java/com/github/eddumelendez/sample/Person.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.sample;
18 |
19 | import javax.naming.Name;
20 |
21 | import org.springframework.ldap.odm.annotations.Attribute;
22 | import org.springframework.ldap.odm.annotations.Entry;
23 | import org.springframework.ldap.odm.annotations.Id;
24 |
25 | /**
26 | * @author Eddú Meléndez
27 | */
28 | @Entry(objectClasses = {"person", "top"}, base = "ou=company1")
29 | public class Person {
30 |
31 | @Id
32 | private Name dn;
33 |
34 | @Attribute(name = "cn")
35 | private String fullName;
36 |
37 | public Name getDn() {
38 | return this.dn;
39 | }
40 |
41 | public void setDn(Name dn) {
42 | this.dn = dn;
43 | }
44 |
45 | public String getFullName() {
46 | return this.fullName;
47 | }
48 |
49 | public void setFullName(String fullName) {
50 | this.fullName = fullName;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return "Person{" +
56 | "dn=" + this.dn +
57 | ", fullName='" + this.fullName + '\'' +
58 | '}';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/odm/src/main/java/com/github/eddumelendez/sample/PersonRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.sample;
18 |
19 | import org.springframework.ldap.repository.LdapRepository;
20 | import org.springframework.ldap.repository.Query;
21 |
22 | /**
23 | * @author Eddú Meléndez
24 | */
25 | public interface PersonRepository extends LdapRepository {
26 |
27 | @Query("(uid={0})")
28 | Person findByUid(String uid);
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/odm/src/test/java/com/github/eddumelendez/sample/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.sample;
18 |
19 | import org.junit.ClassRule;
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 |
23 | import org.springframework.boot.test.context.SpringBootTest;
24 | import org.springframework.boot.test.rule.OutputCapture;
25 | import org.springframework.test.context.junit4.SpringRunner;
26 |
27 | import static org.assertj.core.api.Assertions.assertThat;
28 |
29 | /**
30 | * @author Eddú Meléndez
31 | */
32 | @RunWith(SpringRunner.class)
33 | @SpringBootTest
34 | public class ApplicationTests {
35 |
36 | @ClassRule
37 | public static OutputCapture output = new OutputCapture();
38 |
39 | @Test
40 | public void load() {
41 | assertThat(this.output.toString()).contains("cn=Some Person2");
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/odm/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | ldap.embedded.partitionSuffix=dc=spring,dc=org
2 | ldap.embedded.ldif=classpath:schema.ldif
3 | ldap.embedded.port=0
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/odm/src/test/resources/schema.ldif:
--------------------------------------------------------------------------------
1 | dn: dc=spring,dc=org
2 | objectclass: top
3 | objectclass: domain
4 | objectclass: extensibleObject
5 | dc: spring
6 |
7 | dn: ou=groups,dc=spring,dc=org
8 | objectclass: top
9 | objectclass: organizationalUnit
10 | ou: groups
11 |
12 | dn: cn=ROLE_USER,ou=groups,dc=spring,dc=org
13 | objectclass: top
14 | objectclass: groupOfUniqueNames
15 | cn: ROLE_USER
16 | uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
17 | uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
18 | uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
19 | uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org
20 |
21 | dn: cn=ROLE_ADMIN,ou=groups,dc=spring,dc=org
22 | objectclass: top
23 | objectclass: groupOfUniqueNames
24 | cn: ROLE_ADMIN
25 | uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
26 |
27 | dn: c=Sweden,dc=spring,dc=org
28 | objectclass: top
29 | objectclass: country
30 | c: Sweden
31 | description: The country of Sweden
32 |
33 | dn: ou=company1,c=Sweden,dc=spring,dc=org
34 | objectclass: top
35 | objectclass: organizationalUnit
36 | ou: company1
37 | description: First company in Sweden
38 |
39 | dn: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
40 | objectclass: top
41 | objectclass: person
42 | objectclass: organizationalPerson
43 | objectclass: inetOrgPerson
44 | uid: some.person
45 | userPassword: password
46 | cn: Some Person
47 | sn: Person
48 | description: Sweden, Company1, Some Person
49 | telephoneNumber: +46 555-123456
50 |
51 | dn: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
52 | objectclass: top
53 | objectclass: person
54 | objectclass: organizationalPerson
55 | objectclass: inetOrgPerson
56 | uid: some.person2
57 | userPassword: password
58 | cn: Some Person2
59 | sn: Person2
60 | description: Sweden, Company1, Some Person2
61 | telephoneNumber: +46 555-654321
62 |
63 | dn: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org
64 | objectclass: top
65 | objectclass: person
66 | objectclass: organizationalPerson
67 | objectclass: inetOrgPerson
68 | uid: some.person3
69 | userPassword: password
70 | cn: Some Person3
71 | sn: Person3
72 | description: Sweden, Company1, Some Person3
73 | telephoneNumber: +46 555-123654
74 |
75 | dn: cn=Some Person4,ou=company1,c=Sweden,dc=spring,dc=org
76 | objectclass: top
77 | objectclass: person
78 | objectclass: organizationalPerson
79 | objectclass: inetOrgPerson
80 | uid: some.person4
81 | userPassword: password
82 | cn: Some Person
83 | sn: Person
84 | description: Sweden, Company1, Some Person
85 | telephoneNumber: +46 555-456321
86 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/plain/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | springBootVersion = '1.4.2.RELEASE'
4 | }
5 | repositories {
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
10 | }
11 | }
12 |
13 | apply plugin: 'java'
14 | apply plugin: 'eclipse'
15 | apply plugin: 'org.springframework.boot'
16 |
17 | jar {
18 | baseName = 'demo'
19 | version = '0.0.1-SNAPSHOT'
20 | }
21 | sourceCompatibility = 1.6
22 | targetCompatibility = 1.6
23 |
24 | repositories {
25 | mavenCentral()
26 | }
27 |
28 |
29 | dependencies {
30 | compile project(':ldap-spring-boot-starter')
31 | testCompile "org.springframework.boot:spring-boot-starter-test"
32 | testCompile "com.unboundid:unboundid-ldapsdk:3.2.0"
33 | }
34 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/plain/src/main/java/com/github/eddumelendez/sample/Application.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.sample;
18 |
19 | import java.util.List;
20 |
21 | import org.springframework.boot.CommandLineRunner;
22 | import org.springframework.boot.SpringApplication;
23 | import org.springframework.boot.autoconfigure.SpringBootApplication;
24 | import org.springframework.ldap.core.LdapTemplate;
25 |
26 | /**
27 | * @author Eddú Meléndez
28 | */
29 | @SpringBootApplication
30 | public class Application implements CommandLineRunner {
31 |
32 | private LdapTemplate ldapTemplate;
33 |
34 | public Application(LdapTemplate ldapTemplate) {
35 | this.ldapTemplate = ldapTemplate;
36 | }
37 |
38 | public static void main(String[] args) {
39 | SpringApplication.run(Application.class);
40 | }
41 |
42 | @Override
43 | public void run(String... args) throws Exception {
44 | List members = this.ldapTemplate.list("ou=company1,c=Sweden,dc=spring,dc=org");
45 | for (String member : members) {
46 | System.out.println(member);
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/plain/src/test/java/com/github/eddumelendez/sample/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Eddu Melendez
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.eddumelendez.sample;
18 |
19 | import org.junit.ClassRule;
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 |
23 | import org.springframework.boot.test.context.SpringBootTest;
24 | import org.springframework.boot.test.rule.OutputCapture;
25 | import org.springframework.test.context.junit4.SpringRunner;
26 |
27 | import static org.assertj.core.api.Assertions.assertThat;
28 |
29 | /**
30 | * @author Eddú Meléndez
31 | */
32 | @RunWith(SpringRunner.class)
33 | @SpringBootTest
34 | public class ApplicationTests {
35 |
36 | @ClassRule
37 | public static OutputCapture output = new OutputCapture();
38 |
39 | @Test
40 | public void load() {
41 | assertThat(this.output.toString()).contains("cn=Some Person");
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/plain/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | ldap.embedded.partitionSuffix=dc=spring,dc=org
2 | ldap.embedded.ldif=classpath:schema.ldif
3 | ldap.embedded.port=0
--------------------------------------------------------------------------------
/ldap-spring-boot-samples/plain/src/test/resources/schema.ldif:
--------------------------------------------------------------------------------
1 | dn: dc=spring,dc=org
2 | objectclass: top
3 | objectclass: domain
4 | objectclass: extensibleObject
5 | dc: spring
6 |
7 | dn: ou=groups,dc=spring,dc=org
8 | objectclass: top
9 | objectclass: organizationalUnit
10 | ou: groups
11 |
12 | dn: cn=ROLE_USER,ou=groups,dc=spring,dc=org
13 | objectclass: top
14 | objectclass: groupOfUniqueNames
15 | cn: ROLE_USER
16 | uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
17 | uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
18 | uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
19 | uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org
20 |
21 | dn: cn=ROLE_ADMIN,ou=groups,dc=spring,dc=org
22 | objectclass: top
23 | objectclass: groupOfUniqueNames
24 | cn: ROLE_ADMIN
25 | uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
26 |
27 | dn: c=Sweden,dc=spring,dc=org
28 | objectclass: top
29 | objectclass: country
30 | c: Sweden
31 | description: The country of Sweden
32 |
33 | dn: ou=company1,c=Sweden,dc=spring,dc=org
34 | objectclass: top
35 | objectclass: organizationalUnit
36 | ou: company1
37 | description: First company in Sweden
38 |
39 | dn: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org
40 | objectclass: top
41 | objectclass: person
42 | objectclass: organizationalPerson
43 | objectclass: inetOrgPerson
44 | uid: some.person
45 | userPassword: password
46 | cn: Some Person
47 | sn: Person
48 | description: Sweden, Company1, Some Person
49 | telephoneNumber: +46 555-123456
50 |
51 | dn: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org
52 | objectclass: top
53 | objectclass: person
54 | objectclass: organizationalPerson
55 | objectclass: inetOrgPerson
56 | uid: some.person2
57 | userPassword: password
58 | cn: Some Person2
59 | sn: Person2
60 | description: Sweden, Company1, Some Person2
61 | telephoneNumber: +46 555-654321
62 |
63 | dn: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org
64 | objectclass: top
65 | objectclass: person
66 | objectclass: organizationalPerson
67 | objectclass: inetOrgPerson
68 | uid: some.person3
69 | userPassword: password
70 | cn: Some Person3
71 | sn: Person3
72 | description: Sweden, Company1, Some Person3
73 | telephoneNumber: +46 555-123654
74 |
75 | dn: cn=Some Person4,ou=company1,c=Sweden,dc=spring,dc=org
76 | objectclass: top
77 | objectclass: person
78 | objectclass: organizationalPerson
79 | objectclass: inetOrgPerson
80 | uid: some.person4
81 | userPassword: password
82 | cn: Some Person
83 | sn: Person
84 | description: Sweden, Company1, Some Person
85 | telephoneNumber: +46 555-456321
86 |
--------------------------------------------------------------------------------
/ldap-spring-boot-starter/build.gradle:
--------------------------------------------------------------------------------
1 | description = "Spring Boot LDAP Starter"
2 |
3 | dependencies {
4 | compile project(":ldap-spring-boot-autoconfigure")
5 | }
--------------------------------------------------------------------------------
/ldap-spring-boot-starter/src/main/resources/META-INF/spring.provides:
--------------------------------------------------------------------------------
1 | provides: ldap-spring-boot-autoconfigure
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'ldap-spring-boot'
2 |
3 | include 'ldap-spring-boot-autoconfigure'
4 | include 'ldap-spring-boot-samples/odm'
5 | include 'ldap-spring-boot-samples/plain'
6 | include 'ldap-spring-boot-starter'
--------------------------------------------------------------------------------