• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Sasl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.qpid.proton.engine.Sasl的典型用法代码示例。如果您正苦于以下问题:Java Sasl类的具体用法?Java Sasl怎么用?Java Sasl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sasl类属于org.apache.qpid.proton.engine包,在下文中一共展示了Sasl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: performSaslSteps

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
private void performSaslSteps(Connection connection, InputStream in,
                              OutputStream out,
                              SaslMechanism mechanism) throws IOException, LoginException {
    Transport transport = connection.getTransport();
    Sasl sasl = transport.sasl();
    do {

        readFromNetwork(connection, in, () ->
            !(EnumSet.of(PN_SASL_PASS, PN_SASL_FAIL).contains(sasl.getState())
            || (sasl.getState() == PN_SASL_STEP && sasl.pending() > 0)));

        if (sasl.pending() > 0) {
            byte[] challenge = new byte[sasl.pending()];
            byte[] response = mechanism.getResponse(challenge);
            if (sasl.getState() == PN_SASL_STEP) {
                sasl.send(response, 0, response.length);
                writeToNetwork(connection, out);
            }
        }

    } while (sasl.getState() == PN_SASL_STEP);
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:23,代码来源:SaslDelegatingLogin.java


示例2: process

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public void process(final Handler<Boolean> completionHandler) {
    if (sasl == null) {
        throw new IllegalStateException("Init was not called with the associated transport");
    }
    // Note we do not record the identity with which the client authenticated, nor to we take any notice of
    // an alternative identity passed in the response
    boolean done = false;
    String[] remoteMechanisms = sasl.getRemoteMechanisms();
    if (remoteMechanisms.length > 0) {
        String chosen = remoteMechanisms[0];
        if (ProtonSaslExternalImpl.MECH_NAME.equals(chosen)) {
            // TODO - should handle the case of no initial response per the SASL spec, (i.e. send an empty challenge)
            // however this was causing errors in some clients
            // Missing initial response can be detected with: sasl.recv(new byte[0], 0, 0) == -1
            sasl.done(Sasl.SaslOutcome.PN_SASL_OK);
            succeeded = true;
        } else {
            sasl.done(Sasl.SaslOutcome.PN_SASL_AUTH);
        }
        done = true;
    }
    completionHandler.handle(done);
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:25,代码来源:ExternalSaslAuthenticator.java


示例3: sasl

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public Sasl sasl()
{
    if(_sasl == null)
    {
        if(_processingStarted)
        {
            throw new IllegalStateException("Sasl can't be initiated after transport has started processing");
        }

        init();
        _sasl = new SaslImpl(this, _remoteMaxFrameSize);
        TransportWrapper transportWrapper = _sasl.wrap(_inputProcessor, _outputProcessor);
        _inputProcessor = transportWrapper;
        _outputProcessor = transportWrapper;
    }
    return _sasl;

}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:20,代码来源:TransportImpl.java


示例4: onSaslInit

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public void onSaslInit(Sasl s, Transport t)
{
    assertArrayEquals("Server should now know the client's chosen mechanism.",
            new String[]{TESTMECH1}, s.getRemoteMechanisms());

    byte[] serverReceivedInitialBytes = new byte[s.pending()];
    s.recv(serverReceivedInitialBytes, 0, serverReceivedInitialBytes.length);

    assertArrayEquals("Server should now know the client's initial response.",
            INITIAL_RESPONSE_BYTES, serverReceivedInitialBytes);

    s.send(CHALLENGE_BYTES, 0, CHALLENGE_BYTES.length);

    assertFalse("Should not have already received init", initReceived.getAndSet(true));
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:17,代码来源:SaslTest.java


示例5: channelActive

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) {
    synchronized (lock) {
        System.out.println("ACTIVE");
        transport = Transport.Factory.create();
        transport.setContext(ctx);

        Sasl sasl = transport.sasl();
        sasl.setMechanisms("ANONYMOUS");
        sasl.server();
        sasl.done(Sasl.PN_SASL_OK);

        connection = Connection.Factory.create();
        collector = Collector.Factory.create();
        connection.collect(collector);
        transport.bind(connection);

        // XXX: really we should fire both of these off of an
        //      initial transport event
        write(ctx);
        int capacity = transport.capacity();
        if (capacity > 0) {
            ctx.read();
        }
    }
}
 
开发者ID:rhs,项目名称:qpid-proton-netty,代码行数:27,代码来源:ProtonNettyHandler.java


示例6: init

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
void init() throws NetworkException
{
    synchronized (_lock)
    {
        _collector = Collector.Factory.create();
        _transport = Transport.Factory.create();
        _connection = Connection.Factory.create();
        String id = _settings.getId();
        _connection.collect(_collector);
        _connection.setContainer(id == null || id.trim().equals("") ? UUID.randomUUID().toString() : id);
        _connection.setHostname(_settings.getHost());
        _transport.bind(_connection);
        Sasl sasl = _transport.sasl();
        sasl.client();
        sasl.setMechanisms(new String[] { "ANONYMOUS" });
        _connection.open();
        _connected.set(true);
        write();
    }
}
 
开发者ID:rajith77,项目名称:splash,代码行数:21,代码来源:BaseConnection.java


示例7: handleSaslMechanisms

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
public void handleSaslMechanisms(Sasl sasl, Transport transport) {
    try {
        String[] remoteMechanisms = sasl.getRemoteMechanisms();
        if (remoteMechanisms != null && remoteMechanisms.length != 0) {
            try {
                mechanism = mechanismFinder.apply(remoteMechanisms);
            } catch (JMSSecurityRuntimeException jmssre){
                recordFailure("Could not find a suitable SASL mechanism. " + jmssre.getMessage(), jmssre);
                return;
            }

            byte[] response = mechanism.getInitialResponse();
            if (response != null) {
                sasl.send(response, 0, response.length);
            }
            sasl.setMechanisms(mechanism.getName());
        }
    } catch (Throwable error) {
        recordFailure("Exception while processing SASL init: " + error.getMessage(), error);
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:22,代码来源:AmqpSaslAuthenticator.java


示例8: handleSaslOutcome

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
public void handleSaslOutcome(Sasl sasl, Transport transport) {
    try {
        switch (sasl.getState()) {
            case PN_SASL_FAIL:
                handleSaslFail();
                break;
            case PN_SASL_PASS:
                handleSaslCompletion(sasl);
                break;
            default:
                break;
        }
    } catch (Throwable error) {
        recordFailure(error.getMessage(), error);
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:17,代码来源:AmqpSaslAuthenticator.java


示例9: processSaslExchange

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
public void processSaslExchange() {
    if (protonSasl.getRemoteMechanisms().length > 0) {

        String[] mechanisms = protonSasl.getRemoteMechanisms();
        if (mechanisms != null && mechanisms.length > 0) {
            LOG.debug("SASL [{}} Handshake started.", mechanisms[0]);

            if (mechanisms[0].equalsIgnoreCase("PLAIN")) {
                byte[] data = new byte[protonSasl.pending()];
                protonSasl.recv(data, 0, data.length);
                protonSasl.done(Sasl.SaslOutcome.PN_SASL_OK);
            } else if (mechanisms[0].equalsIgnoreCase("ANONYMOUS")) {
                protonSasl.done(Sasl.SaslOutcome.PN_SASL_OK);
            } else {
                protonSasl.done(Sasl.SaslOutcome.PN_SASL_PERM);
            }

        } else {
            LOG.info("SASL: could not find supported mechanism");
            protonSasl.done(Sasl.SaslOutcome.PN_SASL_PERM);
        }
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:24,代码来源:NettySimpleAmqpServer.java


示例10: AmqpConnection

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
public AmqpConnection(AmqpProvider provider, Connection protonConnection, Sasl sasl, JmsConnectionInfo info) {
    super(info, protonConnection);

    this.provider = provider;
    this.remoteURI = provider.getRemoteURI();

    if (sasl != null) {
        this.authenticator = new AmqpSaslAuthenticator(sasl, info);
    }

    this.info.getConnectionId().setProviderHint(this);

    this.queuePrefix = info.getQueuePrefix();
    this.topicPrefix = info.getTopicPrefix();
    this.tempQueuePrefix = info.getTempQueuePrefix();
    this.tempTopicPrefix = info.getTempTopicPrefix();

    // Create a Session for this connection that is used for Temporary Destinations
    // and perhaps later on management and advisory monitoring.
    JmsSessionInfo sessionInfo = new JmsSessionInfo(this.info, -1);
    sessionInfo.setAcknowledgementMode(Session.AUTO_ACKNOWLEDGE);

    this.connectionSession = new AmqpSession(this, sessionInfo);
}
 
开发者ID:fusesource,项目名称:hawtjms,代码行数:25,代码来源:AmqpConnection.java


示例11: chooseSaslMechanismAndSendInit

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
private SaslMechanism chooseSaslMechanismAndSendInit(Connection connection, InputStream in, OutputStream out) throws LoginException, IOException {

        Transport transport = connection.getTransport();
        Sasl sasl = transport.sasl();
        SaslMechanism mechanism = null;
        // read from network until we get a sasl-mechanisms
        readFromNetwork(connection, in, () -> sasl.getState() == PN_SASL_IDLE && sasl.getRemoteMechanisms().length == 0);

        for (SaslMechanismFactory factory : saslFactories) {
            if (Arrays.asList(sasl.getRemoteMechanisms()).contains(factory.getName())) {
                mechanism = factory.newInstance(callbackHandler, sharedState, options);
                if (mechanism != null) {
                    sasl.setRemoteHostname(saslHostname);
                    sasl.setMechanisms(factory.getName());
                    byte[] initialResponse = mechanism.getResponse(null);
                    if (initialResponse != null && initialResponse.length != 0) {
                        sasl.send(initialResponse, 0, initialResponse.length);
                    }
                    break;
                }
            }
        }

        if (mechanism == null) {
            throw new LoginException("Unable to authenticate using SASL delegation, no supported mechanisms");
        }

        writeToNetwork(connection, out);
        return mechanism;
    }
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:31,代码来源:SaslDelegatingLogin.java


示例12: selected

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:14,代码来源:Driver.java


示例13: makeTransport

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:9,代码来源:Driver.java


示例14: handleOpen

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:40,代码来源:IOHandler.java


示例15: testOptionalChallengeResponseStepOmitted

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
/** 5.3.2 SASL Negotiation. ...challenge/response step can occur zero or more times*/
@Test
public void testOptionalChallengeResponseStepOmitted() throws Exception
{
    getClient().transport = Proton.transport();
    getServer().transport = Proton.transport();

    Sasl clientSasl = getClient().transport.sasl();
    clientSasl.client();
    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());

    Sasl serverSasl = getServer().transport.sasl();
    serverSasl.server();
    serverSasl.setMechanisms(TESTMECH1);
    assertEquals("Server should not yet know the remote's chosen mechanism.",
                 0,
                 serverSasl.getRemoteMechanisms().length);

    pumpClientToServer();
    pumpServerToClient();

    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
    clientSasl.setMechanisms(TESTMECH1);

    pumpClientToServer();

    serverSasl.done(SaslOutcome.PN_SASL_OK);
    pumpServerToClient();

    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_OK, clientSasl.getOutcome());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:32,代码来源:SaslTest.java


示例16: testAuthenticationFails

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
/**
 *  5.3.3.6 Connection authentication failed due to an unspecified problem with the supplied credentials.
 */
@Test
public void testAuthenticationFails() throws Exception
{
    getClient().transport = Proton.transport();
    getServer().transport = Proton.transport();

    Sasl clientSasl = getClient().transport.sasl();
    clientSasl.client();
    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());

    Sasl serverSasl = getServer().transport.sasl();
    serverSasl.server();
    serverSasl.setMechanisms(TESTMECH1);

    pumpClientToServer();
    pumpServerToClient();

    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
    clientSasl.setMechanisms(TESTMECH1);

    pumpClientToServer();

    serverSasl.done(SaslOutcome.PN_SASL_AUTH);
    pumpServerToClient();
    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_AUTH, clientSasl.getOutcome());

}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:31,代码来源:SaslTest.java


示例17: onSaslResponse

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public void onSaslResponse(Sasl s, Transport t)
{
    byte[] serverReceivedResponseBytes = new byte[s.pending()];
    s.recv(serverReceivedResponseBytes, 0, serverReceivedResponseBytes.length);

    assertArrayEquals("Server should now know the client's response", RESPONSE_BYTES, serverReceivedResponseBytes);

    s.send(ADDITIONAL_DATA_BYTES, 0, ADDITIONAL_DATA_BYTES.length);
    s.done(SaslOutcome.PN_SASL_OK);

    assertFalse("Should not have already received response", responseReceived.getAndSet(true));
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:14,代码来源:SaslTest.java


示例18: onSaslMechanisms

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public void onSaslMechanisms(Sasl s, Transport t)
{
    assertArrayEquals("Client should now know the server's mechanisms.",
            new String[]{TESTMECH1, TESTMECH2}, s.getRemoteMechanisms());
    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, s.getOutcome());

    s.setMechanisms(TESTMECH1);
    s.send(INITIAL_RESPONSE_BYTES, 0, INITIAL_RESPONSE_BYTES.length);

    assertFalse("Should not have already received mechanisms", mechanismsReceived.getAndSet(true));
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:13,代码来源:SaslTest.java


示例19: onSaslChallenge

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public void onSaslChallenge(Sasl s, Transport t)
{
    byte[] clientReceivedChallengeBytes = new byte[s.pending()];
    s.recv(clientReceivedChallengeBytes, 0, clientReceivedChallengeBytes.length);

    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, s.getOutcome());
    assertArrayEquals("Client should now know the server's challenge",
                      CHALLENGE_BYTES, clientReceivedChallengeBytes);

    s.send(RESPONSE_BYTES, 0, RESPONSE_BYTES.length);

    assertFalse("Should not have already received challenge", challengeReceived.getAndSet(true));
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:15,代码来源:SaslTest.java


示例20: onSaslOutcome

import org.apache.qpid.proton.engine.Sasl; //导入依赖的package包/类
@Override
public void onSaslOutcome(Sasl s, Transport t)
{
    assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_OK, s.getOutcome());

    byte[] clientReceivedAdditionalBytes = new byte[s.pending()];
    s.recv(clientReceivedAdditionalBytes, 0, clientReceivedAdditionalBytes.length);

    assertArrayEquals("Client should now know the server's outcome additional data", clientReceivedAdditionalBytes,
            clientReceivedAdditionalBytes);

    assertFalse("Should not have already received outcome", outcomeReceived.getAndSet(true));
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:14,代码来源:SaslTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GLES11类代码示例发布时间:2022-05-22
下一篇:
Java HeuristicCommitException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap