我正在尝试创建一个可通过活动目录身份验证访问的网页。我成功连接并可以验证凭据。提交不正确的登录后,终端将显示:Active Directory authentication failed: Supplied password was invalid
。正确的凭据不会在终端上显示任何内容。
问题是我“成功”登录网页后未显示。而是,登录窗口会持续显示,并且不会重定向。凭据经过身份验证后,如何进入网页?下面是我正在使用的代码。
@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);
}
}
@RestController
public class Controller {
@GetMapping("/")
public String index() {
return "home page";
}
}
@Configuration
@SpringBootApplication
public class App {
public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
}
}