Search in sources :

Example 1 with Received

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method testProtocolEngineWithNoSaslTLSandExternal.

public void testProtocolEngineWithNoSaslTLSandExternal() throws Exception {
    final Principal principal = () -> "test";
    when(_networkConnection.getPeerPrincipal()).thenReturn(principal);
    allowMechanisms(ExternalAuthenticationManagerImpl.MECHANISM_NAME);
    createEngine(Transport.SSL);
    _protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance().getHeaderIdentifier()));
    Open open = new Open();
    open.setContainerId("testContainerId");
    _frameWriter.send(AMQFrame.createAMQFrame((short) 0, open));
    verify(_virtualHost).registerConnection(any(AMQPConnection.class), any(ConnectionEstablishmentPolicy.class));
    AuthenticatedPrincipal authPrincipal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
    assertNotNull(authPrincipal);
    assertEquals(authPrincipal, new AuthenticatedPrincipal(principal));
}
Also used : ConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 2 with Received

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _networkConnection = mock(ServerNetworkConnection.class);
    when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
    _broker = mock(Broker.class);
    when(_broker.getModel()).thenReturn(BrokerModel.getInstance());
    when(_broker.getNetworkBufferSize()).thenReturn(256 * 1026);
    final TaskExecutor taskExecutor = new TaskExecutorImpl();
    taskExecutor.start();
    when(_broker.getChildExecutor()).thenReturn(taskExecutor);
    when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(_broker.getId()).thenReturn(UUID.randomUUID());
    when(_broker.getEventLogger()).thenReturn(new EventLogger());
    when(((Broker) _broker).getCategoryClass()).thenReturn(Broker.class);
    _port = mock(AmqpPort.class);
    when(_port.getChildExecutor()).thenReturn(taskExecutor);
    when(_port.getCategoryClass()).thenReturn(Port.class);
    when(_port.getModel()).thenReturn(BrokerModel.getInstance());
    final SubjectCreator subjectCreator = mock(SubjectCreator.class);
    _authenticationProvider = mock(AuthenticationProvider.class);
    when(_port.getAuthenticationProvider()).thenReturn(_authenticationProvider);
    _virtualHost = mock(VirtualHost.class);
    when(_virtualHost.getChildExecutor()).thenReturn(taskExecutor);
    when(_virtualHost.getModel()).thenReturn(BrokerModel.getInstance());
    when(_virtualHost.getState()).thenReturn(State.ACTIVE);
    when(_virtualHost.isActive()).thenReturn(true);
    final ArgumentCaptor<AMQPConnection> connectionCaptor = ArgumentCaptor.forClass(AMQPConnection.class);
    final ArgumentCaptor<ConnectionEstablishmentPolicy> establishmentPolicyCaptor = ArgumentCaptor.forClass(ConnectionEstablishmentPolicy.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            _connection = connectionCaptor.getValue();
            return null;
        }
    }).when(_virtualHost).registerConnection(connectionCaptor.capture(), establishmentPolicyCaptor.capture());
    when(_virtualHost.getPrincipal()).thenReturn(mock(VirtualHostPrincipal.class));
    when(_port.getAddressSpace(anyString())).thenReturn(_virtualHost);
    when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(subjectCreator);
    final ArgumentCaptor<Principal> userCaptor = ArgumentCaptor.forClass(Principal.class);
    when(subjectCreator.createSubjectWithGroups(userCaptor.capture())).then(new Answer<Subject>() {

        @Override
        public Subject answer(final InvocationOnMock invocation) throws Throwable {
            Subject subject = new Subject();
            subject.getPrincipals().add(userCaptor.getValue());
            return subject;
        }
    });
    final ByteBufferSender sender = mock(ByteBufferSender.class);
    when(_networkConnection.getSender()).thenReturn(sender);
    AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer().registerMessagingLayer().registerTransactionLayer().registerSecurityLayer();
    _frameWriter = new FrameWriter(registry, new ByteBufferSender() {

        @Override
        public boolean isDirectBufferPreferred() {
            return false;
        }

        @Override
        public void send(final QpidByteBuffer msg) {
            _protocolEngine_1_0_0.received(msg);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() {
        }
    });
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) InetSocketAddress(java.net.InetSocketAddress) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Subject(javax.security.auth.Subject) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter) ConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) VirtualHost(org.apache.qpid.server.model.VirtualHost) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 3 with Received

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method testProtocolEngineWithNoSaslNonTLSandAnon.

