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