SPRING IN ACTION 第4版笔记-第九章Securing web applications-005-Applying LDAP-backed authentication

一、

1.This method is the  LDAP analog to  jdbcAuthentication() 

1 @Override
2 protected void configure(AuthenticationManagerBuilder auth)
3 throws Exception {
4     auth
5         .ldapAuthentication()
6         .userSearchFilter("(uid={0})")
7         .groupSearchFilter("member={0}");
8 }

The userSearchFilter() and groupSearchFilter() methods are used to provide a filter for the base LDAP queries, which are used to search for users and groups. By default, the base queries for both users and groups are empty, indicating that the search will be done from the root of the LDAP hierarchy. But you can change that by specifying a query base:

 1 @Override
 2 protected void configure(AuthenticationManagerBuilder auth)
 3 throws Exception {
 4     auth
 5         .ldapAuthentication()
 6         .userSearchBase("ou=people")
 7         .userSearchFilter("(uid={0})")
 8         .groupSearchBase("ou=groups")
 9         .groupSearchFilter("member={0}");
10 }

The userSearchBase() method provides a base query for finding users. Likewise, the groupSearchBase() specifies the base query for finding groups. Rather than search from the root, this example specifies that users be searched for where the organization unit is people . And groups should be searched for where the organizational unit is groups .

posted @ 2016-03-07 13:21  shamgod  阅读(281)  评论(0编辑  收藏  举报
haha