use of org.apache.zookeeper.server.auth.X509AuthenticationProvider in project zookeeper by apache.
the class X509AuthTest method testTrustedAuth.
@Test
public void testTrustedAuth() {
X509AuthenticationProvider provider = createProvider(clientCert);
MockServerCnxn cnxn = new MockServerCnxn();
cnxn.clientChain = new X509Certificate[] { clientCert };
Assert.assertEquals(KeeperException.Code.OK, provider.handleAuthentication(cnxn, null));
}
use of org.apache.zookeeper.server.auth.X509AuthenticationProvider in project zookeeper by apache.
the class X509AuthTest method testUntrustedAuth.
@Test
public void testUntrustedAuth() {
X509AuthenticationProvider provider = createProvider(clientCert);
MockServerCnxn cnxn = new MockServerCnxn();
cnxn.clientChain = new X509Certificate[] { unknownCert };
Assert.assertEquals(KeeperException.Code.AUTHFAILED, provider.handleAuthentication(cnxn, null));
}
use of org.apache.zookeeper.server.auth.X509AuthenticationProvider in project zookeeper by apache.
the class NettyServerCnxnFactory method initSSL.
private synchronized void initSSL(ChannelPipeline p) throws X509Exception, KeyManagementException, NoSuchAlgorithmException {
String authProviderProp = System.getProperty(ZKConfig.SSL_AUTHPROVIDER);
SSLContext sslContext;
if (authProviderProp == null) {
sslContext = X509Util.createSSLContext();
} else {
sslContext = SSLContext.getInstance("TLSv1");
X509AuthenticationProvider authProvider = (X509AuthenticationProvider) ProviderRegistry.getProvider(System.getProperty(ZKConfig.SSL_AUTHPROVIDER, "x509"));
if (authProvider == null) {
LOG.error("Auth provider not found: {}", authProviderProp);
throw new SSLContextException("Could not create SSLContext with specified auth provider: " + authProviderProp);
}
sslContext.init(new X509KeyManager[] { authProvider.getKeyManager() }, new X509TrustManager[] { authProvider.getTrustManager() }, null);
}
SSLEngine sslEngine = sslContext.createSSLEngine();
sslEngine.setUseClientMode(false);
sslEngine.setNeedClientAuth(true);
p.addLast("ssl", new SslHandler(sslEngine));
LOG.info("SSL handler added for channel: {}", p.getChannel());
}
use of org.apache.zookeeper.server.auth.X509AuthenticationProvider in project zookeeper by apache.
the class X509AuthTest method testSuperAuth.
@Test
public void testSuperAuth() {
X509AuthenticationProvider provider = createProvider(superCert);
MockServerCnxn cnxn = new MockServerCnxn();
cnxn.clientChain = new X509Certificate[] { superCert };
Assert.assertEquals(KeeperException.Code.OK, provider.handleAuthentication(cnxn, null));
Assert.assertEquals("super", cnxn.getAuthInfo().get(0).getScheme());
}
Aggregations