### Question:
SshShellSecurityAuthenticationProvider implements SshShellAuthenticationProvider { @Override public boolean authenticate(String username, String pass, ServerSession serverSession) throws PasswordChangeRequiredException { try { Authentication auth = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken(username, pass)); LOGGER.debug("User {} authenticated with authorities: {}", username, auth.getAuthorities()); List<String> authorities = auth.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()); serverSession.getIoSession().setAttribute(AUTHENTICATION_ATTRIBUTE, new SshAuthentication(username, auth.getPrincipal(), auth.getDetails(), auth.getCredentials(), authorities)); return auth.isAuthenticated(); } catch (AuthenticationException e) { LOGGER.error("Unable to authenticate user [{}] : {}", username, e.getMessage()); LOGGER.debug("Unable to authenticate user [{}]", username, e); return false; } } SshShellSecurityAuthenticationProvider(ApplicationContext context, String authProviderBeanName); @PostConstruct void init(); @Override boolean authenticate(String username, String pass,
                                ServerSession serverSession);  }### Answer:
@Test void authenticate() { ServerSession session = Mockito.mock(ServerSession.class); IoSession io = Mockito.mock(IoSession.class); Mockito.when(session.getIoSession()).thenReturn(io); Mockito.when(ctx.getBeansOfType(any())).thenReturn(Collections.singletonMap("sec", sec)); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); Mockito.when(io.setAttribute(eq(AUTHENTICATION_ATTRIBUTE), captor.capture())).thenReturn(null); SshShellSecurityAuthenticationProvider provider = new SshShellSecurityAuthenticationProvider(ctx, null); provider.init(); Mockito.when(sec.authenticate(any())).thenReturn( new UsernamePasswordAuthenticationToken("principal", "credentials", Collections.singletonList(new SimpleGrantedAuthority("USER")))); assertTrue(provider.authenticate("user", "pass", session)); SshAuthentication auth = (SshAuthentication) captor.getValue(); assertEquals("principal", auth.getPrincipal()); assertEquals("credentials", auth.getCredentials()); assertEquals(1, auth.getAuthorities().size()); assertNull(auth.getDetails()); Mockito.when(sec.authenticate(any())).thenThrow(new BadCredentialsException("[MOCK]")); assertFalse(provider.authenticate("user", "pass", session)); }