SinglePublicKeyAuthenticator implements PublickeyAuthenticator { public boolean authenticate(String pUser, PublicKey pKey, ServerSession pSession) { return user != null && user.equals(pUser) && allowedKey.equals(pKey); } SinglePublicKeyAuthenticator(String username, String publicKeyPath); boolean authenticate(String pUser, PublicKey pKey, ServerSession pSession);  }
@Test public void withClassPath() throws IOException { SinglePublicKeyAuthenticator auth = new SinglePublicKeyAuthenticator("roland","classpath:com/consol/citrus/ssh/allowed_test_key.pem"); PublicKey pKey = getPublicKey("/com/consol/citrus/ssh/allowed_test_key.pem"); assertTrue(auth.authenticate("roland", pKey, null)); assertFalse(auth.authenticate("guenther", pKey, null)); pKey = getPublicKey("/com/consol/citrus/ssh/forbidden_test_key.pem"); assertFalse(auth.authenticate("roland", pKey, null)); pKey = getPublicKey("/com/consol/citrus/ssh/citrus.pem"); assertFalse(auth.authenticate("citrus", pKey, null)); }
@Test public void withFile() throws IOException { File temp = copyToTempFile("/com/consol/citrus/ssh/allowed_test_key.pem"); SinglePublicKeyAuthenticator auth = new SinglePublicKeyAuthenticator("roland",temp.getAbsolutePath()); PublicKey pKey = getPublicKeyFromStream(new FileInputStream(temp)); assertTrue(auth.authenticate("roland", pKey, null)); assertFalse(auth.authenticate("guenther",pKey,null)); temp = copyToTempFile("/com/consol/citrus/ssh/forbidden_test_key.pem"); pKey = getPublicKeyFromStream(new FileInputStream(temp)); assertFalse(auth.authenticate("roland", pKey, null)); }