EncryCredentialResolver implements CredentialResolver { @Override public Credential resolveCredential(HttpServletRequest request) { if(request!=null){ Cookie[] cookies = request.getCookies(); if(cookies!=null){ String value = null; for(Cookie cookie:cookies){ if(cookie!=null && cookie.getName().equalsIgnoreCase(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY)){ value = cookie.getValue(); break; } } if(StringUtils.isEmpty(value)){ value = request.getParameter(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY); } if(!StringUtils.isEmpty(value)){ return new EncryCredential(value.trim()); } } } return null; }  @Override Credential resolveCredential(HttpServletRequest request);  }
@Test public void testResolveCredential(){ String cookie = "VS032SDAFDAFD"; Assert.assertNull(resolver.resolveCredential(null)); MockHttpServletRequest request = new MockHttpServletRequest(); Assert.assertNull(resolver.resolveCredential(request)); request = new MockHttpServletRequest(); request.setCookies(null, null, null, null); Assert.assertNull(resolver.resolveCredential(request)); request = new MockHttpServletRequest(); request.setCookies(new Cookie("C1", null), null, null, new Cookie("C2", "dafdafdada")); Assert.assertNull(resolver.resolveCredential(request)); request = new MockHttpServletRequest(); request.setCookies(new Cookie("C1", null), null, null, new Cookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY, null)); Assert.assertNull(resolver.resolveCredential(request)); request = new MockHttpServletRequest(); request.setCookies(new Cookie("C1", null), null, null, new Cookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY, cookie)); EncryCredential credential = (EncryCredential)resolver.resolveCredential(request); Assert.assertNotNull(credential); Assert.assertEquals(cookie, credential.getCredential()); }