나는이 가이드 다음 내 봄 백엔드에 JWT를 추가 : https://auth0.com/blog/securing-spring-boot-with-jwts/JWT
나는 즉시 난으로 우편 배달 모든 것이 잘 작동과 같은 소프트웨어를 사용하여 PUT 요청하지만를 보낼 때 의 데이터가 내 Angular 클라이언트에 로그인하려고 시도하면 비어 있습니다.
@Override
public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res)
throws AuthenticationException, IOException, ServletException {
String reqBody = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
// this appears to be empty on angular client calls
System.out.println(reqBody);
ObjectMapper objectMapper = new ObjectMapper().configure(Feature.AUTO_CLOSE_SOURCE, true)
.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
AccountCredentials creds = objectMapper.readValue(reqBody, AccountCredentials.class);
return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(creds.getUsername(),
creds.getPassword(), Collections.emptyList()));
}
이 같은 클라이언트로부터 요청을 보내고있다 :
const user = {
username: "asdf",
password: "asdf"
};
// imported from '@angular/http'
const headers = new Headers({
'Content-Type': 'application/json'
});
const body = JSON.stringify(user);
return this.http
.put("http://localhost:8080/api/login", body, {headers})
.toPromise()
.then(response => response.json().data as User)
.catch(this.handleError);
나의 제안 것
나는 다음과 같은 방법으로 JWTLoginFilter
의 attemptAuthentication
방법으로 데이터를 확인 요청 본문을 잘못된 방법으로 보냈지 만, 내가 뭘 잘못하고 있는지 알 수 없습니다.
는 I 시도 대신 POST을 사용하여 실시 예
- 그것이 다른 목적 JSON 문자열로 전송
- 래핑 송신 일반 JS 객체
- 으로 몸을 보내는 (PUT의 PUT과 작동 함에도 불구하고)
- Content-Type 헤더를 다른 값으로 변경
이 데이터가 백엔드에 표시되지 않았습니다.
더 자세한 정보가 필요하면 제게 문의하십시오.
당신은'spring-security-oauth2' 의존성을 사용하고 있습니까? –
@PraveenM 아니요, 저는'spring-boot-starter-security @ 1.5.8.RELEASE'와'jjwt @ 0.7.0'을 사용하고 있습니다. – Froxx