* Initializes the context from a servlet request.
* @param request
*/
public static void setContextFromRequest( final ServletRequest request ) {
SecurityContextImpl sc = new SecurityContextImpl();
SecurityContextImpl.setCurrentContext( sc );
String remoteAddress = request.getRemoteAddr();
sc.setRemoteAddr(remoteAddress);
X509Certificate[] certChain = null;
try {
certChain = (X509Certificate[]) request
.getAttribute( "javax.servlet.request.X509Certificate" );
} catch ( Exception e ) {
logger.error( "Exception during certificate chain retrieval: " + e );
throw new PAPAuthzException( "No certificate found in request!", e );
}
if (certChain == null)
throw new PAPAuthzException( "No certificate found in request!");
sc.setClientCertChain( certChain );
String subject = X500NameUtils.getReadableForm(sc.getClientX500Principal());
String issuer = X500NameUtils.getReadableForm(sc.getIssuerX500Principal());
BigInteger sn = sc.getClientCert().getSerialNumber();
String serialNumber = ( sn == null ) ? "NULL" : sn.toString();
logger.info( "Connection from \"" + remoteAddress + "\" by \""
+ subject + "\" (issued by \"" + issuer
+ "\", " + "serial " + serialNumber + ")" );