From 90221e91053db4649d02e6bdc50dc97360c5f1f2 Mon Sep 17 00:00:00 2001 From: Alex Prudencio Date: Wed, 14 Aug 2024 22:45:28 -0400 Subject: [PATCH] adding ldap test server --- pom.xml | 4 ++ .../config/SecurityConfig.java | 2 +- src/main/resources/application.properties | 15 +++++-- src/main/resources/logback.xml | 11 +++++ src/main/resources/test-server.ldif | 43 +++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/logback.xml create mode 100644 src/main/resources/test-server.ldif diff --git a/pom.xml b/pom.xml index 343c2c0..f07d625 100644 --- a/pom.xml +++ b/pom.xml @@ -92,6 +92,10 @@ org.springframework.security spring-security-ldap + + com.unboundid + unboundid-ldapsdk + org.springframework.boot spring-boot-starter-validation diff --git a/src/main/java/com/primefactorsolutions/config/SecurityConfig.java b/src/main/java/com/primefactorsolutions/config/SecurityConfig.java index 7fb147d..8d10f24 100644 --- a/src/main/java/com/primefactorsolutions/config/SecurityConfig.java +++ b/src/main/java/com/primefactorsolutions/config/SecurityConfig.java @@ -39,7 +39,7 @@ public class SecurityConfig extends VaadinWebSecurity { @Bean public AuthenticationManager authenticationManager() { DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( - "ldap://ldap.primefactorsolutions.com:389/dc=primefactorsolutions,dc=com"); + "ldap://localhost:8389/dc=primefactorsolutions,dc=com"); contextSource.setCacheEnvironmentProperties(false); LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource); factory.setUserDnPatterns("uid={0},ou=users"); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 71a5dac..39a0612 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -17,16 +17,25 @@ spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.required=true +spring.ldap.embedded.ldif=classpath:test-server.ldif +spring.ldap.embedded.base-dn=dc=primefactorsolutions,dc=com +spring.ldap.embedded.port=8389 + # spring.datasource.url=jdbc:h2:mem:testdb # spring.datasource.url=jdbc:h2:file:./db # spring.datasource.url=jdbc:h2:file:/var/opt/pfs/db spring.datasource.url=${DB_URL:jdbc:h2:mem:testdb} -spring.jpa.hibernate.ddl-auto=update -spring.sql.init.mode=${SQL_INIT:embedded} spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password=${H2_PASS:sa} -spring.h2.console.settings.web-allow-others=true + +spring.jpa.show-sql=true +# spring.jpa.properties.hibernate.format_sql=true +spring.jpa.hibernate.ddl-auto=update spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.defer-datasource-initialization = true + +spring.sql.init.mode=${SQL_INIT:embedded} + spring.h2.console.enabled=true +spring.h2.console.settings.web-allow-others=true diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..4bd2e37 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,11 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/src/main/resources/test-server.ldif b/src/main/resources/test-server.ldif new file mode 100644 index 0000000..7b2afdb --- /dev/null +++ b/src/main/resources/test-server.ldif @@ -0,0 +1,43 @@ +dn: dc=primefactorsolutions,dc=com +objectclass: top +objectclass: domain +objectclass: extensibleObject +dc: primefactorsolutions + +dn: ou=groups,dc=primefactorsolutions,dc=com +objectclass: top +objectclass: organizationalUnit +ou: groups + +dn: ou=users,dc=primefactorsolutions,dc=com +objectclass: top +objectclass: organizationalUnit +ou: users + +dn: uid=ben,ou=users,dc=primefactorsolutions,dc=com +objectclass: top +objectclass: person +objectclass: organizationalPerson +objectclass: inetOrgPerson +cn: Ben User +sn: BenUser +uid: ben +userPassword: $2a$10$c6bSeWPhg06xB1lvmaWNNe4NROmZiSpYhlocU/98HNr2MhIOiSt36 + +dn: uid=bob,ou=users,dc=primefactorsolutions,dc=com +objectclass: top +objectclass: person +objectclass: organizationalPerson +objectclass: inetOrgPerson +cn: Bob User +sn: BobUser +uid: bob +userPassword: bobspassword + +dn: cn=employees,ou=groups,dc=primefactorsolutions,dc=com +objectclass: top +objectclass: groupOfUniqueNames +cn: employees +ou: groups +uniqueMember: uid=ben,ou=users,dc=primefactorsolutions,dc=com +uniqueMember: uid=bob,ou=users,dc=primefactorsolutions,dc=com