Revert "Retrieve token from cookie only when checking an authenticated eperson"

This reverts commit 10bbf8079b.
This commit is contained in:
Giuseppe Digilio
2020-01-09 12:08:55 +01:00
parent 10bbf8079b
commit e5074004f4

View File

@@ -87,7 +87,7 @@ public class JWTTokenRestAuthenticationServiceImpl implements RestAuthentication
@Override
public EPerson getAuthenticatedEPerson(HttpServletRequest request, Context context) {
String token = getToken(request, true);
String token = getToken(request);
try {
EPerson ePerson = jwtTokenHandler.parseEPersonFromToken(token, request, context);
return ePerson;
@@ -110,7 +110,7 @@ public class JWTTokenRestAuthenticationServiceImpl implements RestAuthentication
@Override
public void invalidateAuthenticationData(HttpServletRequest request, HttpServletResponse response,
Context context) throws Exception {
String token = getToken(request, false);
String token = getToken(request);
Cookie cookie = new Cookie(AUTHORIZATION_COOKIE, "");
cookie.setHttpOnly(true);
response.addCookie(cookie);
@@ -156,10 +156,10 @@ public class JWTTokenRestAuthenticationServiceImpl implements RestAuthentication
response.setHeader(AUTHORIZATION_HEADER, String.format("%s %s", AUTHORIZATION_TYPE, token));
}
private String getToken(HttpServletRequest request, Boolean useCookie) {
private String getToken(HttpServletRequest request) {
String tokenValue = null;
String authHeader = request.getHeader(AUTHORIZATION_HEADER);
String authCookie = useCookie ? getAuthorizationCookie(request) : "";
String authCookie = getAuthorizationCookie(request);
if (StringUtils.isNotBlank(authHeader)) {
tokenValue = authHeader.replace(AUTHORIZATION_TYPE, "").trim();
} else if (StringUtils.isNotBlank(authCookie)) {