Java Code Examples for org.apache.qpid.proton.engine.Transport#sasl()

The following examples show how to use org.apache.qpid.proton.engine.Transport#sasl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HonoSaslAuthenticator.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void init(final NetSocket socket, final ProtonConnection protonConnection, final Transport transport) {

    LOG.debug("initializing SASL authenticator");
    this.protonConnection = protonConnection;
    this.sasl = transport.sasl();
    sasl.server();
    sasl.allowSkip(false);
    sasl.setMechanisms(authenticationService.getSupportedSaslMechanisms());
    if (socket.isSsl() && Arrays.asList(authenticationService.getSupportedSaslMechanisms())
            .contains(AuthenticationConstants.MECHANISM_EXTERNAL)) {
        LOG.debug("client connected using TLS, extracting client certificate chain");
        try {
            final Certificate cert = socket.sslSession().getPeerCertificates()[0];
            if (cert instanceof X509Certificate) {
                clientCertificate = (X509Certificate) cert;
            }
        } catch (final SSLPeerUnverifiedException e) {
            LOG.debug("could not extract client certificate chain, maybe client uses other mechanism than SASL EXTERNAL");
        }
    }
}
 
Example 2
Source File: AmqpAdapterSaslAuthenticatorFactory.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void init(final NetSocket socket, final ProtonConnection protonConnection, final Transport transport) {
    LOG.trace("initializing SASL authenticator");
    this.protonConnection = protonConnection;
    this.sasl = transport.sasl();
    sasl.server();
    sasl.allowSkip(false);
    sasl.setMechanisms(getSupportedMechanisms());
    if (socket.isSsl()) {
        LOG.trace("client connected through a secured port");
        sslSession = socket.sslSession();
    }
}
 
Example 3
Source File: Driver.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public void selected() throws IOException {
    SocketChannel sock = socket.accept();
    System.out.println("ACCEPTED: " + sock);
    Connection conn = Connection.Factory.create();
    conn.collect(collector);
    Transport transport = Transport.Factory.create();
    Sasl sasl = transport.sasl();
    sasl.setMechanisms("ANONYMOUS");
    sasl.server();
    sasl.done(Sasl.PN_SASL_OK);
    transport.bind(conn);
    new ChannelHandler(sock, SelectionKey.OP_READ, transport);
}
 
Example 4
Source File: Driver.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private static Transport makeTransport(Connection conn) {
    Transport transport = Transport.Factory.create();
    Sasl sasl = transport.sasl();
    sasl.setMechanisms("ANONYMOUS");
    sasl.client();
    transport.bind(conn);
    return transport;
}
 
Example 5
Source File: IOHandler.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void handleOpen(Reactor reactor, Event event) {
    Connection connection = event.getConnection();
    if (connection.getRemoteState() != EndpointState.UNINITIALIZED) {
        return;
    }
    // Outgoing Reactor connections set the virtual host automatically using the
    // following rules:
    String vhost = connection.getHostname();
    if (vhost == null) {
        // setHostname never called, use the host from the connection's
        // socket address as the default virtual host:
        String conAddr = reactor.getConnectionAddress(connection);
        if (conAddr != null) {
            Address addr = new Address(conAddr);
            connection.setHostname(addr.getHost());
        }
    } else if (vhost.isEmpty()) {
        // setHostname called explictly with a null string. This allows
        // the application to completely avoid sending a virtual host
        // name
        connection.setHostname(null);
    } else {
        // setHostname set by application - use it.
    }
    Transport transport = Proton.transport();

    int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize();
    if (maxFrameSizeOption != 0) {
        transport.setMaxFrameSize(maxFrameSizeOption);
    }

    if (reactor.getOptions().isEnableSaslByDefault()) {
        Sasl sasl = transport.sasl();
        sasl.client();
        sasl.setMechanisms("ANONYMOUS");
    }

    transport.bind(connection);
}
 
Example 6
Source File: ProtonSaslServerAuthenticatorImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
  this.sasl = transport.sasl();
  sasl.server();
  sasl.allowSkip(false);
  sasl.setMechanisms(ProtonSaslAnonymousImpl.MECH_NAME);
  succeeded = false;
}
 
Example 7
Source File: ProtonSaslClientAuthenticatorImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
  this.socket = socket;
  this.connection = protonConnection;
  this.sasl = transport.sasl();
  sasl.client();
}
 
Example 8
Source File: ProtonServerImplTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
  this.protonConnection = protonConnection;
  this.sasl = transport.sasl();
  sasl.server();
  sasl.allowSkip(false);
  sasl.setMechanisms(PLAIN);
}
 
Example 9
Source File: ProtonServerImplTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
  this.sasl = transport.sasl();
  sasl.server();
  sasl.allowSkip(false);
  sasl.setMechanisms(PLAIN);
}
 
Example 10
Source File: AcceptorImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Selectable selectable) {
    Reactor reactor = selectable.getReactor();
    try {
        SocketChannel socketChannel = ((ServerSocketChannel)selectable.getChannel()).accept();
        if (socketChannel == null) {
            throw new ReactorInternalException("Selectable readable, but no socket to accept");
        }
        Handler handler = BaseHandler.getHandler(AcceptorImpl.this);
        if (handler == null) {
            handler = reactor.getHandler();
        }
        Connection conn = reactor.connection(handler);
        Record conn_recs = conn.attachments();
        conn_recs.set(CONNECTION_ACCEPTOR_KEY, Acceptor.class, AcceptorImpl.this);
        InetSocketAddress peerAddr = (InetSocketAddress)socketChannel.getRemoteAddress();
        if (peerAddr != null) {
            Address addr = new Address();
            addr.setHost(peerAddr.getHostString());
            addr.setPort(Integer.toString(peerAddr.getPort()));
            conn_recs.set(ReactorImpl.CONNECTION_PEER_ADDRESS_KEY, Address.class, addr);
        }
        Transport trans = Proton.transport();

        int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize();
        if (maxFrameSizeOption != 0) {
            trans.setMaxFrameSize(maxFrameSizeOption);
        }

        if(reactor.getOptions().isEnableSaslByDefault()) {
            Sasl sasl = trans.sasl();
            sasl.server();
            sasl.setMechanisms("ANONYMOUS");
            sasl.done(SaslOutcome.PN_SASL_OK);
        }
        trans.bind(conn);
        IOHandler.selectableTransport(reactor, socketChannel.socket(), trans);
    } catch(IOException ioException) {
        sel.error();
    }
}