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)));
}
}
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);
}
}
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());
}
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;
}
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();
}
Aggregations