find current user by token

This commit is contained in:
dartpopikyardo
2016-03-11 21:10:50 +03:00
parent 21d21b9833
commit 28216a082d

View File

@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.token.Token;
import org.springframework.security.core.token.TokenService;
import org.springframework.validation.annotation.Validated;
@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.io.IOException;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
/**
@@ -49,4 +52,13 @@ public class AuthController {
public ErrorResponse customersNotFound() {
return new ErrorResponse("Customer not found");
}
@RequestMapping(value = "/user", method = GET)
public ResponseEntity<QuerySideCustomer> getCurrentUser() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
return ResponseEntity.status(HttpStatus.OK).body(customerAuthService.findByEmail(auth.getName()));
}
}