首页>代码>Spring Boot整合Spring Security + Spring LDAP实现用户登录权限验证配置实例>/ldap-auth/src/main/java/com/memorynotfound/ldap/config/WebSecurityConfig.java
package com.memorynotfound.ldap.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.encoding.LdapShaPasswordEncoder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.ldap.DefaultSpringSecurityContextSource; import java.util.Collections; @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/managers").hasRole("MANAGERS") .antMatchers("/employees").hasRole("EMPLOYEES") .anyRequest().fullyAuthenticated() .and() .formLogin(); } @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth .ldapAuthentication() .userDnPatterns("uid={0},ou=people") .groupSearchBase("ou=groups") .contextSource(contextSource()) .passwordCompare() .passwordEncoder(new LdapShaPasswordEncoder()) .passwordAttribute("userPassword"); } @Bean public DefaultSpringSecurityContextSource contextSource() { return new DefaultSpringSecurityContextSource( Collections.singletonList("ldap://localhost:12345"), "dc=zuidaima,dc=com"); } }

没有眼的鱼 LV1
2023年12月22日
C544350851 LV26
2023年11月24日
forsaken123 LV1
2023年5月26日
evagsd LV6
2022年5月30日
1byte8bit LV8
2022年5月28日
zlfsgg LV3
2022年4月26日
笛卡尔积 LV6
2022年1月18日
山水一程 LV1
2021年10月18日
在线不是本人 LV12
2021年9月4日
湿巾不湿 LV1
2021年8月18日

f22m1a2b2 LV17
1月23日
lrj41781196 LV2
2024年9月2日
ma406805131 LV19
2024年6月15日
taoshen95 LV16
2024年5月15日
没有眼的鱼 LV1
2023年12月22日
C544350851 LV26
2023年11月24日
duon12 LV1
2023年9月25日
forsaken123 LV1
2023年5月26日
懒耗子 LV3
2023年4月22日
随便取个名字_哈哈 LV27
2023年4月19日