Example #1
0
  public void receiveSaslInit(final SaslInit saslInit) {
    Symbol mechanism = saslInit.getMechanism();
    final Binary initialResponse = saslInit.getInitialResponse();
    byte[] response = initialResponse == null ? new byte[0] : initialResponse.getArray();

    try {
      _saslServer = _saslServerProvider.getSaslServer(mechanism.toString(), "localhost");

      // Process response from the client
      byte[] challenge = _saslServer.evaluateResponse(response != null ? response : new byte[0]);

      if (_saslServer.isComplete()) {
        SaslOutcome outcome = new SaslOutcome();

        outcome.setCode(SaslCode.OK);
        _saslFrameOutput.send(new SASLFrame(outcome), null);
        synchronized (getLock()) {
          _saslComplete = true;
          _authenticated = true;
          getLock().notifyAll();
        }

        if (_onSaslCompleteTask != null) {
          _onSaslCompleteTask.run();
        }

      } else {
        SaslChallenge challengeBody = new SaslChallenge();
        challengeBody.setChallenge(new Binary(challenge));
        _saslFrameOutput.send(new SASLFrame(challengeBody), null);
      }
    } catch (SaslException e) {
      SaslOutcome outcome = new SaslOutcome();

      outcome.setCode(SaslCode.AUTH);
      _saslFrameOutput.send(new SASLFrame(outcome), null);
      synchronized (getLock()) {
        _saslComplete = true;
        _authenticated = false;
        getLock().notifyAll();
      }
      if (_onSaslCompleteTask != null) {
        _onSaslCompleteTask.run();
      }
    }
  }
Example #2
0
  public void receiveSaslResponse(final SaslResponse saslResponse) {
    final Binary responseBinary = saslResponse.getResponse();
    byte[] response = responseBinary == null ? new byte[0] : responseBinary.getArray();

    try {

      // Process response from the client
      byte[] challenge = _saslServer.evaluateResponse(response != null ? response : new byte[0]);

      if (_saslServer.isComplete()) {
        SaslOutcome outcome = new SaslOutcome();

        outcome.setCode(SaslCode.OK);
        _saslFrameOutput.send(new SASLFrame(outcome), null);
        synchronized (getLock()) {
          _saslComplete = true;
          _authenticated = true;
          getLock().notifyAll();
        }
        if (_onSaslCompleteTask != null) {
          _onSaslCompleteTask.run();
        }

      } else {
        SaslChallenge challengeBody = new SaslChallenge();
        challengeBody.setChallenge(new Binary(challenge));
        _saslFrameOutput.send(new SASLFrame(challengeBody), null);
      }
    } catch (SaslException e) {
      SaslOutcome outcome = new SaslOutcome();

      outcome.setCode(SaslCode.AUTH);
      _saslFrameOutput.send(new SASLFrame(outcome), null);
      synchronized (getLock()) {
        _saslComplete = true;
        _authenticated = false;
        getLock().notifyAll();
      }
      if (_onSaslCompleteTask != null) {
        _onSaslCompleteTask.run();
      }
    }
  }