Принципиальный является нулевым: Весна - PullRequest
0 голосов
/ 21 октября 2018

У меня есть следующее @RestContoller для входа в систему:

  @RequestMapping("/account/login")
@ResponseBody
@CrossOrigin(origins = "*", maxAge = 3600)
public Principal login(Principal principal) {
    logger.info("user logged " + principal.getName());
    return principal;
}

У меня есть следующий запрос от клиента, который является приложением Angularjs.

Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,fa;q=0.8,it;q=0.7
Authorization: Basic bWVocmRhZGFsbGFoa2FyYW1pQGdtYWlsLmNvbTptZWhyZGFk
Connection: keep-alive
DNT: 1
Host: localhost:8080
Origin: http://localhost:4200
Referer: http://localhost:4200/login
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36

Однако я получаю 200 в ответ сервер печатает null и клиент получает в ответ ошибку:

HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "OK", url: "http://localhost:8080/account/login", ok: false, …}error: {timestamp: 1540136257516, status: 400, error: "Bad Request", exception: "org.springframework.web.bind.ServletRequestBindingException", message: "Missing request header 'header' for method parameter of type Header", …}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}message: "Http failure response for http://localhost:8080/account/login: 400 OK"name: "HttpErrorResponse"ok: falsestatus: 400statusText: "OK"url: "http://localhost:8080/account/login"__proto__: HttpResponseBase

Может кто-нибудь помочь мне узнать, в чем я не прав?Он работал раньше, но я использовал перехватчики в Angular, и он больше не работает.

Мой контроллер входа в систему выглядит так:

@Injectable()
export class AuthService {
  constructor(public http: HttpClient, public auth: InterceptorAuthService) {
  }

  public logIn(user: User) {
    this.auth.setUser(user);
    return this.http.get(AppComponent.API_URL + "/account/login")
      .pipe(
        map(response => {
            // login successful if there's a jwt token in the response
            let user = response;// the returned user object is a principal object
            if (user) {
              // store user details  in local storage to keep user logged in between page refreshes
              localStorage.setItem('currentUser', JSON.stringify(user));
            }
          },
          catchError(error => {
            return Observable.throw(error);
          })
        ));
  }
}

Конфигурация WebConfig.java:

// This method is used for override HttpSecurity of the web Application.
// We can specify our authorization criteria inside this method.
@Override
protected void configure(HttpSecurity http) throws Exception {
    // @formatter:off
    // ignoring the guest's urls "
    http.antMatcher("/account/**").authorizeRequests().anyRequest().authenticated().and()
            .antMatcher("/token").authorizeRequests().anyRequest().authenticated()
            .antMatchers("/logout").permitAll()
            .and()
            .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).and()
            .httpBasic();
    // authenticate all remaining URLS

    // @formatter:on
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...