Search in sources :

Example 1 with AuthenticationProvider

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

the class SSLClientCertPreemptiveAuthenticator method attemptAuthentication.

@Override
public Subject attemptAuthentication(final HttpServletRequest request, final HttpManagementConfiguration managementConfig) {
    final AuthenticationProvider authenticationProvider = managementConfig.getAuthenticationProvider(request);
    final Port<?> port = managementConfig.getPort(request);
    SubjectCreator subjectCreator = port.getSubjectCreator(request.isSecure(), request.getServerName());
    if (request.isSecure() && authenticationProvider instanceof ExternalAuthenticationManager && Collections.list(request.getAttributeNames()).contains(CERTIFICATE_ATTRIBUTE_NAME)) {
        ExternalAuthenticationManager<?> externalAuthManager = (ExternalAuthenticationManager<?>) authenticationProvider;
        X509Certificate[] certificates = (X509Certificate[]) request.getAttribute(CERTIFICATE_ATTRIBUTE_NAME);
        if (certificates != null && certificates.length != 0) {
            Principal principal = certificates[0].getSubjectX500Principal();
            if (!externalAuthManager.getUseFullDN()) {
                String username;
                String dn = ((X500Principal) principal).getName(X500Principal.RFC2253);
                username = SSLUtil.getIdFromSubjectDN(dn);
                principal = new UsernamePrincipal(username, authenticationProvider);
            }
            return subjectCreator.createSubjectWithGroups(new AuthenticatedPrincipal(principal));
        }
    }
    return null;
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) X500Principal(javax.security.auth.x500.X500Principal) ExternalAuthenticationManager(org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) X509Certificate(java.security.cert.X509Certificate) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) X500Principal(javax.security.auth.x500.X500Principal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 2 with AuthenticationProvider

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

the class PlainPasswordDatabaseAuthenticationManagerTest method testAddUser.

public void testAddUser() {
    _passwordFile = TestFileUtils.createTempFile(this, ".user.password");
    Map<String, Object> providerAttrs = new HashMap<>();
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
    AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
    assertThat(provider.getChildren(User.class).size(), is(equalTo(0)));
    Map<String, Object> userAttrs = new HashMap<>();
    userAttrs.put(User.TYPE, PROVIDER_TYPE);
    userAttrs.put(User.NAME, "user");
    userAttrs.put(User.PASSWORD, "password");
    User user = (User) provider.createChild(User.class, userAttrs);
    assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
    assertThat(user.getName(), is(equalTo("user")));
}
Also used : User(org.apache.qpid.server.model.User) HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider)

Example 3 with AuthenticationProvider

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

the class PlainPasswordDatabaseAuthenticationManagerTest method testExistingPasswordFile.

public void testExistingPasswordFile() {
    _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
    Map<String, Object> providerAttrs = new HashMap<>();
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
    @SuppressWarnings("unchecked") AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
    assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
    User user = (User) provider.getChildByName(User.class, "user");
    assertThat(user.getName(), is(equalTo("user")));
}
Also used : User(org.apache.qpid.server.model.User) HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider)

Example 4 with AuthenticationProvider

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

the class PlainPasswordDatabaseAuthenticationManagerTest method testDeleteProvider.

public void testDeleteProvider() {
    _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
    Map<String, Object> providerAttrs = new HashMap<>();
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
    AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
    provider.delete();
    assertThat(_passwordFile.exists(), is(equalTo(false)));
}
Also used : HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider)

Example 5 with AuthenticationProvider

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

the class PlainPasswordFileAuthenticationManagerFactoryTest method testThrowsExceptionWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified.

public void testThrowsExceptionWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception {
    _configuration.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE);
    try {
        AuthenticationProvider manager = _factory.create(AuthenticationProvider.class, _configuration, _broker);
        fail("No authentication manager should be created");
    } catch (IllegalArgumentException e) {
    // pass;
    }
}
Also used : AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider)

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