成功登录后,Spring Boot Active Directory身份验证未重定向

时间:2018-09-11 17:29:29

标签: java spring-boot active-directory ldap

我正在尝试创建一个可通过活动目录身份验证访问的网页。我成功连接并可以验证凭据。提交不正确的登录后,终端将显示:Active Directory authentication failed: Supplied password was invalid。正确的凭据不会在终端上显示任何内容。

问题是我“成功”登录网页后未显示。而是,登录窗口会持续显示,并且不会重定向。凭据经过身份验证后,如何进入网页?下面是我正在使用的代码。

ADConfig.java

@Configuration
@EnableWebSecurity
public class ADConfig extends WebSecurityConfigurerAdapter {

    @Value("${ad_domain}")
    private String AD_DOMAIN;

    @Value("${ad_url}")
    private String AD_URL;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().fullyAuthenticated()
            .and()
                .httpBasic();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        ActiveDirectoryLdapAuthenticationProvider adProvider =
            new ActiveDirectoryLdapAuthenticationProvider(AD_DOMAIN, AD_URL);
        adProvider.setConvertSubErrorCodesToExceptions(true);
        adProvider.setUseAuthenticationRequestCredentials(true);

        auth.authenticationProvider(adProvider);
        auth.eraseCredentials(false);
    }
}

Controller.java

@RestController
public class Controller {
    @GetMapping("/")
    public String index() {
        return "home page";
   }
}

App.java

@Configuration
@SpringBootApplication
public class App {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(App.class, args);
    }
}

0 个答案:

没有答案