use of org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager 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;
}
Aggregations