### Question:
KnoxPamRealm extends AuthorizingRealm { @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { PAM pam = null; UnixUser user = null; try { pam = new PAM(this.getService()); UsernamePasswordToken upToken = (UsernamePasswordToken) token; user = pam.authenticate(upToken.getUsername(), new String(upToken.getPassword())); } catch (PAMException e) { handleAuthFailure(token, e.getMessage(), e); } finally { if(pam != null) { pam.dispose(); } } HashRequest hashRequest = new HashRequest.Builder() .setSource(token.getCredentials()) .setAlgorithmName(HASHING_ALGORITHM) .build(); Hash credentialsHash = hashService.computeHash(hashRequest); if (credentialsHash == null) { handleAuthFailure(token, "Failed to compute hash", null); } return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(), credentialsHash.getSalt(), getName()); } KnoxPamRealm(); void setService(String service); String getService();  }### Answer:
@Test public void testDoGetAuthenticationInfo() { KnoxPamRealm realm = new KnoxPamRealm(); realm.setService("sshd"); String pamuser = System.getenv("PAMUSER"); String pampass = System.getenv("PAMPASS"); assumeTrue(pamuser != null); assumeTrue(pampass != null); UsernamePasswordToken authToken = createMock(UsernamePasswordToken.class); expect(authToken.getUsername()).andReturn(pamuser); expect(authToken.getPassword()).andReturn(pampass.toCharArray()); expect(authToken.getCredentials()).andReturn(pampass); replay(authToken); AuthenticationInfo authInfo = realm.doGetAuthenticationInfo(authToken); assertNotNull(authInfo.getCredentials()); }