spring-boot 中的多个身份验证提供程序不适用于 angulr js

时间:2021-01-21 13:28:55

标签: angularjs spring-security-ldap

我有 Spring Boot 应用程序,其中 db 身份验证已经到位。现在我已经添加了 LDAP 身份验证。为此,我配置了多个身份验证提供程序。 现在,如果我点击 /user 端点从浏览器登录,db 和 ldap 身份验证都在工作。 但是从 angular js 代码来看,只有 db 身份验证有效。 我的代码如下所示:

auth.js:-

 authenticate : function($scope, credentials, callback) {
  var headers = credentials && credentials.updatedUseremail ? {
                    authorization : "Basic "
                            + btoa(credentials.updatedUseremail + ":"
                                    + credentials.password)
                } : {cache:false};

                $http.get('user', {
                    headers : headers
                }).success(function(data) {                     
                    if (data.username) {    
                           auth.authenticated = true;
                      }
                     } else {
                        auth.authenticated = false;

                    }

SecurityConfig.java:-

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {

  authenticationProvider.setPasswordEncoder(jasyptEncoder());
  authenticationProvider.setUserDetailsService(userDetailsService);
  auth.authenticationProvider(authenticationProvider);
 
 auth.ldapAuthentication().userDetailsContextMapper(userDetailsContextMapper()).
 ldapAuthoritiesPopulat or(new UserDetailsServiceLdapAuthoritiesPopulator(userDetailsService))
.userDnPatterns("uid={0},ou=people")
.userSearchBase("ou=groups")
.contextSource()
.url("ldap://localhost:8389/dc=devglan,dc=com")
.and()
.passwordCompare()
.passwordEncoder(jasyptEncoder())
            .passwordAttribute("userPassword");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
      
    http.httpBasic().
    authenticationEntryPoint(failureHandler)
    .and().authorizeRequests()
    .antMatchers("/login").permitAll()
    .anyRequest()
    .authenticated()
    .and().exceptionHandling().accessDeniedHandler(accessDeniedExceptionHandler)
    .and()
    .addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
    .csrf().csrfTokenRepository(csrfTokenRepository());
   
  
}

0 个答案:

没有答案