Search in sources :

Example 1 with ConnectionHandler

use of org.apache.qpid.server.protocol.v1_0.ConnectionHandler in project qpid-broker-j by apache.

the class FrameHandlerTest method testOversizedFrame.

@Test
public void testOversizedFrame() {
    ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
    when(connectionHandler.getMaxFrameSize()).thenReturn(MAX_FRAME_SIZE);
    FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
    QpidByteBuffer body = QpidByteBuffer.allocate(false, MAX_FRAME_SIZE + 8);
    // size
    body.putInt(body.capacity());
    // DOFF
    body.put((byte) 2);
    // AMQP Frame Type
    body.put((byte) 1);
    // channel
    body.putShort(UnsignedShort.ZERO.shortValue());
    body.position(body.capacity());
    body.flip();
    handler.parse(body);
    ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
    verify(connectionHandler).handleError(errorCaptor.capture());
    Error error = errorCaptor.getValue();
    assertNotNull(error);
    assertEquals(ConnectionError.FRAMING_ERROR, error.getCondition());
    assertEquals(String.format("specified frame size %s larger than maximum frame header size %s", body.capacity(), MAX_FRAME_SIZE), error.getDescription());
}
Also used : ConnectionHandler(org.apache.qpid.server.protocol.v1_0.ConnectionHandler) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Test(org.junit.Test)

Example 2 with ConnectionHandler

use of org.apache.qpid.server.protocol.v1_0.ConnectionHandler in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method sendConnectionCloseAsync.

@Override
public void sendConnectionCloseAsync(final CloseReason reason, final String description) {
    stopConnection();
    final ErrorCondition cause;
    switch(reason) {
        case MANAGEMENT:
            cause = ConnectionError.CONNECTION_FORCED;
            break;
        case TRANSACTION_TIMEOUT:
            cause = AmqpError.RESOURCE_LIMIT_EXCEEDED;
            break;
        default:
            cause = AmqpError.INTERNAL_ERROR;
    }
    Action<ConnectionHandler> action = object -> closeConnection(cause, description);
    addAsyncTask(action);
}
Also used : AccessControlContext(java.security.AccessControlContext) Arrays(java.util.Arrays) SoleConnectionDetectionPolicy(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionDetectionPolicy) PeekingIterator(com.google.common.collect.PeekingIterator) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult) ExternalAuthenticationManagerImpl(org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManagerImpl) Map(java.util.Map) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) ProtocolHandler(org.apache.qpid.server.protocol.v1_0.codec.ProtocolHandler) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) Set(java.util.Set) DescribedTypeConstructorRegistry(org.apache.qpid.server.protocol.v1_0.codec.DescribedTypeConstructorRegistry) SaslCode(org.apache.qpid.server.protocol.v1_0.type.security.SaslCode) VirtualHostUnavailableException(org.apache.qpid.server.virtualhost.VirtualHostUnavailableException) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Transport(org.apache.qpid.server.model.Transport) SASLFrame(org.apache.qpid.server.protocol.v1_0.framing.SASLFrame) OversizeFrameException(org.apache.qpid.server.protocol.v1_0.framing.OversizeFrameException) AggregateTicker(org.apache.qpid.server.transport.AggregateTicker) ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) AccessController(java.security.AccessController) ValueWriter(org.apache.qpid.server.protocol.v1_0.codec.ValueWriter) ProtocolEngine(org.apache.qpid.server.transport.ProtocolEngine) FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter) SOLE_CONNECTION_ENFORCEMENT_POLICY(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties.SOLE_CONNECTION_ENFORCEMENT_POLICY) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) ChannelFrameBody(org.apache.qpid.server.protocol.v1_0.type.transport.ChannelFrameBody) SoleConnectionEnforcementPolicy(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionEnforcementPolicy) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) ConnectionPropertyEnricher(org.apache.qpid.server.plugin.ConnectionPropertyEnricher) SaslFrameBody(org.apache.qpid.server.protocol.v1_0.type.SaslFrameBody) SoleConnectionConnectionProperties(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionConnectionProperties) Connection(org.apache.qpid.server.model.Connection) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) UnsignedShort(org.apache.qpid.server.protocol.v1_0.type.UnsignedShort) AMQFrame(org.apache.qpid.server.protocol.v1_0.framing.AMQFrame) SaslChallenge(org.apache.qpid.server.protocol.v1_0.type.security.SaslChallenge) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) TransportFrame(org.apache.qpid.server.protocol.v1_0.framing.TransportFrame) AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) SocketAddress(java.net.SocketAddress) SoleConnectionEnforcementPolicyException(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionEnforcementPolicyException) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) LoggerFactory(org.slf4j.LoggerFactory) ConnectionMessages(org.apache.qpid.server.logging.messages.ConnectionMessages) ErrorCondition(org.apache.qpid.server.protocol.v1_0.type.ErrorCondition) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) ResourceLimitMessages(org.apache.qpid.server.logging.messages.ResourceLimitMessages) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) ValueHandler(org.apache.qpid.server.protocol.v1_0.codec.ValueHandler) SectionDecoderRegistry(org.apache.qpid.server.protocol.v1_0.codec.SectionDecoderRegistry) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Collection(java.util.Collection) AnonymousAuthenticationManager(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SaslOutcome(org.apache.qpid.server.protocol.v1_0.type.security.SaslOutcome) UUID(java.util.UUID) PrivilegedAction(java.security.PrivilegedAction) ConnectionLimitException(org.apache.qpid.server.security.limit.ConnectionLimitException) Functions(org.apache.qpid.server.transport.util.Functions) Sets(com.google.common.collect.Sets) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) List(java.util.List) Principal(java.security.Principal) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) Optional(java.util.Optional) FrameHandler(org.apache.qpid.server.protocol.v1_0.framing.FrameHandler) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) SaslMechanisms(org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms) Iterators(com.google.common.collect.Iterators) EventLogger(org.apache.qpid.server.logging.EventLogger) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator) SaslInit(org.apache.qpid.server.protocol.v1_0.type.security.SaslInit) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) SaslResponse(org.apache.qpid.server.protocol.v1_0.type.security.SaslResponse) NoSuchElementException(java.util.NoSuchElementException) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Logger(org.slf4j.Logger) Action(org.apache.qpid.server.util.Action) Iterator(java.util.Iterator) Broker(org.apache.qpid.server.model.Broker) Protocol(org.apache.qpid.server.model.Protocol) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) ConnectionClosingTicker(org.apache.qpid.server.protocol.ConnectionClosingTicker) AMQPSession(org.apache.qpid.server.session.AMQPSession) Collections(java.util.Collections) ErrorCondition(org.apache.qpid.server.protocol.v1_0.type.ErrorCondition)

