javax.security.sasl.Sasl.createSaslClient()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中javax.security.sasl.Sasl.createSaslClient()方法的一些代码示例,展示了Sasl.createSaslClient()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sasl.createSaslClient()方法的具体详情如下:
包路径:javax.security.sasl.Sasl
类名称:Sasl
方法名:createSaslClient

Sasl.createSaslClient介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

protected SaslClient createDigestSaslClient(String[] mechanismNames, String saslDefaultRealm,
  CallbackHandler saslClientCallbackHandler) throws IOException {
 return Sasl.createSaslClient(mechanismNames, null, null, saslDefaultRealm, saslProps,
  saslClientCallbackHandler);
}

代码示例来源:origin: apache/hbase

protected SaslClient createKerberosSaslClient(String[] mechanismNames, String userFirstPart,
  String userSecondPart) throws IOException {
 return Sasl.createSaslClient(mechanismNames, null, userFirstPart, userSecondPart, saslProps,
  null);
}

代码示例来源:origin: apache/kafka

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());
  }
}

代码示例来源:origin: apache/storm

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;
    }
  }
});

代码示例来源:origin: apache/zookeeper

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;
  }
});

代码示例来源:origin: apache/hbase

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;
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

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;
  }
});

代码示例来源:origin: apache/storm

/**
 * 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;
  }
}

代码示例来源:origin: Alluxio/alluxio

@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);
 }
}

代码示例来源:origin: apache/hive

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);
}

代码示例来源:origin: igniterealtime/Smack

@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);
  }
}

代码示例来源:origin: apache/zookeeper

.toArray()[0]);
saslClient = Sasl.createSaslClient(mechs, username, protocol,
    serverName, null, new SaslClientCallbackHandler(password, entity));
return saslClient;

代码示例来源:origin: igniterealtime/Smack

sc = Sasl.createSaslClient(mechanisms, authzid, "xmpp", getServerName().toString(), props,
        new CallbackHandler() {
          @Override

代码示例来源:origin: org.apache.zookeeper/zookeeper

.toArray()[0]);
saslClient = Sasl.createSaslClient(mechs, username, protocol,
    serverName, null, new SaslClientCallbackHandler(password, entity));
return saslClient;

代码示例来源:origin: org.apache.hadoop/hadoop-common

+ " client to authenticate to service at " + saslServerName);
return Sasl.createSaslClient(
  new String[] { mechanism }, saslUser, saslProtocol, saslServerName,
  saslProperties, saslCallback);

代码示例来源:origin: org.mongodb/mongo-java-driver

@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);
  }
}

代码示例来源:origin: org.apache.hbase/hbase-client

protected SaslClient createDigestSaslClient(String[] mechanismNames, String saslDefaultRealm,
  CallbackHandler saslClientCallbackHandler) throws IOException {
 return Sasl.createSaslClient(mechanismNames, null, null, saslDefaultRealm, saslProps,
  saslClientCallbackHandler);
}

代码示例来源:origin: apache/avro

@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);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@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);
    }
  }
}

代码示例来源:origin: apache/avro

@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();
}

相关文章