Search in sources :

Example 1 with PlainPasswordFilePrincipalDatabase

use of org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase 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 2 with PlainPasswordFilePrincipalDatabase

use of org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase 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 3 with PlainPasswordFilePrincipalDatabase

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

the class PlainPasswordFileAuthenticationManagerFactoryTest method testPlainInstanceCreated.

public void testPlainInstanceCreated() throws Exception {
    _configuration.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE);
    _configuration.put("path", _emptyPasswordFile.getAbsolutePath());
    AuthenticationProvider manager = _factory.create(AuthenticationProvider.class, _configuration, _broker);
    assertNotNull(manager);
    assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
    assertTrue(((PrincipalDatabaseAuthenticationManager) manager).getPrincipalDatabase() instanceof PlainPasswordFilePrincipalDatabase);
}
Also used : AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) PlainPasswordFilePrincipalDatabase(org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase)

Example 4 with PlainPasswordFilePrincipalDatabase

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

the class PlainPasswordFileAuthenticationManagerFactoryTest method testPasswordFileNotFound.

public void testPasswordFileNotFound() throws Exception {
    // delete the file
    _emptyPasswordFile.delete();
    _configuration.put(AuthenticationProvider.TYPE, PlainPasswordDatabaseAuthenticationManager.PROVIDER_TYPE);
    _configuration.put("path", _emptyPasswordFile.getAbsolutePath());
    AuthenticationProvider manager = _factory.create(AuthenticationProvider.class, _configuration, _broker);
    assertNotNull(manager);
    assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
    assertTrue(((PrincipalDatabaseAuthenticationManager) manager).getPrincipalDatabase() instanceof PlainPasswordFilePrincipalDatabase);
}
Also used : AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) PlainPasswordFilePrincipalDatabase(org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase)

Aggregations

PlainPasswordFilePrincipalDatabase (org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase)4 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)2 PasswordCredentialManagingAuthenticationProvider (org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider)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 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)1