【发布时间】:2015-04-11 18:50:12
【问题描述】:
在我的 Web 应用程序中,我必须使用 Spring Security 并使用 LDAP 获取用户的身份验证详细信息,并使用 JDBC 获取用户的授权详细信息。用户提交表单,我从中获取用户名和密码。
- 如何在我的
WebSecurityConfig文件中获取用户名和密码? - 如何配置授权和身份验证?
我的WebSecurityConfig:
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().formLogin()
.loginPage("/").permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth.ldapAuthentication().userDnPatterns("uid={0},ou=people")
.groupSearchBase("ou=groups").contextSource(contextSource());
}
@Bean
public DefaultSpringSecurityContextSource contextSource() {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
"ldap://mjkoldc-03.red.com");
contextSource.setUserDn("mj\\" + email);
contextSource.setPassword(password);
contextSource.setReferral("follow");
contextSource.afterPropertiesSet();
return contextSource;
}
}
之前我使用LDAPTemplate获取详细信息:
LdapQuery query = query().base("dc=metaljunction,dc=com")
.attributes("GivenName", "sn", "mail", "MobilePhone")
.where("ObjectClass").is("user").and("SamAccountName")
.is(email);
【问题讨论】:
标签: spring spring-mvc spring-security ldap spring-ldap