NegotiateAuthenticationRealm extends AuthenticatingRealm { @Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken t) { final NegotiateToken token = (NegotiateToken) t; final byte[] inToken = token.getIn(); if (token.isNtlmPost()) { this.windowsAuthProvider.resetSecurityToken(token.getConnectionId()); } final IWindowsSecurityContext securityContext; try { securityContext = this.windowsAuthProvider.acceptSecurityToken(token.getConnectionId(), inToken, token.getSecurityPackage()); } catch (final Exception e) { NegotiateAuthenticationRealm.LOGGER.warn("error logging in user: {}", e.getMessage()); throw new AuthenticationException(e); } final byte[] continueTokenBytes = securityContext.getToken(); token.setOut(continueTokenBytes); if (continueTokenBytes != null) { NegotiateAuthenticationRealm.LOGGER.debug("continue token bytes: {}", Integer.valueOf(continueTokenBytes.length)); } else { NegotiateAuthenticationRealm.LOGGER.debug("no continue token bytes"); } if (securityContext.isContinue() || token.isNtlmPost()) { throw new AuthenticationInProgressException(); } final IWindowsIdentity windowsIdentity = securityContext.getIdentity(); securityContext.dispose(); NegotiateAuthenticationRealm.LOGGER.debug("logged in user: {} ({})", windowsIdentity.getFqn(), windowsIdentity.getSidString()); final Principal principal = new WindowsPrincipal(windowsIdentity); token.setPrincipal(principal); final Subject subject = new Subject(); subject.getPrincipals().add(principal); token.setSubject(subject); return token.createInfo(); } NegotiateAuthenticationRealm(); @Override boolean supports(final AuthenticationToken token);  }
@Test void testAuthenticationInfo(@Mocked final NegotiateToken negotiateToken) { Assertions.assertNotNull(new Expectations() { { negotiateToken.getIn(); this.result = Byte.valueOf((byte) 0); } }); Assertions.assertThrows(AuthenticationException.class, () -> { this.negAuthRealm.doGetAuthenticationInfo(negotiateToken); }); }