001package com.nimbusds.openid.connect.provider.spi; 002 003 004import java.io.InputStream; 005import javax.servlet.ServletContext; 006 007import org.infinispan.manager.EmbeddedCacheManager; 008 009 010/** 011 * Servlet-based context for the initialisation of SPI implementations. 012 */ 013public abstract class ServletInitContext implements InitContext { 014 015 016 /** 017 * The servlet context. 018 */ 019 private final ServletContext servletContext; 020 021 022 /** 023 * Creates a new servlet-based SPI initialisation context. 024 * 025 * @param servletContext The servlet context. Must not be {@code null}. 026 */ 027 public ServletInitContext(final ServletContext servletContext) { 028 029 if (servletContext == null) 030 throw new IllegalArgumentException("The servlet context must not be null"); 031 032 this.servletContext = servletContext; 033 } 034 035 036 /** 037 * Returns the servlet context. 038 * 039 * @return The servlet context. 040 */ 041 public ServletContext getServletContext() { 042 043 return servletContext; 044 } 045 046 047 @Override 048 public InputStream getResourceAsStream(final String path) { 049 050 return servletContext.getResourceAsStream(path); 051 } 052 053 054 @Override 055 public EmbeddedCacheManager getInfinispanCacheManager() { 056 057 // Constant from com.nimbusds.common.servlet.InfinispanLauncher.INFINISPAN_CTX_ATTRIBUTE_NAME 058 return (EmbeddedCacheManager) servletContext.getAttribute("org.infinispan.manager.EmbeddedCacheManager"); 059 } 060} 061