1 17 18 19 package org.apache.catalina.authenticator; 20 21 22 import java.io.IOException ; 23 import java.security.Principal ; 24 import java.security.cert.X509Certificate ; 25 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.apache.coyote.ActionCode; 29 import org.apache.catalina.Globals; 30 import org.apache.catalina.LifecycleException; 31 import org.apache.catalina.connector.Request; 32 import org.apache.catalina.connector.Response; 33 import org.apache.catalina.deploy.LoginConfig; 34 35 36 37 44 45 public class SSLAuthenticator 46 extends AuthenticatorBase { 47 48 49 51 52 55 protected static final String info = 56 "org.apache.catalina.authenticator.SSLAuthenticator/1.0"; 57 58 59 62 public String getInfo() { 63 64 return (info); 65 66 } 67 68 69 71 72 84 public boolean authenticate(Request request, 85 Response response, 86 LoginConfig config) 87 throws IOException { 88 89 Principal principal = request.getUserPrincipal(); 91 if (principal != null) { 93 if (containerLog.isDebugEnabled()) 94 containerLog.debug("Already authenticated '" + principal.getName() + "'"); 95 String ssoId = (String ) request.getNote(Constants.REQ_SSOID_NOTE); 98 if (ssoId != null) 99 associate(ssoId, request.getSessionInternal(true)); 100 return (true); 101 } 102 103 127 128 if (containerLog.isDebugEnabled()) 130 containerLog.debug(" Looking up certificates"); 131 132 X509Certificate certs[] = (X509Certificate []) 133 request.getAttribute(Globals.CERTIFICATES_ATTR); 134 if ((certs == null) || (certs.length < 1)) { 135 request.getCoyoteRequest().action 136 (ActionCode.ACTION_REQ_SSL_CERTIFICATE, null); 137 certs = (X509Certificate []) 138 request.getAttribute(Globals.CERTIFICATES_ATTR); 139 } 140 if ((certs == null) || (certs.length < 1)) { 141 if (containerLog.isDebugEnabled()) 142 containerLog.debug(" No certificates included with this request"); 143 response.sendError(HttpServletResponse.SC_BAD_REQUEST, 144 sm.getString("authenticator.certificates")); 145 return (false); 146 } 147 148 principal = context.getRealm().authenticate(certs); 150 if (principal == null) { 151 if (containerLog.isDebugEnabled()) 152 containerLog.debug(" Realm.authenticate() returned false"); 153 response.sendError(HttpServletResponse.SC_UNAUTHORIZED, 154 sm.getString("authenticator.unauthorized")); 155 return (false); 156 } 157 158 register(request, response, principal, Constants.CERT_METHOD, 160 null, null); 161 return (true); 162 163 } 164 165 166 168 169 176 public void start() throws LifecycleException { 177 178 super.start(); 179 180 } 181 182 183 190 public void stop() throws LifecycleException { 191 192 super.stop(); 193 194 } 195 196 197 } 198 | Popular Tags |