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