Search in sources :

Example 6 with AuthenticationProvider

use of org.apache.qpid.server.model.AuthenticationProvider in project qpid-broker-j by apache.

the class VirtualHostAliasTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _broker = BrokerTestHelper.createBrokerMock();
    AuthenticationProvider dummyAuthProvider = mock(AuthenticationProvider.class);
    when(dummyAuthProvider.getName()).thenReturn("dummy");
    when(dummyAuthProvider.getId()).thenReturn(UUID.randomUUID());
    when(dummyAuthProvider.getMechanisms()).thenReturn(Arrays.asList("PLAIN"));
    when(_broker.getChildren(eq(AuthenticationProvider.class))).thenReturn(Collections.singleton(dummyAuthProvider));
    for (String name : new String[] { "red", "blue", "purple", "black" }) {
        boolean defaultVHN = "black".equals(name);
        VirtualHost<?> virtualHost = BrokerTestHelper.createVirtualHost(name, _broker, defaultVHN);
        VirtualHostNode vhn = (VirtualHostNode) virtualHost.getParent();
        assertNotSame(vhn.getName(), virtualHost.getName());
        _vhosts.put(name, virtualHost);
        if (defaultVHN) {
            when(_broker.findDefautVirtualHostNode()).thenReturn(vhn);
        }
    }
    ConfiguredObjectFactory objectFactory = _broker.getObjectFactory();
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put(Port.NAME, getTestName());
    attributes.put(Port.PORT, 0);
    attributes.put(Port.AUTHENTICATION_PROVIDER, "dummy");
    attributes.put(Port.TYPE, "AMQP");
    _port = (AmqpPort) objectFactory.create(Port.class, attributes, _broker);
}
Also used : ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) HashMap(java.util.HashMap) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode)

Example 7 with AuthenticationProvider

use of org.apache.qpid.server.model.AuthenticationProvider in project qpid-broker-j by apache.

the class SNITest method doBrokerStartup.

private void doBrokerStartup(boolean useMatching, String defaultAlias) throws Exception {
    final File initialConfiguration = createInitialContext();
    _brokerWork = TestFileUtils.createTestDirectory("qpid-work", true);
    Map<String, String> context = new HashMap<>();
    context.put("qpid.work_dir", _brokerWork.toString());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(SystemConfig.INITIAL_CONFIGURATION_LOCATION, initialConfiguration.getAbsolutePath());
    attributes.put(SystemConfig.TYPE, JsonSystemConfigImpl.SYSTEM_CONFIG_TYPE);
    attributes.put(SystemConfig.CONTEXT, context);
    _systemLauncher = new SystemLauncher(new DefaultSystemLauncherListener() {

        @Override
        public void onContainerResolve(final SystemConfig<?> systemConfig) {
            _broker = systemConfig.getContainer(Broker.class);
        }
    });
    _systemLauncher.startup(attributes);
    final Map<String, Object> authProviderAttr = new HashMap<>();
    authProviderAttr.put(AuthenticationProvider.NAME, "myAuthProvider");
    authProviderAttr.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
    final AuthenticationProvider authProvider = _broker.createChild(AuthenticationProvider.class, authProviderAttr);
    Map<String, Object> keyStoreAttr = new HashMap<>();
    keyStoreAttr.put(FileKeyStore.NAME, "myKeyStore");
    keyStoreAttr.put(FileKeyStore.STORE_URL, _keyStoreFile.toURI().toURL().toString());
    keyStoreAttr.put(FileKeyStore.PASSWORD, KEYSTORE_PASSWORD);
    keyStoreAttr.put(FileKeyStore.USE_HOST_NAME_MATCHING, useMatching);
    keyStoreAttr.put(FileKeyStore.CERTIFICATE_ALIAS, defaultAlias);
    final KeyStore keyStore = _broker.createChild(KeyStore.class, keyStoreAttr);
    Map<String, Object> portAttr = new HashMap<>();
    portAttr.put(Port.NAME, "myPort");
    portAttr.put(Port.TYPE, "AMQP");
    portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
    portAttr.put(Port.PORT, 0);
    portAttr.put(Port.AUTHENTICATION_PROVIDER, authProvider);
    portAttr.put(Port.KEY_STORE, keyStore);
    final Port<?> port = _broker.createChild(Port.class, portAttr);
    _boundPort = port.getBoundPort();
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) FileKeyStore(org.apache.qpid.server.security.FileKeyStore) KeyStore(org.apache.qpid.server.model.KeyStore) SystemLauncher(org.apache.qpid.server.SystemLauncher) DefaultSystemLauncherListener(org.apache.qpid.server.SystemLauncherListener.DefaultSystemLauncherListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) File(java.io.File)

