Authenticate the user by checking for the existence of a certificate
chain, and optionally asking a trust manager to validate that we trust
this user.
// Have we already authenticated someone?
Principal principal =
((HttpServletRequest) request.getRequest()).getUserPrincipal();
if (principal != null) {
if (debug >= 1)
log("Already authenticated '" + principal.getName() + "'");
return (true);
}
// Retrieve the certificate chain for this client
HttpServletResponse hres =
(HttpServletResponse) response.getResponse();
if (debug >= 1)
log(" Looking up certificates");
X509Certificate certs[] = (X509Certificate[])
request.getRequest().getAttribute(Globals.CERTIFICATES_ATTR);
if ((certs == null) || (certs.length < 1)) {
certs = (X509Certificate[])
request.getRequest().getAttribute(Globals.SSL_CERTIFICATE_ATTR);
}
if ((certs == null) || (certs.length < 1)) {
if (debug >= 1)
log(" No certificates included with this request");
/* S1AS 4878272
hres.sendError(HttpServletResponse.SC_BAD_REQUEST,
sm.getString("authenticator.certificates"));
*/
// BEGIN S1AS 4878272
hres.sendError(HttpServletResponse.SC_BAD_REQUEST);
response.setDetailMessage(sm.getString("authenticator.certificates"));
// END S1AS 4878272
return (false);
}
// Authenticate the specified certificate chain
principal = context.getRealm().authenticate(certs);
if (principal == null) {
if (debug >= 1)
log(" Realm.authenticate() returned false");
/* S1AS 4878272
hres.sendError(HttpServletResponse.SC_UNAUTHORIZED,
sm.getString("authenticator.unauthorized"));
*/
// BEGIN S1AS 4878272
hres.sendError(HttpServletResponse.SC_UNAUTHORIZED);
response.setDetailMessage(sm.getString("authenticator.unauthorized"));
// END S1AS 4878272
return (false);
}
// Cache the principal (if requested) and record this authentication
register(request, response, principal, Constants.CERT_METHOD,
null, null);
String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE);
if (ssoId != null) {
getSession(request, true);
}
return (true);