public void testProtocolEngineWithNoSaslNonTLSandAnon() throws Exception {
    final Map<String, Object> attrs = Collections.singletonMap(ConfiguredObject.NAME, getTestName());
    final AnonymousAuthenticationManager anonymousAuthenticationManager = (new AnonymousAuthenticationManagerFactory()).create(null, attrs, _broker);
    when(_port.getAuthenticationProvider()).thenReturn(anonymousAuthenticationManager);
    allowMechanisms(AnonymousAuthenticationManager.MECHANISM_NAME);
    createEngine(Transport.TCP);
    _protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance().getHeaderIdentifier()));
    Open open = new Open();
    open.setContainerId("testContainerId");
    _frameWriter.send(AMQFrame.createAMQFrame((short) 0, open));
    verify(_virtualHost).registerConnection(any(AMQPConnection.class), any(ConnectionEstablishmentPolicy.class));
    AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
    assertNotNull(principal);
    assertEquals(principal, new AuthenticatedPrincipal(anonymousAuthenticationManager.getAnonymousPrincipal()));
}
Also used : ConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy) AnonymousAuthenticationManagerFactory(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory) AnonymousAuthenticationManager(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Matchers.anyString(org.mockito.Matchers.anyString) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 4 with Received

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method getSession.

private Session_1_0 getSession(final int channel) {
    Session_1_0 session = _receivingSessions[channel];
    if (session == null) {
        Error error = new Error();
        error.setCondition(ConnectionError.FRAMING_ERROR);
        error.setDescription("Frame received on channel " + channel + " which is not known as a begun session.");
        handleError(error);
    }
    return session;
}
Also used : ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error)

Example 5 with Received

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method receive.

@Override
public void receive(final List<ChannelFrameBody> channelFrameBodies) {
    if (!channelFrameBodies.isEmpty()) {
        PeekingIterator<ChannelFrameBody> itr = Iterators.peekingIterator(channelFrameBodies.iterator());
        boolean cleanExit = false;
        try {
            while (itr.hasNext()) {
                final ChannelFrameBody channelFrameBody = itr.next();
                final int frameChannel = channelFrameBody.getChannel();
                Session_1_0 session = _receivingSessions == null || frameChannel >= _receivingSessions.length ? null : _receivingSessions[frameChannel];
                if (session != null) {
                    final AccessControlContext context = session.getAccessControllerContext();
                    AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
                        ChannelFrameBody channelFrame = channelFrameBody;
                        boolean nextIsSameChannel;
                        do {
                            received(frameChannel, channelFrame.getFrameBody());
                            nextIsSameChannel = itr.hasNext() && frameChannel == itr.peek().getChannel();
                            if (nextIsSameChannel) {
                                channelFrame = itr.next();
                            }
                        } while (nextIsSameChannel);
                        return null;
                    }, context);
                } else {
                    received(frameChannel, channelFrameBody.getFrameBody());
                }
            }
            cleanExit = true;
        } finally {
            if (!cleanExit) {
                while (itr.hasNext()) {
                    final Object frameBody = itr.next().getFrameBody();
                    if (frameBody instanceof Transfer) {
                        ((Transfer) frameBody).dispose();
                    }
                }
            }
        }
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) ChannelFrameBody(org.apache.qpid.server.protocol.v1_0.type.transport.ChannelFrameBody) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)

Aggregations

AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)9 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)9 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)7 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)6 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)6 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)6 Test (org.junit.Test)6 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)5 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)5 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)5 ConnectionEstablishmentPolicy (org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy)5 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 ConnectionError (org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError)4 InetSocketAddress (java.net.InetSocketAddress)3 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)3 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)3 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)3 LinkError (org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)3