protected ByteBuf newConnectCommand() throws PulsarClientException { String authData = ""; if (authentication.getAuthData().hasDataFromCommand()) { authData = authentication.getAuthData().getCommandData(); } return Commands.newConnect(authentication.getAuthMethodName(), authData, this.protocolVersion, getPulsarClientVersion(), proxyToTargetBrokerAddress, null, null, null); }
public PulsarClientImpl(ClientConfigurationData conf, EventLoopGroup eventLoopGroup, ConnectionPool cnxPool) throws PulsarClientException { if (conf == null || isBlank(conf.getServiceUrl()) || eventLoopGroup == null) { throw new PulsarClientException.InvalidConfigurationException("Invalid client configuration"); } this.eventLoopGroup = eventLoopGroup; this.conf = conf; conf.getAuthentication().start(); this.cnxPool = cnxPool; externalExecutorProvider = new ExecutorProvider(conf.getNumListenerThreads(), getThreadFactory("pulsar-external-listener")); if (conf.getServiceUrl().startsWith("http")) { lookup = new HttpLookupService(conf, eventLoopGroup); } else { lookup = new BinaryProtoLookupService(this, conf.getServiceUrl(), conf.isUseTls(), externalExecutorProvider.getExecutor()); } timer = new HashedWheelTimer(getThreadFactory("pulsar-timer"), 1, TimeUnit.MILLISECONDS); producers = Maps.newIdentityHashMap(); consumers = Maps.newIdentityHashMap(); state.set(State.Open); }
@Override public void shutdown() throws PulsarClientException { try { lookup.close(); cnxPool.close(); timer.stop(); externalExecutorProvider.shutdownNow(); conf.getAuthentication().close(); } catch (Throwable t) { log.warn("Failed to shutdown Pulsar client", t); throw new PulsarClientException(t); } }
this.auth = clientConfigData != null ? clientConfigData.getAuthentication() : new AuthenticationDisabled(); LOG.debug("created: serviceUrl={}, authMethodName={}", serviceUrl, auth != null ? auth.getAuthMethodName() : null); auth.start(); AuthenticationDataProvider authData = auth.getAuthData(); if (authData.hasDataForTls()) { sslCtx = SecurityUtility.createSslContext(clientConfigData.isTlsAllowInsecureConnection(), try { if (auth != null) { auth.close();
auth.start(); AuthenticationDataProvider authData = auth.getAuthData(); if (authData.hasDataForTls()) { sslCtx = SecurityUtility.createSslContext( } catch (Exception e) { try { auth.close(); } catch (IOException ioe) { LOG.error("Failed to close the authentication service", ioe);
public void initChannel(SocketChannel ch) throws Exception { if (conf.isUseTls()) { SslContext sslCtx; // Set client certificate if available AuthenticationDataProvider authData = conf.getAuthentication().getAuthData(); if (authData.hasDataForTls()) { sslCtx = SecurityUtility.createNettySslContextForClient(conf.isTlsAllowInsecureConnection(), conf.getTlsTrustCertsFilePath(), (X509Certificate[]) authData.getTlsCertificates(), authData.getTlsPrivateKey()); } else { sslCtx = SecurityUtility.createNettySslContextForClient(conf.isTlsAllowInsecureConnection(), conf.getTlsTrustCertsFilePath()); } ch.pipeline().addLast(TLS_HANDLER, sslCtx.newHandler(ch.alloc())); ch.pipeline().addLast("ByteBufPairEncoder", ByteBufPair.COPYING_ENCODER); } else { ch.pipeline().addLast("ByteBufPairEncoder", ByteBufPair.ENCODER); } ch.pipeline().addLast("frameDecoder", new LengthFieldBasedFrameDecoder(MaxMessageSize, 0, 4, 0, 4)); ch.pipeline().addLast("handler", clientCnxSupplier.get()); } });
try { Authentication auth = AuthenticationFactory.create(authPluginClassName, authParams); auth.start(); AuthenticationDataProvider authData = auth.getAuthData(); if (authData.hasDataForHttp()) { for (Map.Entry<String, String> kv : authData.getHttpHeaders()) {
/** * Create an instance of the Authentication-Plugin * * @param authPluginClassName * name of the Authentication-Plugin you want to use * @param authParams * map which represents parameters for the Authentication-Plugin * @return instance of the Authentication-Plugin * @throws UnsupportedAuthenticationException */ @SuppressWarnings("deprecation") public static final Authentication create(String authPluginClassName, Map<String, String> authParams) throws UnsupportedAuthenticationException { try { if (isNotBlank(authPluginClassName)) { Class<?> authClass = Class.forName(authPluginClassName); Authentication auth = (Authentication) authClass.newInstance(); auth.configure(authParams); return auth; } else { return new AuthenticationDisabled(); } } catch (Throwable t) { throw new UnsupportedAuthenticationException(t); } } }
try { String requestUrl = new URL(serviceNameResolver.resolveHostUri().toURL(), path).toString(); AuthenticationDataProvider authData = authentication.getAuthData(); BoundRequestBuilder builder = httpClient.prepareGet(requestUrl);
} else { auth.configure(configureFromPulsar1AuthParamString(authParamsString));
protected ByteBuf newConnectCommand() throws PulsarClientException { String authData = ""; if (authentication.getAuthData().hasDataFromCommand()) { authData = authentication.getAuthData().getCommandData(); } return Commands.newConnect(authentication.getAuthMethodName(), authData, this.protocolVersion, getPulsarClientVersion(), proxyToTargetBrokerAddress, null, null, null); }
AuthenticationDataProvider authData = authentication.getAuthData(); if (authData.hasDataForTls()) { sslCtx = SecurityUtility.createNettySslContextForClient(tlsAllowInsecureConnection, tlsTrustCertsFilePath,
public PulsarClientImpl(ClientConfigurationData conf, EventLoopGroup eventLoopGroup, ConnectionPool cnxPool) throws PulsarClientException { if (conf == null || isBlank(conf.getServiceUrl()) || eventLoopGroup == null) { throw new PulsarClientException.InvalidConfigurationException("Invalid client configuration"); } this.eventLoopGroup = eventLoopGroup; this.conf = conf; conf.getAuthentication().start(); this.cnxPool = cnxPool; externalExecutorProvider = new ExecutorProvider(conf.getNumListenerThreads(), getThreadFactory("pulsar-external-listener")); if (conf.getServiceUrl().startsWith("http")) { lookup = new HttpLookupService(conf, eventLoopGroup); } else { lookup = new BinaryProtoLookupService(this, conf.getServiceUrl(), conf.isUseTls(), externalExecutorProvider.getExecutor()); } timer = new HashedWheelTimer(getThreadFactory("pulsar-timer"), 1, TimeUnit.MILLISECONDS); producers = Maps.newIdentityHashMap(); consumers = Maps.newIdentityHashMap(); state.set(State.Open); }
/** * Close the Pulsar admin client to release all the resources */ @Override public void close() { try { if (auth != null) { auth.close(); } } catch (IOException e) { LOG.error("Failed to close the authentication service", e); } client.close(); } }
/** * Create an instance of the Authentication-Plugin * * @param authPluginClassName name of the Authentication-Plugin you want to use * @param authParams map which represents parameters for the Authentication-Plugin * @return instance of the Authentication-Plugin * @throws UnsupportedAuthenticationException */ @SuppressWarnings("deprecation") public static final Authentication create(String authPluginClassName, Map<String, String> authParams) throws UnsupportedAuthenticationException { try { if (isNotBlank(authPluginClassName)) { Class<?> authClass = Class.forName(authPluginClassName); Authentication auth = (Authentication) authClass.newInstance(); auth.configure(authParams); return auth; } else { return new AuthenticationDisabled(); } } catch (Throwable t) { throw new UnsupportedAuthenticationException(t); } } }
@Override protected ByteBuf newConnectCommand() throws PulsarClientException { if (log.isDebugEnabled()) { log.debug( "New Connection opened via ProxyClientCnx with params clientAuthRole = {}, clientAuthData = {}, clientAuthMethod = {}", clientAuthRole, clientAuthData, clientAuthMethod); } String authData = null; if (authentication.getAuthData().hasDataFromCommand()) { authData = authentication.getAuthData().getCommandData(); } return Commands.newConnect(authentication.getAuthMethodName(), authData, protocolVersion, getPulsarClientVersion(), proxyToTargetBrokerAddress, clientAuthRole, clientAuthData, clientAuthMethod); }
public Builder request(final WebTarget target) throws PulsarAdminException { try { Builder builder = target.request(MediaType.APPLICATION_JSON); // Add headers for authentication if any if (auth != null && auth.getAuthData().hasDataForHttp()) { for (Map.Entry<String, String> header : auth.getAuthData().getHttpHeaders()) { builder.header(header.getKey(), header.getValue()); } } return builder; } catch (Throwable t) { throw new GettingAuthenticationDataException(t); } }
@Override public void shutdown() throws PulsarClientException { try { lookup.close(); cnxPool.close(); timer.stop(); externalExecutorProvider.shutdownNow(); conf.getAuthentication().close(); } catch (Throwable t) { log.warn("Failed to shutdown Pulsar client", t); throw new PulsarClientException(t); } }
/** * Create an instance of the Authentication-Plugin * * @param authPluginClassName name of the Authentication-Plugin you want to use * @param authParamsString string which represents parameters for the Authentication-Plugin, e.g., "key1:val1,key2:val2" * @return instance of the Authentication-Plugin * @throws UnsupportedAuthenticationException */ @SuppressWarnings("deprecation") public static final Authentication create(String authPluginClassName, String authParamsString) throws UnsupportedAuthenticationException { try { if (isNotBlank(authPluginClassName)) { Class<?> authClass = Class.forName(authPluginClassName); Authentication auth = (Authentication) authClass.newInstance(); if (auth instanceof EncodedAuthenticationParameterSupport) { // Parse parameters on plugin side. ((EncodedAuthenticationParameterSupport) auth).configure(authParamsString); } else { // Parse parameters by default parse logic. auth.configure(AuthenticationUtil.configureFromPulsar1AuthParamString(authParamsString)); } return auth; } else { return new AuthenticationDisabled(); } } catch (Throwable t) { throw new UnsupportedAuthenticationException(t); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { this.ctx = ctx; // Send the Connect command to broker String authData = ""; if (authentication.getAuthData().hasDataFromCommand()) { authData = authentication.getAuthData().getCommandData(); } ByteBuf command = null; command = Commands.newConnect(authentication.getAuthMethodName(), authData, protocolVersion, "Pulsar proxy", null /* target broker */, originalPrincipal, clientAuthData, clientAuthMethod); outboundChannel.writeAndFlush(command); outboundChannel.read(); }