Search in sources :

Example 1 with AnonymousAuthenticationManagerFactory

use of org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method testProtocolEngineWithNoSaslNonTLSandAnon.

@Test
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(new TransportFrame((int) (short) 0, open));
    verify(_virtualHost).registerConnection(any(AMQPConnection.class));
    AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
    assertNotNull(principal);
    assertEquals(principal, new AuthenticatedPrincipal(anonymousAuthenticationManager.getAnonymousPrincipal()));
}
Also used : 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) TransportFrame(org.apache.qpid.server.protocol.v1_0.framing.TransportFrame) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Test(org.junit.Test)

Example 2 with AnonymousAuthenticationManagerFactory

use of org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method testProtocolEngineWithSaslNonTLSandAnon.

@Test
public void testProtocolEngineWithSaslNonTLSandAnon() 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);
    when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(new SubjectCreator(anonymousAuthenticationManager, Collections.emptyList(), null));
    allowMechanisms(AnonymousAuthenticationManager.MECHANISM_NAME);
    createEngine(Transport.TCP);
    _protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0_SASL.getInstance().getHeaderIdentifier()));
    SaslInit init = new SaslInit();
    init.setMechanism(Symbol.valueOf("ANONYMOUS"));
    _frameWriter.send(new SASLFrame(init));
    _protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance().getHeaderIdentifier()));
    Open open = new Open();
    open.setContainerId("testContainerId");
    _frameWriter.send(new TransportFrame((int) (short) 0, open));
    verify(_virtualHost).registerConnection(any(AMQPConnection.class));
    AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
    assertNotNull(principal);
    assertEquals(principal, new AuthenticatedPrincipal(anonymousAuthenticationManager.getAnonymousPrincipal()));
}
Also used : 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) SaslInit(org.apache.qpid.server.protocol.v1_0.type.security.SaslInit) SASLFrame(org.apache.qpid.server.protocol.v1_0.framing.SASLFrame) TransportFrame(org.apache.qpid.server.protocol.v1_0.framing.TransportFrame) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Test(org.junit.Test)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)2 TransportFrame (org.apache.qpid.server.protocol.v1_0.framing.TransportFrame)2 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)2 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)2 AnonymousAuthenticationManager (org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager)2 AnonymousAuthenticationManagerFactory (org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory)2 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 SASLFrame (org.apache.qpid.server.protocol.v1_0.framing.SASLFrame)1 SaslInit (org.apache.qpid.server.protocol.v1_0.type.security.SaslInit)1 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)1