CompositeCredentialResolver implements CredentialResolver { public Credential resolveCredential(HttpServletRequest request){ if(request==null){ return null; } Credential credential = null; if(encryCredentialResolver!=null){ credential = encryCredentialResolver.resolveCredential(request); } if(credential==null){ if(usernamePasswordCredentialResolver!=null){ credential = usernamePasswordCredentialResolver.resolveCredential(request); } } if(credential instanceof AbstractParameter){ AbstractParameter abstractParameter = (AbstractParameter)credential; abstractParameter.setParameters(WebUtils.getParametersStartingWith(request, null)); if(abstractParameter.getParameterValue(WebConstants.SERVICE_PARAM_NAME)==null){ if(request.getSession().getAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION)!=null){ abstractParameter.getParameters().put(WebConstants.SERVICE_PARAM_NAME, request.getSession().getAttribute(WebConstants.KI4SO_SERVICE_KEY_IN_SESSION)); } } } return credential; } CompositeCredentialResolver(); Credential resolveCredential(HttpServletRequest request); void setEncryCredentialResolver(
			CredentialResolver encryCredentialResolver); void setUsernamePasswordCredentialResolver(
			CredentialResolver usernamePasswordCredentialResolver);  }
@Test public void testResolveCredential() { Assert.assertNull(resolver.resolveCredential(null)); MockHttpServletRequest request = new MockHttpServletRequest(); Assert.assertNull(resolver.resolveCredential(request)); CredentialResolver encryCredentialResolver = Mockito.mock(CredentialResolver.class); CredentialResolver usernamePasswordCredentialResolver = Mockito.mock(CredentialResolver.class); resolver.setEncryCredentialResolver(encryCredentialResolver); Assert.assertNull(resolver.resolveCredential(request)); resolver.setEncryCredentialResolver(null); resolver.setUsernamePasswordCredentialResolver(usernamePasswordCredentialResolver); Assert.assertNull(resolver.resolveCredential(request)); resolver.setEncryCredentialResolver(encryCredentialResolver); resolver.setUsernamePasswordCredentialResolver(usernamePasswordCredentialResolver); Assert.assertNull(resolver.resolveCredential(request)); Credential credential = Mockito.mock(Credential.class); Credential credential1 = Mockito.mock(Credential.class); resolver.setEncryCredentialResolver(encryCredentialResolver); resolver.setUsernamePasswordCredentialResolver(usernamePasswordCredentialResolver); Mockito.when(encryCredentialResolver.resolveCredential(request)).thenReturn(credential); Mockito.when(usernamePasswordCredentialResolver.resolveCredential(request)).thenReturn(credential1); Credential result = resolver.resolveCredential(request); Assert.assertNotNull(result); Assert.assertEquals(result, credential); credential = Mockito.mock(Credential.class); credential1 = Mockito.mock(Credential.class); resolver.setEncryCredentialResolver(encryCredentialResolver); resolver.setUsernamePasswordCredentialResolver(usernamePasswordCredentialResolver); Mockito.when(encryCredentialResolver.resolveCredential(request)).thenReturn(null); Mockito.when(usernamePasswordCredentialResolver.resolveCredential(request)).thenReturn(credential1); result = resolver.resolveCredential(request); Assert.assertNotNull(result); Assert.assertEquals(result, credential1); }