@Test void setCookies_accessTokenNull() { HttpServletResponse response = Mockito.mock(HttpServletResponse.class); when(cookieConfigProperties.getMaxAge()).thenReturn(300); when(cookieConfigProperties.getPath()).thenReturn("somePath"); assertThatCode(() -> responseUtils.setCookies(response, getConsentReference("someCookie"), null, getAccessTokenTO())).doesNotThrowAnyException(); }
public void setCookies(HttpServletResponse response, ConsentReference consentReference, String accessTokenString, AccessTokenTO accessTokenTO) { int validity = cookieConfigProperties.getMaxAge(); if (StringUtils.isNoneBlank(accessTokenString) && accessTokenTO != null) { long diffInMillies = Math.abs(new Date().getTime() - accessTokenTO.getExp().getTime()); validity = ((Long) TimeUnit.SECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS)).intValue(); Cookie accessTokenCookie = new Cookie(ACCESS_TOKEN_COOKIE_NAME, accessTokenString); accessTokenCookie.setHttpOnly(cookieConfigProperties.isHttpOnly()); accessTokenCookie.setSecure(cookieConfigProperties.isSecure()); accessTokenCookie.setMaxAge(validity); accessTokenCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(accessTokenCookie); } else { removeCookie(response, ACCESS_TOKEN_COOKIE_NAME); } if (consentReference!=null && StringUtils.isNoneBlank(consentReference.getCookieString())) { Cookie consentCookie = new Cookie(CONSENT_COOKIE_NAME, consentReference.getCookieString()); consentCookie.setHttpOnly(true); consentCookie.setSecure(cookieConfigProperties.isSecure()); consentCookie.setMaxAge(validity); consentCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(consentCookie); } }
ResponseUtils { public void setCookies(HttpServletResponse response, ConsentReference consentReference, String accessTokenString, AccessTokenTO accessTokenTO) { int validity = cookieConfigProperties.getMaxAge(); if (StringUtils.isNoneBlank(accessTokenString) && accessTokenTO != null) { long diffInMillies = Math.abs(new Date().getTime() - accessTokenTO.getExp().getTime()); validity = ((Long) TimeUnit.SECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS)).intValue(); Cookie accessTokenCookie = new Cookie(ACCESS_TOKEN_COOKIE_NAME, accessTokenString); accessTokenCookie.setHttpOnly(cookieConfigProperties.isHttpOnly()); accessTokenCookie.setSecure(cookieConfigProperties.isSecure()); accessTokenCookie.setMaxAge(validity); accessTokenCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(accessTokenCookie); } else { removeCookie(response, ACCESS_TOKEN_COOKIE_NAME); } if (consentReference!=null && StringUtils.isNoneBlank(consentReference.getCookieString())) { Cookie consentCookie = new Cookie(CONSENT_COOKIE_NAME, consentReference.getCookieString()); consentCookie.setHttpOnly(true); consentCookie.setSecure(cookieConfigProperties.isSecure()); consentCookie.setMaxAge(validity); consentCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(consentCookie); } } }
ResponseUtils { public void setCookies(HttpServletResponse response, ConsentReference consentReference, String accessTokenString, AccessTokenTO accessTokenTO) { int validity = cookieConfigProperties.getMaxAge(); if (StringUtils.isNoneBlank(accessTokenString) && accessTokenTO != null) { long diffInMillies = Math.abs(new Date().getTime() - accessTokenTO.getExp().getTime()); validity = ((Long) TimeUnit.SECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS)).intValue(); Cookie accessTokenCookie = new Cookie(ACCESS_TOKEN_COOKIE_NAME, accessTokenString); accessTokenCookie.setHttpOnly(cookieConfigProperties.isHttpOnly()); accessTokenCookie.setSecure(cookieConfigProperties.isSecure()); accessTokenCookie.setMaxAge(validity); accessTokenCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(accessTokenCookie); } else { removeCookie(response, ACCESS_TOKEN_COOKIE_NAME); } if (consentReference!=null && StringUtils.isNoneBlank(consentReference.getCookieString())) { Cookie consentCookie = new Cookie(CONSENT_COOKIE_NAME, consentReference.getCookieString()); consentCookie.setHttpOnly(true); consentCookie.setSecure(cookieConfigProperties.isSecure()); consentCookie.setMaxAge(validity); consentCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(consentCookie); } }  }
ResponseUtils { public void setCookies(HttpServletResponse response, ConsentReference consentReference, String accessTokenString, AccessTokenTO accessTokenTO) { int validity = cookieConfigProperties.getMaxAge(); if (StringUtils.isNoneBlank(accessTokenString) && accessTokenTO != null) { long diffInMillies = Math.abs(new Date().getTime() - accessTokenTO.getExp().getTime()); validity = ((Long) TimeUnit.SECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS)).intValue(); Cookie accessTokenCookie = new Cookie(ACCESS_TOKEN_COOKIE_NAME, accessTokenString); accessTokenCookie.setHttpOnly(cookieConfigProperties.isHttpOnly()); accessTokenCookie.setSecure(cookieConfigProperties.isSecure()); accessTokenCookie.setMaxAge(validity); accessTokenCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(accessTokenCookie); } else { removeCookie(response, ACCESS_TOKEN_COOKIE_NAME); } if (consentReference!=null && StringUtils.isNoneBlank(consentReference.getCookieString())) { Cookie consentCookie = new Cookie(CONSENT_COOKIE_NAME, consentReference.getCookieString()); consentCookie.setHttpOnly(true); consentCookie.setSecure(cookieConfigProperties.isSecure()); consentCookie.setMaxAge(validity); consentCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(consentCookie); } }  void setCookies(HttpServletResponse response, ConsentReference consentReference, String accessTokenString,
			AccessTokenTO accessTokenTO); void removeCookies(HttpServletResponse response); ResponseEntity<T> unknownCredentials(
			T resp, HttpServletResponse httpResp); ResponseEntity<T> couldNotProcessRequest(T authResp, String message,
			HttpStatus status, HttpServletResponse httpResp); @SuppressWarnings("PMD.AvoidReassigningParameters") ResponseEntity<T> redirect(String locationURI, HttpServletResponse httpResp); ResponseEntity<T> error(T authResp, HttpStatus status, String message, HttpServletResponse response); String consentCookie(String cookieString); }
