From 1afe74766ec76850fa08d03581d8c50055277dde Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 6 Apr 2017 00:03:39 +0300 Subject: juick-server: refactor HashParamAuthenticationFilter using Spring WebUtils --- .../security/HashParamAuthenticationFilter.java | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server') diff --git a/juick-server/src/main/java/com/juick/server/security/HashParamAuthenticationFilter.java b/juick-server/src/main/java/com/juick/server/security/HashParamAuthenticationFilter.java index d1358a20..b384a8c8 100644 --- a/juick-server/src/main/java/com/juick/server/security/HashParamAuthenticationFilter.java +++ b/juick-server/src/main/java/com/juick/server/security/HashParamAuthenticationFilter.java @@ -10,6 +10,7 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.RememberMeServices; import org.springframework.util.Assert; import org.springframework.web.filter.OncePerRequestFilter; +import org.springframework.web.util.WebUtils; import javax.servlet.FilterChain; import javax.servlet.ServletException; @@ -71,19 +72,12 @@ public class HashParamAuthenticationFilter extends OncePerRequestFilter { } private String getHashFromRequest(HttpServletRequest request) { - String hash = request.getHeader(PARAM_NAME); + String paramHash = request.getParameter(PARAM_NAME); + Cookie cookieHash = WebUtils.getCookie(request, PARAM_NAME); - if (hash == null) - hash = request.getParameter(PARAM_NAME); - - Cookie[] cookies = request.getCookies(); - - if (hash == null && cookies != null) - for (Cookie cookie : cookies) - if (PARAM_NAME.equals(cookie.getName())) { - hash = cookie.getValue(); - break; - } - return hash; + if (paramHash == null && cookieHash != null) { + return cookieHash.getValue(); + } + return paramHash; } } -- cgit v1.2.3