Search in sources :

Example 11 with AuthenticatedPrincipal

use of org.apache.qpid.server.security.auth.AuthenticatedPrincipal 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 12 with AuthenticatedPrincipal

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

the class ProtocolEngine_1_0_0Test method testProtocolEngineWithNoSaslTLSandExternal.

@Test
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(new TransportFrame((int) (short) 0, open));
    verify(_virtualHost).registerConnection(any(AMQPConnection.class));
    AuthenticatedPrincipal authPrincipal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
    assertNotNull(authPrincipal);
    assertEquals(authPrincipal, new AuthenticatedPrincipal(principal));
}
Also used : AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) TransportFrame(org.apache.qpid.server.protocol.v1_0.framing.TransportFrame) 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) Test(org.junit.Test)

Example 13 with AuthenticatedPrincipal

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

the class AbstractVirtualHostNode method enrichAttributesWithAuditInformation.

private Map<String, Object> enrichAttributesWithAuditInformation(final Map<String, Object> attributes) {
    LinkedHashMap<String, Object> enriched = new LinkedHashMap<>(attributes);
    final AuthenticatedPrincipal currentUser = AuthenticatedPrincipal.getCurrentUser();
    if (currentUser != null) {
        enriched.put(ConfiguredObject.LAST_UPDATED_BY, currentUser.getName());
        enriched.put(ConfiguredObject.CREATED_BY, currentUser.getName());
    }
    long currentTime = System.currentTimeMillis();
    enriched.put(ConfiguredObject.LAST_UPDATED_TIME, currentTime);
    enriched.put(ConfiguredObject.CREATED_TIME, currentTime);
    return enriched;
}
Also used : ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) LinkedHashMap(java.util.LinkedHashMap) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 14 with AuthenticatedPrincipal

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

the class AMQChannelTest method setUp.

@Before
public void setUp() throws Exception {
    TaskExecutor taskExecutor = mock(TaskExecutor.class);
    _broker = mock(Broker.class);
    when(_broker.getEventLogger()).thenReturn(mock(EventLogger.class));
    when(_broker.getContextValue(Long.class, Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT)).thenReturn(1l);
    _messageStore = mock(MessageStore.class);
    _virtualHost = mock(QueueManagingVirtualHost.class);
    when(_virtualHost.getContextValue(Integer.class, Broker.MESSAGE_COMPRESSION_THRESHOLD_SIZE)).thenReturn(1);
    when(_virtualHost.getContextValue(Long.class, Connection.MAX_UNCOMMITTED_IN_MEMORY_SIZE)).thenReturn(1l);
    when(_virtualHost.getContextValue(Boolean.class, Broker.BROKER_MSG_AUTH)).thenReturn(false);
    when(_virtualHost.getPrincipal()).thenReturn(mock(Principal.class));
    when(_virtualHost.getEventLogger()).thenReturn(mock(EventLogger.class));
    _port = mock(AmqpPort.class);
    when(_port.getChildExecutor()).thenReturn(taskExecutor);
    when(_port.getModel()).thenReturn(BrokerModel.getInstance());
    when(_port.getContextValue(Integer.class, Connection.MAX_MESSAGE_SIZE)).thenReturn(1);
    AuthenticatedPrincipal authenticatedPrincipal = new AuthenticatedPrincipal(new UsernamePrincipal("user", null));
    Set<Principal> authenticatedUser = Collections.<Principal>singleton(authenticatedPrincipal);
    Subject authenticatedSubject = new Subject(true, authenticatedUser, Collections.<Principal>emptySet(), Collections.<Principal>emptySet());
    _protocolOutputConverter = mock(ProtocolOutputConverter.class);
    _amqConnection = mock(AMQPConnection_0_8.class);
    when(_amqConnection.getSubject()).thenReturn(authenticatedSubject);
    when(_amqConnection.getAuthorizedPrincipal()).thenReturn(authenticatedPrincipal);
    when(_amqConnection.getAddressSpace()).thenReturn((VirtualHost) _virtualHost);
    when(_amqConnection.getProtocolOutputConverter()).thenReturn(_protocolOutputConverter);
    when(_amqConnection.getBroker()).thenReturn((Broker) _broker);
    when(_amqConnection.getMethodRegistry()).thenReturn(new MethodRegistry(ProtocolVersion.v0_9));
    when(_amqConnection.getContextProvider()).thenReturn(_virtualHost);
    when(_amqConnection.getContextValue(Long.class, Session.PRODUCER_AUTH_CACHE_TIMEOUT)).thenReturn(Session.PRODUCER_AUTH_CACHE_TIMEOUT_DEFAULT);
    when(_amqConnection.getContextValue(Integer.class, Session.PRODUCER_AUTH_CACHE_SIZE)).thenReturn(Session.PRODUCER_AUTH_CACHE_SIZE_DEFAULT);
    when(_amqConnection.getContextValue(Long.class, Connection.MAX_UNCOMMITTED_IN_MEMORY_SIZE)).thenReturn(Connection.DEFAULT_MAX_UNCOMMITTED_IN_MEMORY_SIZE);
    when(_amqConnection.getContextValue(Boolean.class, AMQPConnection_0_8.FORCE_MESSAGE_VALIDATION)).thenReturn(true);
    when(_amqConnection.getTaskExecutor()).thenReturn(taskExecutor);
    when(_amqConnection.getChildExecutor()).thenReturn(taskExecutor);
    when(_amqConnection.getModel()).thenReturn(BrokerModel.getInstance());
    when(_amqConnection.getContextValue(Long.class, AMQPConnection_0_8.BATCH_LIMIT)).thenReturn(AMQPConnection_0_8.DEFAULT_BATCH_LIMIT);
    when(_amqConnection.getContextValue(Long.class, AMQPConnection_0_8.HIGH_PREFETCH_LIMIT)).thenReturn(AMQPConnection_0_8.DEFAULT_BATCH_LIMIT);
    when(_amqConnection.getEventLogger()).thenReturn(mock(EventLogger.class));
    _messageDestination = mock(MessageDestination.class);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) Broker(org.apache.qpid.server.model.Broker) MessageDestination(org.apache.qpid.server.message.MessageDestination) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) EventLogger(org.apache.qpid.server.logging.EventLogger) MethodRegistry(org.apache.qpid.server.protocol.v0_8.transport.MethodRegistry) Subject(javax.security.auth.Subject) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Principal(java.security.Principal) Before(org.junit.Before)

Example 15 with AuthenticatedPrincipal

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

the class LatestManagementControllerTest method createTestSubject.

private Subject createTestSubject() {
    final AuthenticationProvider<?> provider = mock(AuthenticationProvider.class);
    when(provider.getType()).thenReturn("type");
    when(provider.getName()).thenReturn("name");
    return new Subject(false, Collections.singleton(new AuthenticatedPrincipal(new UsernamePrincipal("user", provider))), Collections.emptySet(), Collections.emptySet());
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) Subject(javax.security.auth.Subject) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Aggregations

AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)27 Subject (javax.security.auth.Subject)12 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)11 Principal (java.security.Principal)7 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 Before (org.junit.Before)6 Test (org.junit.Test)6 Date (java.util.Date)5 EventLogger (org.apache.qpid.server.logging.EventLogger)5 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)5 ArrayList (java.util.ArrayList)4 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)4 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Broker (org.apache.qpid.server.model.Broker)3 GenericPrincipal (org.apache.qpid.server.model.preferences.GenericPrincipal)3 TransportFrame (org.apache.qpid.server.protocol.v1_0.framing.TransportFrame)3 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)3 URISyntaxException (java.net.URISyntaxException)2