Example 3 with ConnectionHandler

use of org.apache.qpid.server.protocol.v1_0.ConnectionHandler in project qpid-broker-j by apache.

the class FrameHandlerTest method testSaslHeartbeat.

@Test
public void testSaslHeartbeat() {
    ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
    when(connectionHandler.getMaxFrameSize()).thenReturn(MAX_FRAME_SIZE);
    FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
    QpidByteBuffer body = QpidByteBuffer.allocate(false, 8);
    // size
    body.putInt(8);
    // DOFF
    body.put((byte) 2);
    // AMQP Frame Type
    body.put((byte) 1);
    // channel
    body.putShort(UnsignedShort.ZERO.shortValue());
    body.flip();
    handler.parse(body);
    ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
    verify(connectionHandler).handleError(errorCaptor.capture());
    Error error = errorCaptor.getValue();
    assertNotNull(error);
    assertEquals(ConnectionError.FRAMING_ERROR, error.getCondition());
    assertEquals("Empty (heartbeat) frames are not permitted during SASL negotiation", error.getDescription());
}
Also used : ConnectionHandler(org.apache.qpid.server.protocol.v1_0.ConnectionHandler) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) ConnectionError(org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Test(org.junit.Test)

Aggregations

QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 ConnectionError (org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError)3 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)3 Iterators (com.google.common.collect.Iterators)1 PeekingIterator (com.google.common.collect.PeekingIterator)1 Sets (com.google.common.collect.Sets)1 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SocketAddress (java.net.SocketAddress)1 AccessControlContext (java.security.AccessControlContext)1 AccessControlException (java.security.AccessControlException)1 AccessController (java.security.AccessController)1 Principal (java.security.Principal)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1