當前位置: 首頁>>代碼示例>>Java>>正文


Java SaslClient.isComplete方法代碼示例

本文整理匯總了Java中javax.security.sasl.SaslClient.isComplete方法的典型用法代碼示例。如果您正苦於以下問題:Java SaslClient.isComplete方法的具體用法?Java SaslClient.isComplete怎麽用?Java SaslClient.isComplete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.security.sasl.SaslClient的用法示例。


在下文中一共展示了SaslClient.isComplete方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import javax.security.sasl.SaslClient; //導入方法依賴的package包/類
@Override
public <CC extends ClientConnection> SaslMessage process(SaslChallengeContext<CC> context) throws Exception {
  final SaslClient saslClient = context.connection.getSaslClient();

  if (saslClient.isComplete()) {
    handleSuccess(context);
    return null;
  } else {
    // server completed before client; so try once, fail otherwise
    evaluateChallenge(context.ugi, saslClient, context.challenge.getData().toByteArray()); // discard response

    if (saslClient.isComplete()) {
      handleSuccess(context);
      return null;
    } else {
      throw new SaslException("Server allegedly succeeded authentication, but client did not. Suspicious?");
    }
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:20,代碼來源:AuthenticationOutcomeListener.java

示例2: testSaslServerClient

import javax.security.sasl.SaslClient; //導入方法依賴的package包/類
private void testSaslServerClient(SaslServer server, SaslClient client) throws SaslException {
    byte[] message = new byte[]{};
    if (client.hasInitialResponse()) message = client.evaluateChallenge(message);
    while(!server.isComplete() || !client.isComplete()) {
        if (!server.isComplete()) message = server.evaluateResponse(message);
        if (!client.isComplete()) message = client.evaluateChallenge(message);
    }
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:9,代碼來源:SaslTestCase.java

示例3: main

import javax.security.sasl.SaslClient; //導入方法依賴的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

示例4: run

import javax.security.sasl.SaslClient; //導入方法依賴的package包/類
public void run() throws Exception {
    System.out.println("Host:" + host + " port: "
            + port);
    try (SaslEndpoint endpoint = SaslEndpoint.create(host, port)) {
        negotiateMechanism(endpoint);
        SaslClient client = createSaslClient();
        byte[] data = new byte[0];
        if (client.hasInitialResponse()) {
            data = client.evaluateChallenge(data);
        }
        endpoint.send(new Message(SaslStatus.CONTINUE, data));
        Message msg = getMessage(endpoint.receive());
        while (!client.isComplete()
                && msg.getStatus() != SaslStatus.FAILURE) {
            switch (msg.getStatus()) {
                case CONTINUE:
                    System.out.println("client continues");
                    data = client.evaluateChallenge(msg.getData());
                    endpoint.send(new Message(SaslStatus.CONTINUE,
                            data));
                    msg = getMessage(endpoint.receive());
                    break;
                case SUCCESS:
                    System.out.println("client succeeded");
                    data = client.evaluateChallenge(msg.getData());
                    if (data != null) {
                        throw new SaslException("data should be null");
                    }
                    break;
                default:
                    throw new RuntimeException("Wrong status:"
                            + msg.getStatus());
            }
        }

        if (msg.getStatus() == SaslStatus.FAILURE) {
            throw new RuntimeException("Status is FAILURE");
        }
    }

    System.out.println("Done");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:43,代碼來源:ClientServerTest.java

示例5: main

import javax.security.sasl.SaslClient; //導入方法依賴的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

示例6: authenticate

import javax.security.sasl.SaslClient; //導入方法依賴的package包/類
@Override
public void authenticate(Socket sock, String hostName) throws IOException {
    if (!quorumRequireSasl) { // let it through, we don't require auth
        LOG.info("Skipping SASL authentication as {}={}",
                QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED,
                quorumRequireSasl);
        return;
    }
    SaslClient sc = null;
    String principalConfig = SecurityUtils
            .getServerPrincipal(quorumServicePrincipal, hostName);
    try {
        DataOutputStream dout = new DataOutputStream(
                sock.getOutputStream());
        DataInputStream din = new DataInputStream(sock.getInputStream());
        byte[] responseToken = new byte[0];
        sc = SecurityUtils.createSaslClient(learnerLogin.getSubject(),
                principalConfig,
                QuorumAuth.QUORUM_SERVER_PROTOCOL_NAME,
                QuorumAuth.QUORUM_SERVER_SASL_DIGEST, LOG, "QuorumLearner");

        if (sc.hasInitialResponse()) {
            responseToken = createSaslToken(new byte[0], sc, learnerLogin);
        }
        send(dout, responseToken);
        QuorumAuthPacket authPacket = receive(din);
        QuorumAuth.Status qpStatus = QuorumAuth.Status
                .getStatus(authPacket.getStatus());
        while (!sc.isComplete()) {
            switch (qpStatus) {
            case SUCCESS:
                responseToken = createSaslToken(authPacket.getToken(), sc,
                        learnerLogin);
                // we're done; don't expect to send another BIND
                if (responseToken != null) {
                    throw new SaslException(
                            "Protocol error: attempting to send response after completion"
                                    + ". Server addr: "
                                    + sock.getRemoteSocketAddress());
                }
                break;
            case IN_PROGRESS:
                responseToken = createSaslToken(authPacket.getToken(), sc,
                        learnerLogin);
                send(dout, responseToken);
                authPacket = receive(din);
                qpStatus = QuorumAuth.Status
                        .getStatus(authPacket.getStatus());
                break;
            case ERROR:
                throw new SaslException(
                        "Authentication failed against server addr: "
                                + sock.getRemoteSocketAddress());
            default:
                LOG.warn("Unknown status:{}!", qpStatus);
                throw new SaslException(
                        "Authentication failed against server addr: "
                                + sock.getRemoteSocketAddress());
            }
        }

        // Validate status code at the end of authentication exchange.
        checkAuthStatus(sock, qpStatus);
    } finally {
        if (sc != null) {
            try {
                sc.dispose();
            } catch (SaslException e) {
                LOG.error("SaslClient dispose() failed", e);
            }
        }
    }
    return;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:75,代碼來源:SaslQuorumAuthLearner.java


注:本文中的javax.security.sasl.SaslClient.isComplete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。