Search in sources :

Example 1 with PasswordCredentialManagingAuthenticationProvider

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

the class PlainPasswordDatabaseAuthenticationManagerTest method testAuthenticate.

public void testAuthenticate() {
    _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
    String file = _passwordFile.getAbsolutePath();
    Map<String, Object> providerAttrs = new HashMap<>();
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, file);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
    PasswordCredentialManagingAuthenticationProvider provider = ((PasswordCredentialManagingAuthenticationProvider) _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker));
    {
        AuthenticationResult result = provider.authenticate("user", "password");
        assertThat(result.getStatus(), is(equalTo(SUCCESS)));
    }
    {
        AuthenticationResult result = provider.authenticate("user", "badpassword");
        assertThat(result.getStatus(), is(equalTo(AuthenticationResult.AuthenticationStatus.ERROR)));
    }
    {
        AuthenticationResult result = provider.authenticate("unknownuser", "badpassword");
        assertThat(result.getStatus(), is(equalTo(AuthenticationResult.AuthenticationStatus.ERROR)));
    }
}
Also used : HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 2 with PasswordCredentialManagingAuthenticationProvider

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

the class PrincipalDatabaseAuthenticationManagerTest method testInitialiseWhenPasswordFileNotFound.

public void testInitialiseWhenPasswordFileNotFound() throws Exception {
    PasswordCredentialManagingAuthenticationProvider mockAuthProvider = mock(PasswordCredentialManagingAuthenticationProvider.class);
    when(mockAuthProvider.getContextValue(Integer.class, AbstractScramAuthenticationManager.QPID_AUTHMANAGER_SCRAM_ITERATION_COUNT)).thenReturn(4096);
    _principalDatabase = new PlainPasswordFilePrincipalDatabase(mockAuthProvider);
    setupManager(true);
    try {
        _manager.initialise();
        fail("Initialisiation should fail when users file does not exist");
    } catch (IllegalConfigurationException e) {
        assertTrue(e.getCause() instanceof FileNotFoundException);
    }
}
Also used : PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) FileNotFoundException(java.io.FileNotFoundException) PlainPasswordFilePrincipalDatabase(org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase)

Example 3 with PasswordCredentialManagingAuthenticationProvider

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

the class PrincipalDatabaseAuthenticationManagerTest method testInitialiseWhenPasswordFileExists.

public void testInitialiseWhenPasswordFileExists() throws Exception {
    PasswordCredentialManagingAuthenticationProvider mockAuthProvider = mock(PasswordCredentialManagingAuthenticationProvider.class);
    when(mockAuthProvider.getContextValue(Integer.class, AbstractScramAuthenticationManager.QPID_AUTHMANAGER_SCRAM_ITERATION_COUNT)).thenReturn(4096);
    _principalDatabase = new PlainPasswordFilePrincipalDatabase(mockAuthProvider);
    setupManager(true);
    File f = new File(_passwordFileLocation);
    f.createNewFile();
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(f);
        fos.write("admin:admin".getBytes());
    } finally {
        if (fos != null) {
            fos.close();
        }
    }
    _manager.initialise();
    List<Principal> users = _principalDatabase.getUsers();
    assertEquals("Unexpected uses size", 1, users.size());
    Principal p = _principalDatabase.getUser("admin");
    assertEquals("Unexpected principal name", "admin", p.getName());
}
Also used : PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) FileOutputStream(java.io.FileOutputStream) PlainPasswordFilePrincipalDatabase(org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase) File(java.io.File) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) Principal(java.security.Principal)

Example 4 with PasswordCredentialManagingAuthenticationProvider

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

the class ScramNegotiatorTest method createTestAuthenticationManager.

private AuthenticationProvider createTestAuthenticationManager(String type) {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, getTestName());
    attributes.put(ConfiguredObject.ID, UUID.randomUUID());
    attributes.put(ConfiguredObject.TYPE, type);
    ConfiguredObjectFactory objectFactory = _broker.getObjectFactory();
    @SuppressWarnings("unchecked") AuthenticationProvider<?> configuredObject = objectFactory.create(AuthenticationProvider.class, attributes, _broker);
    assertEquals("Unexpected state", State.ACTIVE, configuredObject.getState());
    PasswordCredentialManagingAuthenticationProvider<?> authenticationProvider = (PasswordCredentialManagingAuthenticationProvider<?>) configuredObject;
    authenticationProvider.createUser(VALID_USER_NAME, VALID_USER_PASSWORD, Collections.<String, String>emptyMap());
    return configuredObject;
}
Also used : ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 5 with PasswordCredentialManagingAuthenticationProvider

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

the class PlainPasswordFilePrincipalDatabaseTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final PasswordCredentialManagingAuthenticationProvider mockAuthenticationProvider = mock(PasswordCredentialManagingAuthenticationProvider.class);
    when(mockAuthenticationProvider.getContextValue(Integer.class, AbstractScramAuthenticationManager.QPID_AUTHMANAGER_SCRAM_ITERATION_COUNT)).thenReturn(4096);
    _database = new PlainPasswordFilePrincipalDatabase(mockAuthenticationProvider);
    _testPwdFiles.clear();
}
Also used : PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider)

Aggregations

PasswordCredentialManagingAuthenticationProvider (org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider)5 HashMap (java.util.HashMap)2 PlainPasswordFilePrincipalDatabase (org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 Principal (java.security.Principal)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 ConfiguredObjectFactory (org.apache.qpid.server.model.ConfiguredObjectFactory)1 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)1 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)1