Не удается получить базовый c запрос на авторизацию от Ax ios до бэкэнда Spring-security oauth2 - PullRequest
1 голос
/ 09 марта 2020

Я пытаюсь отправить запрос на аутентификацию Ax ios из React Native на сторону сервера Spring Security. Однако на контроллере на стороне сервера я ничего не получаю (принцип = ноль). Мой веб-интерфейс:

 login(user) {
 const headers = {
  Authorization: 'Basic ' + btoa(user.email + ':' + user.password)
};
console.log(headers)
return axios.get(API_URL + 'login', {headers: headers})
    .then(response => {
    console.log('function called')

Мой бэкэнд находится здесь:

    @RequestMapping(value = {"/login"}, method = RequestMethod.GET) 
public ResponseEntity<?> login(Principal principal) { //when debuging: principal==null
    if(principal == null){
        //logout will also use here so we should return ok http status.
        return (ResponseEntity<?>) ResponseEntity.badRequest();
    }
    UsernamePasswordAuthenticationToken authenticationToken =
            (UsernamePasswordAuthenticationToken) principal;

Заголовки генерируются как токены и отправляются в виде чего-то вроде:

[{"key": "Authorization", "value": "Basi c dGVzdDoxMjM0", "description": ""}] Так что не знаю, почему Spring ничего не получает. Настройки Spring Security:

 protected void configure(HttpSecurity http) throws Exception {

            http.
            authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/login").permitAll()
            .antMatchers("/admin/**").hasAuthority("ADMIN").anyRequest()
            .authenticated().and().csrf().disable().formLogin()
            .loginPage("/login").failureUrl("/login?error=true")
            .defaultSuccessUrl("/admin/home")
            .usernameParameter("email")
            .passwordParameter("password")
            .and().logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/").and().exceptionHandling()
            .accessDeniedPage("/access-denied");

        @Bean
        public WebMvcConfigurer corsConfigurer(){
        return new WebMvcConfigurer() {

        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedOrigins("*").allowedMethods("*");
        }
    };
}

Есть ли что-то еще, что мне нужно настроить, чтобы Spring мог принимать запросы с параметром Principal? Или есть что-то еще, что мешает ему увидеть любое отправленное значение?

...