Example 8 with AuthenticationProvider

use of org.apache.qpid.server.model.AuthenticationProvider in project qpid-broker-j by apache.

the class AMQPConnection_0_8Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    EventLogger value = new EventLogger();
    SystemConfig systemConfig = mock(SystemConfig.class);
    when(systemConfig.getEventLogger()).thenReturn(mock(EventLogger.class));
    _taskExecutor = new TaskExecutorImpl();
    _taskExecutor.start();
    Model model = BrokerModel.getInstance();
    _broker = mock(Broker.class);
    when(_broker.getParent()).thenReturn(systemConfig);
    when(_broker.getModel()).thenReturn(model);
    when(_broker.getCategoryClass()).thenReturn(Broker.class);
    when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
    when(_broker.getChildExecutor()).thenReturn(_taskExecutor);
    when(_broker.getEventLogger()).thenReturn(value);
    when(_broker.getContextValue(eq(Long.class), eq(Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT))).thenReturn(0l);
    _virtualHostNode = mock(VirtualHostNode.class);
    when(_virtualHostNode.getParent()).thenReturn(_broker);
    when(_virtualHostNode.getModel()).thenReturn(model);
    when(_virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
    when(_virtualHostNode.getTaskExecutor()).thenReturn(_taskExecutor);
    when(_virtualHostNode.getChildExecutor()).thenReturn(_taskExecutor);
    _virtualHost = mock(QueueManagingVirtualHost.class);
    VirtualHostPrincipal virtualHostPrincipal = new VirtualHostPrincipal(_virtualHost);
    when(_virtualHost.getParent()).thenReturn(_virtualHostNode);
    when(_virtualHost.getModel()).thenReturn(model);
    when(_virtualHost.getCategoryClass()).thenReturn(VirtualHost.class);
    when(_virtualHost.getState()).thenReturn(State.ACTIVE);
    when(_virtualHost.isActive()).thenReturn(true);
    when(_virtualHost.getTaskExecutor()).thenReturn(_taskExecutor);
    when(_virtualHost.getPrincipal()).thenReturn(virtualHostPrincipal);
    when(_virtualHost.getContextValue(Integer.class, Broker.MESSAGE_COMPRESSION_THRESHOLD_SIZE)).thenReturn(1024);
    when(_virtualHost.getContextValue(Long.class, Connection.MAX_UNCOMMITTED_IN_MEMORY_SIZE)).thenReturn(1024l);
    when(_virtualHost.getContextValue(Boolean.class, Broker.BROKER_MSG_AUTH)).thenReturn(false);
    when(_virtualHost.authoriseCreateConnection(any(AMQPConnection.class))).thenReturn(true);
    when(_virtualHost.getEventLogger()).thenReturn(value);
    SubjectCreator subjectCreator = mock(SubjectCreator.class);
    SaslNegotiator saslNegotiator = mock(SaslNegotiator.class);
    when(subjectCreator.createSaslNegotiator(eq(SASL_MECH.toString()), any(SaslSettings.class))).thenReturn(saslNegotiator);
    when(subjectCreator.authenticate(saslNegotiator, SASL_RESPONSE)).thenReturn(new SubjectAuthenticationResult(new AuthenticationResult(new AuthenticatedPrincipal(new UsernamePrincipal("username", null))), new Subject()));
    AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
    when(authenticationProvider.getAvailableMechanisms(anyBoolean())).thenReturn(Collections.singletonList(SASL_MECH.toString()));
    _port = mock(AmqpPort.class);
    when(_port.getParent()).thenReturn(_broker);
    when(_port.getCategoryClass()).thenReturn(Port.class);
    when(_port.getChildExecutor()).thenReturn(_taskExecutor);
    when(_port.getModel()).thenReturn(model);
    when(_port.getAuthenticationProvider()).thenReturn(authenticationProvider);
    when(_port.getAddressSpace(VIRTUAL_HOST_NAME)).thenReturn(_virtualHost);
    when(_port.getContextValue(Long.class, Port.CONNECTION_MAXIMUM_AUTHENTICATION_DELAY)).thenReturn(2500l);
    when(_port.getContextValue(Integer.class, Connection.MAX_MESSAGE_SIZE)).thenReturn(Connection.DEFAULT_MAX_MESSAGE_SIZE);
    when(_port.getSubjectCreator(eq(false), anyString())).thenReturn(subjectCreator);
    _sender = mock(ByteBufferSender.class);
    _network = mock(ServerNetworkConnection.class);
    when(_network.getSender()).thenReturn(_sender);
    when(_network.getLocalAddress()).thenReturn(new InetSocketAddress("localhost", 12345));
    _transport = Transport.TCP;
    _protocol = Protocol.AMQP_0_8;
    _ticker = new AggregateTicker();
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) SystemConfig(org.apache.qpid.server.model.SystemConfig) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) Broker(org.apache.qpid.server.model.Broker) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) EventLogger(org.apache.qpid.server.logging.EventLogger) InetSocketAddress(java.net.InetSocketAddress) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) AggregateTicker(org.apache.qpid.server.transport.AggregateTicker) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) Subject(javax.security.auth.Subject) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) BrokerModel(org.apache.qpid.server.model.BrokerModel) Model(org.apache.qpid.server.model.Model) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode)

