我正在开发我的第一个Angular项目。现在我被要求在应用程序中实现LDAP安全性。因此,在我跟进this和this后,我可以看到登录屏幕,它也会对AD进行验证。但问题是我看到了浏览器身份验证弹出窗口。我不确定它是Angular还是Spring安全配置问题。任何请你会很棒!
WebSecurityConfiguration.java
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
private static final Logger log = LoggerFactory.getLogger(WebSecurityConfiguration.class);
LdapConfiguration ldapConfig;
ActiveProfilesConfiguration activeProfiles;
SecurityUserConfiguration securityUser;
SimpleAuthenticationSuccessHandler authenticationSuccessHandler;
public WebSecurityConfiguration(LdapConfiguration ldapConfig,
ActiveProfilesConfiguration activeProfiles,
SecurityUserConfiguration securityUser,
SimpleAuthenticationSuccessHandler authenticationSuccessHandler) {
this.ldapConfig = ldapConfig;
this.activeProfiles = activeProfiles;
this.securityUser = securityUser;
this.authenticationSuccessHandler = authenticationSuccessHandler;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic().and()
.authorizeRequests()
// .antMatchers("/**").permitAll()
.antMatchers("/index.html", "/", "/home", "/login").permitAll()
.anyRequest().authenticated()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
app.module.ts
@Injectable()
export class XhrInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler) {
const xhr = req.clone({
headers: req.headers.set('X-Requested-With', 'XMLHttpRequest')
});
return next.handle(xhr);
}
}