亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

LDAP:在身份驗證事件期間獲取自定義值

LDAP:在身份驗證事件期間獲取自定義值

眼眸繁星 2022-12-15 16:07:36
我讓 Springboot 成功地對 LDAP 進行了身份驗證并向視圖添加了一個CustomUserDetails模型。在身份驗證活動期間,我還想帶回其他詳細信息,如電子郵件、電話和城市。根據this SO answer,這是可能的,我認為這也解決了這個問題。盡管閱讀了這兩個答案,但我仍然不確定如何繼續執行此操作 - 特別是關于第二個答案的步驟 2 和 3 如何關聯,以及電子郵件、城市和電話等詳細信息映射到哪里?我的安全等級:安全@SpringBootApplicationpublic class ApplicationSecurity extends WebSecurityConfigurerAdapter {@Autowiredprivate UserDetailsService userDetailsService;@Overridepublic void configure(HttpSecurity http) throws Exception {    http            .authorizeRequests()                .anyRequest().fullyAuthenticated()                .and()            .formLogin()                .defaultSuccessUrl("/newExhibit");}@Overridepublic void configure(AuthenticationManagerBuilder auth) throws Exception {    auth            .userDetailsService(userDetailsService)            .and()            .ldapAuthentication()            .userDnPatterns("uid={0},ou=people")            .groupSearchBase("ou=groups")            .contextSource()            .url("ldap://localhost:8389/dc=springframework,dc=org")            .and()            .passwordCompare()            .passwordEncoder(passwordEncoder())            .passwordAttribute("userPassword");}我的用戶對象來自 test-server.ldifdn: uid=abc123,ou=people,dc=springframework,dc=orgobjectclass: topobjectclass: personobjectclass: organizationalPersonobjectclass: inetOrgPersoncn: Tom Smithsn: Smithuid: abc123userPassword: passmail: [email protected]: +212 307 12345st: CA
查看完整描述

1 回答

?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

查看您的 LDIF 文件,您似乎正在嘗試獲取定義為inetOrgPerson的一部分的屬性。Spring Security 為這個InetOrgPersonContextMapper. 這會將定義的屬性映射到InetOrgPerson,這將根據UserDetails需要進行操作。

要配置您只需要創建一個新實例并將其連接到您的配置。

@SpringBootApplication

public class ApplicationSecurity extends WebSecurityConfigurerAdapter {



@Override

public void configure(AuthenticationManagerBuilder auth) throws Exception {

    auth

      .ldapAuthentication()

        .userDnPatterns("uid={0},ou=people")

        .groupSearchBase("ou=groups")

        .contextSource()

        .url("ldap://localhost:8389/dc=springframework,dc=org")

        .and()

        .userDetailsContextMapper(new InetOrgPersonContextMapper())

        .passwordCompare()

        .passwordEncoder(passwordEncoder())

        .passwordAttribute("userPassword");

}

這將相應地映射屬性。當您使用 LDAP 時,您不需要UserDetailsService注入,因為它會自動配置LdapUserDetailsService底層。


查看完整回答
反對 回復 2022-12-15
  • 1 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號