Java 8 SaslClient - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SaslClient class.

This code example shows how to use the following methods:getNegotiatedProperty, isComplete
    public void opened(Connection conn) 
    { 
        if (conn.getSaslClient() != null)
        { 
            saslClient = conn.getSaslClient();
            if (saslClient.isComplete() && "auth-conf".equals(saslClient.getNegotiatedProperty(Sasl.QOP)))
            {                 
                sendBuffSize = Integer.parseInt(
                        (String)saslClient.getNegotiatedProperty(Sasl.RAW_SEND_SIZE));
                recvBuffSize = Integer.parseInt(
                        (String)saslClient.getNegotiatedProperty(Sasl.MAX_BUFFER));
                securityLayerEstablished(); 
                securityLayerEstablished = true;
            } 
        } 
    } 
     
    public void exception(Connection conn, ConnectionException exception){}
    public void closed(Connection conn) {}
     
6
CodeRank
This code example shows how to use the following methods:dispose, unwrap
      byte[] saslToken;
      try { 
         int length = inStream.readInt();
         saslToken = new byte[length];
         inStream.readFully(saslToken);
         buffer = saslClient.unwrap(saslToken, 0, length);
      } catch (EOFException e) {
         return -1; 
      } catch (SaslException se) {
         try { 
            disposeSasl(); 
         } catch (SaslException e) {
         } 
         throw se;
      } 
      bufferPtr = 0;
      bufferLength = buffer.length;
      return bufferLength;
   } 
 

6
CodeRank
This code example shows how to use the following methods:dispose, wrap
      } 
   } 
 
   private void wrapAndWrite() throws IOException {
      try { 
         byte[] saslToken = saslClient.wrap(buffer.toByteArray(), 0, buffer.size());
         writeInt(saslToken.length);
         outStream.write(saslToken);
         buffer.reset();
      } catch (SaslException se) {
         try { 
            saslClient.dispose();
         } catch (SaslException ignored) {
         } 
         throw se;
      } 
   } 
   /** 
    * Flushes this output stream 
    * 
6
CodeRank
This code example shows how to use the following methods:dispose, wrap
   * @exception SaslException 
   *              if a SASL error occurs. 
   */ 
  private void disposeSasl() throws SaslException {
    if (saslClient != null) {
      saslClient.dispose();
    } 
    if (saslServer != null) {
      saslServer.dispose();
    } 
  } 
 
  /** 
   * Writes the specified byte to this output stream. 
   *  
   * @param b 
   *          the <code>byte</code>. 
   * @exception IOException 
   *              if an I/O error occurs. 
   */ 

6
CodeRank
This code example shows how to use the following methods:evaluateChallenge, hasInitialResponse
   * @throws IOException 
   */ 
  public SaslTokenMessageRequest firstToken() 
    throws IOException {
    byte[] saslToken = new byte[0];
    if (saslClient.hasInitialResponse()) {
      saslToken = saslClient.evaluateChallenge(saslToken);
    } 
    SaslTokenMessageRequest saslTokenMessage =
        new SaslTokenMessageRequest(); 
    saslTokenMessage.setSaslToken(saslToken);
    return saslTokenMessage;
  } 
 
  public boolean isComplete() { 
    return saslClient.isComplete();
  } 
 
  /** 
   * Respond to server's SASL token. 
6
CodeRank
This code example shows how to use the following methods:evaluateChallenge, hasInitialResponse
 
    protected void authenticate() throws IOException, XmppException {
    	 
        String authenticationText = null;
        try { 
            if(sc.hasInitialResponse()) {
                byte[] response = sc.evaluateChallenge(new byte[0]);
                //authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES); 
                authenticationText = Base64.encodeBase64String(response);
            } 
        } catch (SaslException e) {
            throw new XmppException("SASL authentication failed", e);
        } 
 
        // Send the authentication to the server 
        connection.send(new AuthMechanism(getName(), authenticationText));
    } 
 
 
    /** 
5
CodeRank
This code example shows how to use the following methods:isComplete
   * 
   * @return true if SASL negotiation is complete 
   */ 
  public boolean isComplete() { 
    if (saslClient != null) {
      return saslClient.isComplete();
    } else { 
      return saslServer.isComplete();
    } 
  } 
 
  /** 
   * Return some input/output streams that may henceforth have their 
   * communication encrypted, depending on the negotiated quality of protection. 
   * 
   * @param out output stream to wrap 
   * @param in input stream to wrap 
   * @return IOStreamPair wrapping the streams 
   */ 
  public IOStreamPair createStreamPair(DataOutputStream out,
5
CodeRank
This code example shows how to use the following methods:dispose
   * @exception SaslException 
   *              if a SASL error occurs. 
   */ 
  private void disposeSasl() throws SaslException {
    if (saslClient != null) {
      saslClient.dispose();
    } 
    if (saslServer != null) {
      saslServer.dispose();
    } 
  } 
 
  /** 
   * Constructs a SASLInputStream from an InputStream and a SaslServer <br> 
   * Note: if the specified InputStream or SaslServer is null, a 
   * NullPointerException may be thrown later when they are used. 
   *  
   * @param inStream 
   *          the InputStream to be processed 
   * @param saslServer 
5
CodeRank
This code example shows how to use the following methods:dispose
      try { 
         if (socketInputStream != null) socketInputStream.close();
         if (socketOutputStream != null) socketOutputStream.close();
         if (socketChannel != null) socketChannel.close();
         if (socket != null) socket.close();
         if (saslClient != null) saslClient.dispose();
         if (trace) {
            log.tracef("Successfully closed socket: %s", socket);
         } 
      } catch (IOException e) {
         invalid = true;
         log.errorClosingSocket(this, e);
         // Just in case an exception is thrown, make sure they're fully closed 
         Util.close(socketInputStream, socketOutputStream, socketChannel);
         Util.close(socket);
      } 
   } 
 
   public boolean isValid() { 
      return !socket.isClosed() && !invalid;
5
CodeRank
This code example shows how to use the following methods:dispose
        _cramMd5SaslClient = Sasl.createSaslClient(mechanisms, authorizationId, protocol, serverName, props, cbh);
    } 
 
    public void dispose() throws SaslException_cramMd5SaslClient.dispose();
    } 
 
    public String getMechanismName()
    { 
        return CRAMMD5HashedSaslClientFactory.MECHANISM; 
    } 
 
    public byte[] evaluateChallenge(byte[] challenge) throws SaslException
    { 
        return _cramMd5SaslClient.evaluateChallenge(challenge);
    } 
 
 
    public Object getNegotiatedProperty(String propName)
4
CodeRank
See Code Examples for Java 8 SaslClient Methods: