当前位置: 首页>>代码示例>>Java>>正文


Java Sasl.createSaslClient方法代码示例

本文整理汇总了Java中javax.security.sasl.Sasl.createSaslClient方法的典型用法代码示例。如果您正苦于以下问题:Java Sasl.createSaslClient方法的具体用法?Java Sasl.createSaslClient怎么用?Java Sasl.createSaslClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.security.sasl.Sasl的用法示例。


在下文中一共展示了Sasl.createSaslClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSaslClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
static SaslClient createSaslClient(final String user, final String password) throws SaslException {
    return Sasl.createSaslClient(new String[]{"PLAIN"}, user, null, null, 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(password.toCharArray());
                        } else if (callback instanceof NameCallback) {
                            ((NameCallback) callback).setName(user);
                        }
                    }
                }
            });
}
 
开发者ID:mongodb,项目名称:mongosql-auth-java,代码行数:17,代码来源:Plain.java

示例2: runNegotiation

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
private void runNegotiation(CallbackHandler clientCbh,
                            CallbackHandler serverCbh)
                                throws SaslException {
  String mechanism = AuthMethod.PLAIN.getMechanismName();

  SaslClient saslClient = Sasl.createSaslClient(
      new String[]{ mechanism }, null, null, null, null, clientCbh);
  assertNotNull(saslClient);

  SaslServer saslServer = Sasl.createSaslServer(
      mechanism, null, "localhost", null, serverCbh);
  assertNotNull("failed to find PLAIN server", saslServer);
  
  byte[] response = saslClient.evaluateChallenge(new byte[0]);
  assertNotNull(response);
  assertTrue(saslClient.isComplete());

  response = saslServer.evaluateResponse(response);
  assertNull(response);
  assertTrue(saslServer.isComplete());
  assertNotNull(saslServer.getAuthorizationID());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:TestSaslRPC.java

示例3: createSaslClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
static SaslClient createSaslClient(final String user, final String hostName) throws SaslException {
    Map<String, Object> saslClientProperties = new HashMap<String, Object>();
    saslClientProperties.put(Sasl.MAX_BUFFER, "0");
    saslClientProperties.put(Sasl.CREDENTIALS, getGSSCredential(user));

    return Sasl.createSaslClient(new String[]{"GSSAPI"}, user, SERVICE_NAME_DEFAULT_VALUE, hostName, saslClientProperties, null);
}
 
开发者ID:mongodb,项目名称:mongosql-auth-java,代码行数:8,代码来源:Gssapi.java

示例4: authenticate

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
@Override
public void authenticate(String apiKeyAndSecret, String host,
        String sessionKey) throws IOException, XMPPException
{
    if (apiKeyAndSecret == null || sessionKey == null)
    {
        throw new IllegalArgumentException("Invalid parameters");
    }

    String[] keyArray = apiKeyAndSecret.split("\\|", 2);
    if (keyArray.length < 2)
    {
        throw new IllegalArgumentException(
                "API key or session key is not present");
    }

    this.apiKey = keyArray[0];
    this.applicationSecret = keyArray[1];
    this.sessionKey = sessionKey;

    this.authenticationId = sessionKey;
    this.password = applicationSecret;
    this.hostname = host;

    String[] mechanisms = { NAME };
    Map<String, String> props = new HashMap<String, String>();
    this.sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, this);
    authenticate();
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:30,代码来源:SASLXFacebookPlatformMechanism.java

示例5: SampleClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
public SampleClient(String requestedQOPs) throws SaslException {

        Map<String,String> properties = new HashMap<String,String>();

        if (requestedQOPs != null) {
            properties.put(Sasl.QOP, requestedQOPs);
        }
        saslClient = Sasl.createSaslClient(new String[]{ DIGEST_MD5 }, null,
            "local", "127.0.0.1", properties, new SampleCallbackHandler());
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:CheckNegotiatedQOPs.java

示例6: authenticateInternal

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:13,代码来源:SASLJavaXMechanism.java

示例7: authenticate

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
/**
 * Builds and sends the <tt>auth</tt> stanza to the server. Note that this method of
 * authentication is not recommended, since it is very inflexable.  Use
 * {@link #authenticate(String, String, CallbackHandler)} whenever possible.
 *
 * @param username the username of the user being authenticated.
 * @param host     the hostname where the user account resides.
 * @param password the password for this account.
 * @throws IOException If a network error occurs while authenticating.
 * @throws XMPPException If a protocol error occurs or the user is not authenticated.
 */
public void authenticate(String username, String host, String password) throws IOException, XMPPException {
    //Since we were not provided with a CallbackHandler, we will use our own with the given
    //information

    //Set the authenticationID as the username, since they must be the same in this case.
    this.authenticationId = username;
    this.password = password;
    this.hostname = host;

    String[] mechanisms = { getName() };
    Map<String,String> props = new HashMap<String,String>();
    sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
    authenticate();
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:26,代码来源:SASLMechanism.java

示例8: initialize

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
@Override
public void initialize() {
  try {
    SaslClient sc = Sasl.createSaslClient(mech, null, "memcached",
        serverName, props, cbh);

    byte[] response = buildResponse(sc);
    String mechanism = sc.getMechanismName();

    prepareBuffer(mechanism, 0, response);
  } catch (SaslException e) {
    // XXX: Probably something saner can be done here.
    throw new RuntimeException("Can't make SASL go.", e);
  }
}
 
开发者ID:Alachisoft,项目名称:TayzGrid,代码行数:16,代码来源:SASLBaseOperationImpl.java

示例9: createSaslClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
/**
 * Try to create a SaslClient for an authentication type.  May return
 * null if the type isn't supported or the client lacks the required
 * credentials.
 * 
 * @param authType - the requested authentication method
 * @return SaslClient for the authType or null
 * @throws SaslException - error instantiating client
 * @throws IOException - misc errors
 */
private SaslClient createSaslClient(SaslAuth authType)
    throws SaslException, IOException {
  String saslUser = null;
  // SASL requires the client and server to use the same proto and serverId
  // if necessary, auth types below will verify they are valid
  final String saslProtocol = authType.getProtocol();
  final String saslServerName = authType.getServerId();
  Map<String, String> saslProperties =
    saslPropsResolver.getClientProperties(serverAddr.getAddress());  
  CallbackHandler saslCallback = null;
  
  final AuthMethod method = AuthMethod.valueOf(authType.getMethod());
  switch (method) {
    case TOKEN: {
      Token<?> token = getServerToken(authType);
      if (token == null) {
        LOG.debug("tokens aren't supported for this protocol" +
            " or user doesn't have one");
        return null;
      }
      saslCallback = new SaslClientCallbackHandler(token);
      break;
    }
    case KERBEROS: {
      if (ugi.getRealAuthenticationMethod().getAuthMethod() !=
          AuthMethod.KERBEROS) {
        LOG.debug("client isn't using kerberos");
        return null;
      }
      String serverPrincipal = getServerPrincipal(authType);
      if (serverPrincipal == null) {
        LOG.debug("protocol doesn't use kerberos");
        return null;
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server's Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
      break;
    }
    default:
      throw new IOException("Unknown authentication method " + method);
  }

  String mechanism = method.getMechanismName();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Creating SASL " + mechanism + "(" + method + ") "
        + " client to authenticate to service at " + saslServerName);
  }
  return Sasl.createSaslClient(
      new String[] { mechanism }, saslUser, saslProtocol, saslServerName,
      saslProperties, saslCallback);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:64,代码来源:SaslRpcClient.java

示例10: createSaslClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
/**
 * Try to create a SaslClient for an authentication type.  May return
 * null if the type isn't supported or the client lacks the required
 * credentials.
 * 
 * @param authType - the requested authentication method
 * @return SaslClient for the authType or null
 * @throws SaslException - error instantiating client
 * @throws IOException - misc errors
 */
private SaslClient createSaslClient(SaslAuth authType)
    throws SaslException, IOException {
  String saslUser = null;
  // SASL requires the client and server to use the same proto and serverId
  // if necessary, auth types below will verify they are valid
  final String saslProtocol = authType.getProtocol();
  final String saslServerName = authType.getServerId();
  Map<String, String> saslProperties =
    saslPropsResolver.getClientProperties(serverAddr.getAddress());  
  CallbackHandler saslCallback = null;
  
  final AuthMethod method = AuthMethod.valueOf(authType.getMethod());
  switch (method) {
    case TOKEN: {
      Token<?> token = getServerToken(authType);
      if (token == null) {
        return null; // tokens aren't supported or user doesn't have one
      }
      saslCallback = new SaslClientCallbackHandler(token);
      break;
    }
    case KERBEROS: {
      if (ugi.getRealAuthenticationMethod().getAuthMethod() !=
          AuthMethod.KERBEROS) {
        return null; // client isn't using kerberos
      }
      String serverPrincipal = getServerPrincipal(authType);
      if (serverPrincipal == null) {
        return null; // protocol doesn't use kerberos
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server's Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
      break;
    }
    default:
      throw new IOException("Unknown authentication method " + method);
  }
  
  String mechanism = method.getMechanismName();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Creating SASL " + mechanism + "(" + method + ") "
        + " client to authenticate to service at " + saslServerName);
  }
  return Sasl.createSaslClient(
      new String[] { mechanism }, saslUser, saslProtocol, saslServerName,
      saslProperties, saslCallback);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:60,代码来源:SaslRpcClient.java

示例11: main

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        Map<String, String> props = new TreeMap<String, String>();
        props.put(Sasl.QOP, "auth");

        // client
        SaslClient client = Sasl.createSaslClient(new String[]{ DIGEST_MD5 },
            "user1", "xmpp", "127.0.0.1", props, authCallbackHandler);
        if (client == null) {
            throw new Exception("Unable to find client implementation for: " +
                DIGEST_MD5);
        }

        byte[] response = client.hasInitialResponse()
            ? client.evaluateChallenge(EMPTY) : EMPTY;
        logger.info("initial: " + new String(response));

        // server
        byte[] challenge = null;
        SaslServer server = Sasl.createSaslServer(DIGEST_MD5, "xmpp",
          "127.0.0.1", props, authCallbackHandler);
        if (server == null) {
            throw new Exception("Unable to find server implementation for: " +
                DIGEST_MD5);
        }

        if (!client.isComplete() || !server.isComplete()) {
            challenge = server.evaluateResponse(response);

            logger.info("challenge: " + new String(challenge));

            if (challenge != null) {
                response = client.evaluateChallenge(challenge);
            }
        }

        String challengeString = new String(challenge, "UTF-8").toLowerCase();

        if (challengeString.indexOf("\"md5-sess\"") > 0 ||
            challengeString.indexOf("\"utf-8\"") > 0) {
            throw new Exception("The challenge string's charset and " +
                "algorithm values must not be enclosed within quotes");
        }

        client.dispose();
        server.dispose();
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:NoQuoteParams.java

示例12: createSaslClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
private SaslClient createSaslClient() throws SaslException {
    Map<String, String> props = new HashMap<>();
    props.put(Sasl.QOP, qop);
    return Sasl.createSaslClient(new String[] {mechanism}, USER_ID,
            PROTOCOL, host, props, callback);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:ClientServerTest.java

示例13: main

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        pwfile = "pw.properties";
        namesfile = "names.properties";
        auto = true;
    } else {
        int i = 0;
        if (args[i].equals("-m")) {
            i++;
            auto = false;
        }
        if (args.length > i) {
            pwfile = args[i++];

            if (args.length > i) {
                namesfile = args[i++];
            }
        } else {
            pwfile = "pw.properties";
            namesfile = "names.properties";
        }
    }

    CallbackHandler clntCbh = new ClientCallbackHandler(auto);

    CallbackHandler srvCbh =
        new PropertiesFileCallbackHandler(pwfile, namesfile, null);

    SaslClient clnt = Sasl.createSaslClient(
        new String[]{MECH}, null, PROTOCOL, SERVER_FQDN, null, clntCbh);

    SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, null,
        srvCbh);

    if (clnt == null) {
        throw new IllegalStateException(
            "Unable to find client impl for " + MECH);
    }
    if (srv == null) {
        throw new IllegalStateException(
            "Unable to find server impl for " + MECH);
    }

    byte[] response = (clnt.hasInitialResponse()?
        clnt.evaluateChallenge(EMPTY) : EMPTY);
    byte[] challenge;

    while (!clnt.isComplete() || !srv.isComplete()) {
        challenge = srv.evaluateResponse(response);

        if (challenge != null) {
            response = clnt.evaluateChallenge(challenge);
        }
    }

    if (clnt.isComplete() && srv.isComplete()) {
        if (verbose) {
            System.out.println("SUCCESS");
            System.out.println("authzid is " + srv.getAuthorizationID());
        }
    } else {
        throw new IllegalStateException("FAILURE: mismatched state:" +
            " client complete? " + clnt.isComplete() +
            " server complete? " + srv.isComplete());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:67,代码来源:Cram.java

示例14: createDigestSaslClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
protected SaslClient createDigestSaslClient(String[] mechanismNames,
    String saslDefaultRealm, CallbackHandler saslClientCallbackHandler)
    throws IOException {
  return Sasl.createSaslClient(mechanismNames, null, null, saslDefaultRealm,
      SaslUtil.SASL_PROPS, saslClientCallbackHandler);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:7,代码来源:HBaseSaslRpcClient.java

示例15: createKerberosSaslClient

import javax.security.sasl.Sasl; //导入方法依赖的package包/类
protected SaslClient createKerberosSaslClient(String[] mechanismNames,
    String userFirstPart, String userSecondPart) throws IOException {
  return Sasl.createSaslClient(mechanismNames, null, userFirstPart,
      userSecondPart, SaslUtil.SASL_PROPS, null);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:6,代码来源:HBaseSaslRpcClient.java


注:本文中的javax.security.sasl.Sasl.createSaslClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。