@Override
  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
          throws AuthenticationException {
    UsernamePasswordToken userToken = (UsernamePasswordToken) token;
    UnixUser user;

    try {
      user = (new PAM(this.getService()))
          .authenticate(userToken.getUsername(), new String(userToken.getPassword()));
    } catch (PAMException e) {
      throw new AuthenticationException("Authentication failed for PAM.", e);
    }

    return new SimpleAuthenticationInfo(
        new UserPrincipal(user),
        userToken.getCredentials(),
        getName());
  }
@Test
  public void testDoGetAuthenticationInfo() {
    PamRealm realm = new PamRealm();
    realm.setService("sshd");

    String pamUser = System.getenv("PAM_USER");
    String pamPass = System.getenv("PAM_PASS");
    assumeTrue(pamUser != null);
    assumeTrue(pamPass != null);

    // mock shiro auth token
    UsernamePasswordToken authToken = mock(UsernamePasswordToken.class);
    when(authToken.getUsername()).thenReturn(pamUser);
    when(authToken.getPassword()).thenReturn(pamPass.toCharArray());
    when(authToken.getCredentials()).thenReturn(pamPass);

    AuthenticationInfo authInfo = realm.doGetAuthenticationInfo(authToken);

    assertNotNull(authInfo.getCredentials());
  }