Example 9 with AuthenticationProvider

use of org.apache.qpid.server.model.AuthenticationProvider in project qpid-broker-j by apache.

the class AnonymousPreemptiveAuthenticator method attemptAuthentication.

@Override
public Subject attemptAuthentication(final HttpServletRequest request, final HttpManagementConfiguration managementConfig) {
    final Port<?> port = managementConfig.getPort(request);
    final AuthenticationProvider authenticationProvider = managementConfig.getAuthenticationProvider(request);
    SubjectCreator subjectCreator = port.getSubjectCreator(request.isSecure(), request.getServerName());
    if (authenticationProvider instanceof AnonymousAuthenticationManager) {
        return subjectCreator.createResultWithGroups(((AnonymousAuthenticationManager) authenticationProvider).getAnonymousAuthenticationResult()).getSubject();
    }
    return null;
}
Also used : AnonymousAuthenticationManager(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) SubjectCreator(org.apache.qpid.server.security.SubjectCreator)

Example 10 with AuthenticationProvider

use of org.apache.qpid.server.model.AuthenticationProvider in project qpid-broker-j by apache.

the class BrokerRecovererTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    _taskExecutor = new CurrentThreadTaskExecutor();
    _taskExecutor.start();
    _systemConfig = new JsonSystemConfigImpl(_taskExecutor, mock(EventLogger.class), null, new HashMap<String, Object>()) {

        {
            updateModel(BrokerModel.getInstance());
        }
    };
    when(_brokerEntry.getId()).thenReturn(_brokerId);
    when(_brokerEntry.getType()).thenReturn(Broker.class.getSimpleName());
    Map<String, Object> attributesMap = new HashMap<String, Object>();
    attributesMap.put(Broker.MODEL_VERSION, BrokerModel.MODEL_VERSION);
    attributesMap.put(Broker.NAME, getName());
    when(_brokerEntry.getAttributes()).thenReturn(attributesMap);
    when(_brokerEntry.getParents()).thenReturn(Collections.singletonMap(SystemConfig.class.getSimpleName(), _systemConfig.getId()));
    // Add a base AuthenticationProvider for all tests
    _authenticationProvider1 = mock(AuthenticationProvider.class);
    when(_authenticationProvider1.getName()).thenReturn("authenticationProvider1");
    when(_authenticationProvider1.getId()).thenReturn(_authenticationProvider1Id);
}
Also used : Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) JsonSystemConfigImpl(org.apache.qpid.server.model.JsonSystemConfigImpl)

Aggregations

AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)14 HashMap (java.util.HashMap)8 PasswordCredentialManagingAuthenticationProvider (org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider)4 Broker (org.apache.qpid.server.model.Broker)3 SystemConfig (org.apache.qpid.server.model.SystemConfig)3 User (org.apache.qpid.server.model.User)3 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)3 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)2 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)2 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)2 PlainPasswordFilePrincipalDatabase (org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase)2 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 Principal (java.security.Principal)1 X509Certificate (java.security.cert.X509Certificate)1 Subject (javax.security.auth.Subject)1 X500Principal (javax.security.auth.x500.X500Principal)1 SystemLauncher (org.apache.qpid.server.SystemLauncher)1