ResponseUtils { public void setCookies(HttpServletResponse response, ConsentReference consentReference, String accessTokenString, AccessTokenTO accessTokenTO) { int validity = cookieConfigProperties.getMaxAge(); if (StringUtils.isNoneBlank(accessTokenString) && accessTokenTO != null) { long diffInMillies = Math.abs(new Date().getTime() - accessTokenTO.getExp().getTime()); validity = ((Long) TimeUnit.SECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS)).intValue(); Cookie accessTokenCookie = new Cookie(ACCESS_TOKEN_COOKIE_NAME, accessTokenString); accessTokenCookie.setHttpOnly(cookieConfigProperties.isHttpOnly()); accessTokenCookie.setSecure(cookieConfigProperties.isSecure()); accessTokenCookie.setMaxAge(validity); accessTokenCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(accessTokenCookie); } else { removeCookie(response, ACCESS_TOKEN_COOKIE_NAME); } if (consentReference!=null && StringUtils.isNoneBlank(consentReference.getCookieString())) { Cookie consentCookie = new Cookie(CONSENT_COOKIE_NAME, consentReference.getCookieString()); consentCookie.setHttpOnly(true); consentCookie.setSecure(cookieConfigProperties.isSecure()); consentCookie.setMaxAge(validity); consentCookie.setPath(cookieConfigProperties.getPath()); response.addCookie(consentCookie); } }  void setCookies(HttpServletResponse response, ConsentReference consentReference, String accessTokenString,
			AccessTokenTO accessTokenTO); void removeCookies(HttpServletResponse response); ResponseEntity<T> unknownCredentials(
			T resp, HttpServletResponse httpResp); ResponseEntity<T> couldNotProcessRequest(T authResp, String message,
			HttpStatus status, HttpServletResponse httpResp); @SuppressWarnings("PMD.AvoidReassigningParameters") ResponseEntity<T> redirect(String locationURI, HttpServletResponse httpResp); ResponseEntity<T> error(T authResp, HttpStatus status, String message, HttpServletResponse response); String consentCookie(String cookieString); static final String CONSENT_COOKIE_NAME; static final String ACCESS_TOKEN_COOKIE_NAME; static final String UNKNOWN_CREDENTIALS; }