protected SaslClient createDigestSaslClient(String[] mechanismNames, String saslDefaultRealm, CallbackHandler saslClientCallbackHandler) throws IOException { return Sasl.createSaslClient(mechanismNames, null, null, saslDefaultRealm, saslProps, saslClientCallbackHandler); }
protected SaslClient createKerberosSaslClient(String[] mechanismNames, String userFirstPart, String userSecondPart) throws IOException { return Sasl.createSaslClient(mechanismNames, null, userFirstPart, userSecondPart, saslProps, null); }
private SaslClient createSaslClient() { try { return Subject.doAs(subject, (PrivilegedExceptionAction<SaslClient>) () -> { String[] mechs = {mechanism}; LOG.debug("Creating SaslClient: client={};service={};serviceHostname={};mechs={}", clientPrincipalName, servicePrincipal, host, Arrays.toString(mechs)); return Sasl.createSaslClient(mechs, clientPrincipalName, servicePrincipal, host, configs, callbackHandler); }); } catch (PrivilegedActionException e) { throw new SaslAuthenticationException("Failed to create SaslClient with mechanism " + mechanism, e.getCause()); } }
public SaslClient run() { try { Map<String, String> props = new TreeMap<String, String>(); props.put(Sasl.QOP, "auth"); props.put(Sasl.SERVER_AUTH, "false"); return Sasl.createSaslClient( new String[]{ SaslUtils.KERBEROS }, fPrincipalName, fServiceName, fHost, props, fch); } catch (Exception e) { LOG.error("Subject failed to create sasl client.", e); return null; } } });
public SaslClient run() throws SaslException { LOG.info("{} will use GSSAPI as SASL mechanism.", entity); String[] mechs = { "GSSAPI" }; LOG.debug("creating sasl client: {}={};service={};serviceHostname={}", new Object[] { entity, clientPrincipalName, serviceName, serviceHostname }); SaslClient saslClient = Sasl.createSaslClient( mechs, clientPrincipalName, serviceName, serviceHostname, null, new SaslClientCallbackHandler(null, entity)); return saslClient; } });
public SaslNegotiateHandler(Configuration conf, String username, char[] password, Map<String, String> saslProps, int timeoutMs, Promise<Void> promise, DFSClient dfsClient) throws SaslException { this.conf = conf; this.saslProps = saslProps; this.saslClient = Sasl.createSaslClient(new String[] { MECHANISM }, username, PROTOCOL, SERVER_NAME, saslProps, new SaslClientCallbackHandler(username, password)); this.timeoutMs = timeoutMs; this.promise = promise; this.dfsClient = dfsClient; }
public SaslClient run() throws SaslException { LOG.info("{} will use GSSAPI as SASL mechanism.", entity); String[] mechs = { "GSSAPI" }; LOG.debug("creating sasl client: {}={};service={};serviceHostname={}", new Object[] { entity, clientPrincipalName, serviceName, serviceHostname }); SaslClient saslClient = Sasl.createSaslClient( mechs, clientPrincipalName, serviceName, serviceHostname, null, new SaslClientCallbackHandler(null, entity)); return saslClient; } });
/** * Create a SaslNettyClient for authentication with servers. */ public SaslNettyClient(String topologyName, byte[] token) { try { LOG.debug("SaslNettyClient: Creating SASL {} client to authenticate to server ", SaslUtils.AUTH_DIGEST_MD5); saslClient = Sasl.createSaslClient( new String[]{ SaslUtils.AUTH_DIGEST_MD5 }, null, null, SaslUtils.DEFAULT_REALM, SaslUtils.getSaslProps(), new SaslClientCallbackHandler(topologyName, token)); } catch (IOException e) { LOG.error("SaslNettyClient: Could not obtain topology token for Netty " + "Client to use to authenticate with a Netty Server."); saslClient = null; } }
@Override public SaslClient createSaslClient(String username, String password, String impersonationUser) throws UnauthenticatedException { try { return Sasl.createSaslClient(new String[] {PlainSaslServerProvider.MECHANISM}, impersonationUser, null, null, new HashMap<String, String>(), new PlainSaslClientCallbackHandler(username, password)); } catch (SaslException e) { throw new UnauthenticatedException(e.getMessage(), e); } }
SaslClientHandler( RpcConfiguration config, String clientId, Promise<Rpc> promise, ScheduledFuture<?> timeout, String secret, RpcDispatcher dispatcher) throws IOException { super(config); this.clientId = clientId; this.promise = promise; this.timeout = timeout; this.secret = secret; this.dispatcher = dispatcher; this.client = Sasl.createSaslClient(new String[] { config.getSaslMechanism() }, null, SASL_PROTOCOL, SASL_REALM, config.getSaslOptions(), this); }
@Override protected void authenticateInternal(CallbackHandler cbh) throws SmackException { String[] mechanisms = { getName() }; Map<String, String> props = getSaslProps(); try { sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, cbh); } catch (SaslException e) { throw new SmackException(e); } }
.toArray()[0]); saslClient = Sasl.createSaslClient(mechs, username, protocol, serverName, null, new SaslClientCallbackHandler(password, entity)); return saslClient;
sc = Sasl.createSaslClient(mechanisms, authzid, "xmpp", getServerName().toString(), props, new CallbackHandler() { @Override
.toArray()[0]); saslClient = Sasl.createSaslClient(mechs, username, protocol, serverName, null, new SaslClientCallbackHandler(password, entity)); return saslClient;
+ " client to authenticate to service at " + saslServerName); return Sasl.createSaslClient( new String[] { mechanism }, saslUser, saslProtocol, saslServerName, saslProperties, saslCallback);
@Override protected SaslClient createSaslClient(final ServerAddress serverAddress) { MongoCredential credential = getMongoCredential(); try { Map<String, Object> saslClientProperties = credential.getMechanismProperty(JAVA_SASL_CLIENT_PROPERTIES_KEY, null); if (saslClientProperties == null) { saslClientProperties = new HashMap<String, Object>(); saslClientProperties.put(Sasl.MAX_BUFFER, "0"); saslClientProperties.put(Sasl.CREDENTIALS, getGSSCredential(credential.getUserName())); } SaslClient saslClient = Sasl.createSaslClient(new String[]{GSSAPI.getMechanismName()}, credential.getUserName(), credential.getMechanismProperty(SERVICE_NAME_KEY, SERVICE_NAME_DEFAULT_VALUE), getHostName(serverAddress), saslClientProperties, null); if (saslClient == null) { throw new MongoSecurityException(credential, String.format("No platform support for %s mechanism", GSSAPI)); } return saslClient; } catch (SaslException e) { throw new MongoSecurityException(credential, "Exception initializing SASL client", e); } catch (GSSException e) { throw new MongoSecurityException(credential, "Exception initializing GSSAPI credentials", e); } catch (UnknownHostException e) { throw new MongoSecurityException(credential, "Unable to canonicalize host name + " + serverAddress); } }
protected SaslClient createDigestSaslClient(String[] mechanismNames, String saslDefaultRealm, CallbackHandler saslClientCallbackHandler) throws IOException { return Sasl.createSaslClient(mechanismNames, null, null, saslDefaultRealm, saslProps, saslClientCallbackHandler); }
@Before public void testStartServer() throws Exception { if (server != null) return; server = new SaslSocketServer (new TestResponder(), new InetSocketAddress(0), DIGEST_MD5_MECHANISM, SERVICE, HOST, DIGEST_MD5_PROPS, new TestSaslCallbackHandler()); server.start(); SaslClient saslClient = Sasl.createSaslClient (new String[]{DIGEST_MD5_MECHANISM}, PRINCIPAL, SERVICE, HOST, DIGEST_MD5_PROPS, new TestSaslCallbackHandler()); client = new SaslSocketTransceiver(new InetSocketAddress(server.getPort()), saslClient); requestor = new GenericRequestor(PROTOCOL, client); }
@Override protected SaslClient createSaslClient(final ServerAddress serverAddress) { final MongoCredential credential = getMongoCredential(); isTrue("mechanism is PLAIN", credential.getAuthenticationMechanism() == PLAIN); try { return Sasl.createSaslClient(new String[]{PLAIN.getMechanismName()}, credential.getUserName(), DEFAULT_PROTOCOL, serverAddress.getHost(), null, new CallbackHandler() { @Override public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword(credential.getPassword()); } else if (callback instanceof NameCallback) { ((NameCallback) callback).setName(credential.getUserName()); } } } }); } catch (SaslException e) { throw new MongoSecurityException(credential, "Exception initializing SASL client", e); } } }
@Test(expected=SaslException.class) public void testWrongPassword() throws Exception { Server s = new SaslSocketServer (new TestResponder(), new InetSocketAddress(0), DIGEST_MD5_MECHANISM, SERVICE, HOST, DIGEST_MD5_PROPS, new TestSaslCallbackHandler()); s.start(); SaslClient saslClient = Sasl.createSaslClient (new String[]{DIGEST_MD5_MECHANISM}, PRINCIPAL, SERVICE, HOST, DIGEST_MD5_PROPS, new WrongPasswordCallbackHandler()); Transceiver c = new SaslSocketTransceiver (new InetSocketAddress(server.getPort()), saslClient); GenericRequestor requestor = new GenericRequestor(PROTOCOL, c); GenericRecord params = new GenericData.Record(PROTOCOL.getMessages().get("hello").getRequest()); params.put("greeting", "bob"); Utf8 response = (Utf8)requestor.request("hello", params); assertEquals(new Utf8("goodbye"), response); s.close(); c.close(); }