Skip to content

Commit c5eb1c5

Browse files
committed
modify ldap configuration
1 parent 93d6e3f commit c5eb1c5

5 files changed

Lines changed: 44 additions & 30 deletions

File tree

‎spring-security-mvc-ldap/pom.xml‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,13 @@
3535
<artifactId>spring-security-ldap</artifactId>
3636
</dependency>
3737

38-
<dependency>
39-
<groupId>org.springframework.ldap</groupId>
40-
<artifactId>spring-ldap-core</artifactId>
41-
<version>2.0.3.RELEASE</version>
42-
</dependency>
43-
<dependency>
44-
<groupId>org.springframework.ldap</groupId>
45-
<artifactId>spring-ldap-core-tiger</artifactId>
46-
<version>2.0.3.RELEASE</version>
47-
</dependency>
48-
4938
<dependency>
5039
<!-- Is the ApacheDS server - 1.5.6 and 1.5.7 don't work -->
5140
<groupId>org.apache.directory.server</groupId>
5241
<artifactId>apacheds-server-jndi</artifactId>
5342
<version>1.5.5</version>
5443
</dependency>
55-
<dependency>
56-
<groupId>org.apache.mina</groupId>
57-
<artifactId>mina-core</artifactId>
58-
<version>2.0.9</version>
59-
</dependency>
60-
44+
6145
</dependencies>
6246

6347
<build>
@@ -74,7 +58,6 @@
7458
<plugin>
7559
<groupId>org.apache.maven.plugins</groupId>
7660
<artifactId>maven-compiler-plugin</artifactId>
77-
<version>${maven-compiler-plugin.version}</version>
7861
<configuration>
7962
<source>1.8</source>
8063
<target>1.8</target>

‎spring-security-mvc-ldap/src/main/java/org/baeldung/SampleLDAPApplication.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
55
import org.springframework.context.annotation.ComponentScan;
6-
import org.springframework.scheduling.annotation.EnableScheduling;
76
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
87
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
98

109
/**
1110
* Main Application Class - uses Spring Boot. Just run this as a normal Java
1211
* class to run up a Jetty Server (on http://localhost:8080)
13-
*
12+
*
1413
*/
15-
@EnableScheduling
1614
@EnableAutoConfiguration
1715
@ComponentScan("org.baeldung")
1816
public class SampleLDAPApplication extends WebMvcConfigurerAdapter {
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
package org.baeldung.security;
22

3-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4-
import org.springframework.context.annotation.ComponentScan;
3+
import org.springframework.context.annotation.Configuration;
54
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
65
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
76
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8-
import org.springframework.stereotype.Controller;
97

108
/**
119
* Security Configuration - LDAP and HTTP Authorizations.
1210
*/
13-
@EnableAutoConfiguration
14-
@ComponentScan
15-
@Controller
11+
@Configuration
12+
// @ImportResource({ "classpath:webSecurityConfig.xml" })
1613
public class SecurityConfig extends WebSecurityConfigurerAdapter {
1714

1815
@Override
1916
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
20-
auth.ldapAuthentication().userSearchBase("ou=people").userSearchFilter("(uid={0})").groupSearchBase("ou=groups").groupSearchFilter("member={0}").contextSource().root("dc=baeldung,dc=com").ldif("classpath:users.ldif");
17+
auth.ldapAuthentication().userSearchBase("ou=people").userSearchFilter("(uid={0})").groupSearchBase("ou=groups").groupSearchFilter("(member={0})").contextSource().root("dc=baeldung,dc=com").ldif("classpath:users.ldif");
2118
}
2219

2320
@Override
2421
protected void configure(HttpSecurity http) throws Exception {
2522
http.authorizeRequests().antMatchers("/", "/home").permitAll().anyRequest().authenticated();
26-
http.formLogin().loginPage("/login").permitAll().and().logout().logoutSuccessUrl("/");
23+
http.formLogin().loginPage("/login").permitAll().loginProcessingUrl("/j_spring_security_check").and().logout().logoutSuccessUrl("/");
2724
}
2825

2926
}

‎spring-security-mvc-ldap/src/main/resources/templates/login.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<p th:if="${param.logout}" class="alert">You have been logged out</p>
2222
<p th:if="${param.error}" class="alert alert-error">There was an error, please try again</p>
2323
<h2>Login with Username and Password</h2>
24-
<form name="form" th:action="@{/login}" action="/login" method="POST">
24+
<form name="form" th:action="@{/j_spring_security_check}" action="/login" method="POST">
2525
<fieldset>
2626
<input type="text" name="username" value="" placeholder="Username" />
2727
<input type="password" name="password" placeholder="Password" />
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
3+
xsi:schemaLocation="
4+
http://www.springframework.org/schema/security
5+
http://www.springframework.org/schema/security/spring-security.xsd
6+
http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd"
8+
>
9+
10+
<http auto-config="true" use-expressions="true">
11+
<intercept-url pattern="/" access="permitAll"/>
12+
<intercept-url pattern="/home" access="permitAll"/>
13+
<intercept-url pattern="/login" access="permitAll"/>
14+
<intercept-url pattern="/secure" access="isAuthenticated()"/>
15+
16+
<form-login login-page='/login' default-target-url="/"
17+
authentication-failure-url="/login?error"
18+
username-parameter="username"
19+
password-parameter="password"/>
20+
<logout logout-success-url="/" />
21+
</http>
22+
23+
<authentication-manager>
24+
<ldap-authentication-provider
25+
user-search-base="ou=people"
26+
user-search-filter="(uid={0})"
27+
group-search-base="ou=groups"
28+
group-search-filter="(member={0})"
29+
>
30+
</ldap-authentication-provider>
31+
</authentication-manager>
32+
33+
<ldap-server root="dc=baeldung,dc=com" ldif="users.ldif"/>
34+
35+
36+
</beans:beans>

0 commit comments

Comments
 (0)