Я разрабатываю приложение с Angular 7 и Spring Boot.
Моя проблема с запросом авторизации.
Я много искал, и все решения, которые я нашел, такие же, как в моем коде, но проблема в том, что запросы хорошо работают с Postman, а с Angular не работают.
это ошибка
![enter image description here](https://i.stack.imgur.com/jvP4F.png)
и это мой профиль службы:
getEmployeeById(id: number) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('user:userPass'),
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token'
})
};
return this.http.get<UserProfile>( this.baseUrl.oneEmployee.replace(':id', id),
httpOptions) ;
}
и это конфигурация безопасности при загрузке Spring:
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password(encoder().encode("adminPass")).roles("ADMIN")
.and()
.withUser("user").password(encoder().encode("userPass")).roles("USER");
}
@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
/*http
.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic();*/
//http.addFilterBefore(new CorsFilter(), ChannelProcessingFilter.class);
http.authorizeRequests().antMatchers("/").permitAll()
.anyRequest().fullyAuthenticated().and().httpBasic().and().csrf().disable();
}