本文整理汇总了Java中org.apache.shiro.web.env.EnvironmentLoaderListener类的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentLoaderListener类的具体用法?Java EnvironmentLoaderListener怎么用?Java EnvironmentLoaderListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EnvironmentLoaderListener类属于org.apache.shiro.web.env包,在下文中一共展示了EnvironmentLoaderListener类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupRestApiContextHandler
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
private static void setupRestApiContextHandler(WebAppContext webapp,
ZeppelinConfiguration conf) {
final ServletHolder servletHolder = new ServletHolder(
new org.glassfish.jersey.servlet.ServletContainer());
servletHolder.setInitParameter("javax.ws.rs.Application", ZeppelinServer.class.getName());
servletHolder.setName("rest");
servletHolder.setForcedPath("rest");
webapp.setSessionHandler(new SessionHandler());
webapp.addServlet(servletHolder, "/api/*");
String shiroIniPath = conf.getShiroPath();
if (!StringUtils.isBlank(shiroIniPath)) {
webapp.setInitParameter("shiroConfigLocations", new File(shiroIniPath).toURI().toString());
SecurityUtils.setIsEnabled(true);
webapp.addFilter(ShiroFilter.class, "/api/*", EnumSet.allOf(DispatcherType.class))
.setInitParameter("staticSecurityManagerEnabled", "true");
webapp.addEventListener(new EnvironmentLoaderListener());
}
}
示例2: initializeShiro
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
private void initializeShiro(final ShiroConfiguration config, Environment environment) {
if (config.isEnabled()) {
LOG.debug("Shiro is enabled");
if (config.isDropwizardSessionHandler() && environment.getApplicationContext().getSessionHandler() == null) {
LOG.debug("Adding DropWizard SessionHandler to environment.");
environment.getApplicationContext().setSessionHandler(new SessionHandler());
}
// This line ensure Shiro is configured and its .ini file found in the designated location.
// e.g., via the shiroConfigLocations ContextParameter with fall-backs to default locations if that parameter isn't specified.
environment.servlets().addServletListeners( new EnvironmentLoaderListener() );
final String filterUrlPattern = config.getSecuredUrlPattern();
LOG.debug("ShiroFilter will check URLs matching '{}'.", filterUrlPattern);
environment.servlets().addFilter("shiro-filter", new ShiroFilter()).addMappingForUrlPatterns( EnumSet.allOf(DispatcherType.class), true, filterUrlPattern );
} else {
LOG.debug("Shiro is not enabled");
}
}
示例3: test
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
@Test
public void test()
throws Exception
{
int port = FreePortFinder.findFreePortOnLoopback();
Server server = new Server( port );
try {
ServletContextHandler context = new ServletContextHandler();
context.setContextPath( "/" );
context.setInitParameter( "shiroConfigLocations", "classpath:web-shiro.ini" );
context.addEventListener( new EnvironmentLoaderListener() );
context.addFilter( ShiroFilter.class, "/*", EnumSet.of( REQUEST, FORWARD, INCLUDE, ERROR ) );
server.setHandler( context );
server.start();
// HttpClient client = new DefaultHttpClient();
// String result = client.execute( new HttpGet( "http://127.0.0.1:" + port + "/" ), new BasicResponseHandler() );
} finally {
server.stop();
}
}
示例4: shiroServletListenerRegistrationBean
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
@Bean
public ServletListenerRegistrationBean shiroServletListenerRegistrationBean() {
ServletListenerRegistrationBean registrationBean = new ServletListenerRegistrationBean();
EnvironmentLoaderListener environmentLoaderListener = new EnvironmentLoaderListener();
registrationBean.setListener(environmentLoaderListener);
registrationBean.setOrder(0);
return registrationBean;
}
示例5: configure
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
@Override
protected void configure()
{
bind(TablesResource.class).in(Scopes.SINGLETON);
bind(ExecuteResource.class).in(Scopes.SINGLETON);
bind(QueryResource.class).in(Scopes.SINGLETON);
bind(HealthResource.class).in(Scopes.SINGLETON);
bind(PingResource.class).in(Scopes.SINGLETON);
bind(SessionResource.class).in(Scopes.SINGLETON);
bind(SSEEventSourceServlet.class).in(Scopes.SINGLETON);
bind(FilesResource.class).in(Scopes.SINGLETON);
bind(ResultsPreviewResource.class).in(Scopes.SINGLETON);
bind(S3FilesResource.class).in(Scopes.SINGLETON);
httpClientBinder(binder()).bindHttpClient("query-info", ForQueryInfoClient.class)
.withConfigDefaults(HTTP_CLIENT_CONFIG_DEFAULTS);
httpClientBinder(binder()).bindHttpClient("query-runner", ForQueryRunner.class)
.withConfigDefaults(HTTP_CLIENT_CONFIG_DEFAULTS);
bind(EnvironmentLoaderListener.class).in(Scopes.SINGLETON);
bind(String.class).annotatedWith(Names.named("createTableDestinationSchema")).toInstance(config.getCreateTableDestinationSchema());
bind(String.class).annotatedWith(Names.named("s3Bucket")).toInstance(Strings.nullToEmpty(config.getS3Bucket()));
bind(PrestoHealthCheck.class).in(Scopes.SINGLETON);
bind(ExecutionClient.class).in(Scopes.SINGLETON);
bind(PersistentJobOutputFactory.class).in(Scopes.SINGLETON);
bind(JobHistoryStore.class).to(JobHistoryStoreDAO.class).in(Scopes.SINGLETON);
}
示例6: buildDeploymentInfo
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
private DeploymentInfo buildDeploymentInfo(JbootServerClassloader classloader) {
DeploymentInfo deploymentInfo = Servlets.deployment()
.setClassLoader(classloader)
.setResourceManager(new ClassPathResourceManager(classloader))
.setContextPath(config.getContextPath())
.setDeploymentName("jboot" + StringUtils.uuid())
.setEagerFilterInit(true); //设置启动的时候,初始化servlet或filter
JbootShiroConfig shiroConfig = Jboot.config(JbootShiroConfig.class);
if (shiroConfig.isConfigOK()) {
deploymentInfo.addListeners(Servlets.listener(EnvironmentLoaderListener.class));
deploymentInfo.addFilter(
Servlets.filter("shiro", ShiroFilter.class))
.addFilterUrlMapping("shiro", "/*", DispatcherType.REQUEST);
}
deploymentInfo.addFilter(
Servlets.filter("jfinal", JFinalFilter.class)
.addInitParam("configClass", Jboot.me().getJbootConfig().getJfinalConfig()))
.addFilterUrlMapping("jfinal", "/*", DispatcherType.REQUEST);
JbootHystrixConfig hystrixConfig = Jboot.config(JbootHystrixConfig.class);
if (StringUtils.isNotBlank(hystrixConfig.getUrl())) {
deploymentInfo.addServlets(
Servlets.servlet("HystrixMetricsStreamServlet", HystrixMetricsStreamServlet.class)
.addMapping(hystrixConfig.getUrl()));
}
JbootMetricConfig metricsConfig = Jboot.config(JbootMetricConfig.class);
if (StringUtils.isNotBlank(metricsConfig.getUrl())) {
deploymentInfo.addServlets(
Servlets.servlet("MetricsAdminServlet", AdminServlet.class)
.addMapping(metricsConfig.getUrl()));
deploymentInfo.addListeners(Servlets.listener(JbootMetricServletContextListener.class));
deploymentInfo.addListeners(Servlets.listener(JbootHealthCheckServletContextListener.class));
}
io.jboot.server.Servlets jbootServlets = new io.jboot.server.Servlets();
ContextListeners listeners = new ContextListeners();
JbootAppListenerManager.me().onJbootDeploy(jbootServlets, listeners);
for (Map.Entry<String, io.jboot.server.Servlets.ServletInfo> entry : jbootServlets.getServlets().entrySet()) {
ServletInfo servletInfo = Servlets.servlet(entry.getKey(), entry.getValue().getServletClass()).addMappings(entry.getValue().getUrlMapping());
deploymentInfo.addServlet(servletInfo);
}
for (Class<? extends ServletContextListener> listenerClass : listeners.getListeners()) {
deploymentInfo.addListeners(Servlets.listener(listenerClass));
}
deploymentInfo.addServlets(
Servlets.servlet("JbootResourceServlet", JbootResourceServlet.class)
.addMapping("/*"));
return deploymentInfo;
}
示例7: initJettyServer
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
private void initJettyServer() {
InetSocketAddress address = new InetSocketAddress(config.getHost(), config.getPort());
jettyServer = new Server(address);
handler = new ServletContextHandler();
handler.setContextPath(config.getContextPath());
handler.setClassLoader(new JbootServerClassloader(JettyServer.class.getClassLoader()));
handler.setResourceBase(getRootClassPath());
JbootShiroConfig shiroConfig = Jboot.config(JbootShiroConfig.class);
if (shiroConfig.isConfigOK()) {
handler.addEventListener(new EnvironmentLoaderListener());
handler.addFilter(ShiroFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
}
//JFinal
FilterHolder jfinalFilter = handler.addFilter(JFinalFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
jfinalFilter.setInitParameter("configClass", Jboot.me().getJbootConfig().getJfinalConfig());
JbootHystrixConfig hystrixConfig = Jboot.config(JbootHystrixConfig.class);
if (StringUtils.isNotBlank(hystrixConfig.getUrl())) {
handler.addServlet(HystrixMetricsStreamServlet.class, hystrixConfig.getUrl());
}
JbootMetricConfig metricsConfig = Jboot.config(JbootMetricConfig.class);
if (StringUtils.isNotBlank(metricsConfig.getUrl())) {
handler.addEventListener(new JbootMetricServletContextListener());
handler.addEventListener(new JbootHealthCheckServletContextListener());
handler.addServlet(AdminServlet.class, metricsConfig.getUrl());
}
io.jboot.server.Servlets jbootServlets = new io.jboot.server.Servlets();
ContextListeners listeners = new ContextListeners();
JbootAppListenerManager.me().onJbootDeploy(jbootServlets, listeners);
for (Map.Entry<String, io.jboot.server.Servlets.ServletInfo> entry : jbootServlets.getServlets().entrySet()) {
for (String path : entry.getValue().getUrlMapping()) {
handler.addServlet(entry.getValue().getServletClass(), path);
}
}
for (Class<? extends ServletContextListener> listenerClass : listeners.getListeners()) {
handler.addEventListener(ClassKits.newInstance(listenerClass));
}
jettyServer.setHandler(handler);
}
示例8: main
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
public static void main(String[] args) {
DeploymentInfo servletBuilder
= Servlets.deployment()
.setClassLoader(Main.class.getClassLoader())
.setContextPath(CONTEXT_PATH)
.setDeploymentName("ROOT.war")
.setDefaultEncoding("UTF-8")
.addListener(new ListenerInfo(EnvironmentLoaderListener.class))
.addFilter(new FilterInfo(SHIRO_FILTER, ShiroFilter.class))
.addFilterUrlMapping(SHIRO_FILTER, SHIRO_FILTER_MAPPING, REQUEST)
.addFilterUrlMapping(SHIRO_FILTER, SHIRO_FILTER_MAPPING, FORWARD)
.addFilterUrlMapping(SHIRO_FILTER, SHIRO_FILTER_MAPPING, INCLUDE)
.addFilterUrlMapping(SHIRO_FILTER, SHIRO_FILTER_MAPPING, ERROR)
.addServlets(
servlet(
MainServlet.class.getSimpleName(),
MainServlet.class).addMapping(SHIRO_FILTER_MAPPING)
);
DeploymentManager manager = Servlets
.defaultContainer()
.addDeployment(servletBuilder);
manager.deploy();
try {
HttpHandler httpHandler = manager.start();
PathHandler path = Handlers.path(redirect(CONTEXT_PATH))
.addPrefixPath(CONTEXT_PATH, httpHandler);
Undertow undertowServer = Undertow.builder()
.addHttpListener(8080, "0.0.0.0")
.setHandler(path)
.build();
undertowServer.start();
undertowOptional = Optional.of(undertowServer);
undertowServer.getListenerInfo().forEach(System.out::println);
} catch (ServletException e) {
e.printStackTrace();
undertowOptional = Optional.empty();
}
}
示例9: createDeployment
import org.apache.shiro.web.env.EnvironmentLoaderListener; //导入依赖的package包/类
@Deployment
public static WebArchive createDeployment() {
PomEquippedResolveStage pom = Maven.resolver().loadPomFromFile("pom.xml");
File[] libs = pom.resolve(
"ch.qos.logback:logback-classic").withTransitivity().asFile();
WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
.version(WebAppVersionType._3_0)
.createContextParam()
.paramName("liquibase.changelog")
.paramValue("src/test/resources/db.changelog.xml").up()
.createContextParam()
.paramName("liquibase.datasource")
.paramValue("shiro").up()
.createContextParam()
.paramName("liquibase.onerror.fail")
.paramValue("true").up()
.createListener()
.listenerClass(ContextListener.class.getName()).up()
.createListener()
.listenerClass(LiquibaseServletListener.class.getName()).up()
.createListener()
.listenerClass(EnvironmentLoaderListener.class.getName()).up()
.createContextParam()
.paramName("javax.ws.rs.Application")
.paramValue(Activator.class.getName()).up()
.createFilter()
.filterName("ShiroFilter")
.filterClass(ShiroFilter.class.getName()).up()
.createFilterMapping()
.filterName("ShiroFilter")
.urlPattern("/*").up()
.createFilter()
.filterName("Resteasy")
.filterClass(FilterDispatcher.class.getName()).up()
.createFilterMapping()
.filterName("Resteasy")
.urlPattern("/*").up()
.createResourceEnvRef()
.resourceEnvRefName("BeanManager")
.resourceEnvRefType(BeanManager.class.getName()).up()
.createErrorPage()
.exceptionType("java.lang.Exception")
.location("/error.jsp").up()
.createErrorPage()
.errorCode(400)
.location("/error.jsp").up()
.createErrorPage()
.errorCode(401)
.location("/error.jsp").up()
.createErrorPage()
.errorCode(403)
.location("/error.jsp").up()
.createErrorPage()
.errorCode(404)
.location("/error.jsp").up()
.createErrorPage()
.errorCode(500)
.location("/error.jsp").up();
WebArchive war = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
.setWebXML(new StringAsset(descriptor.exportAsString()))
.addAsLibraries(libs)
.addPackages(true, "me.buom.shiro")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new File("src/test/resources/jetty-env.xml"), "jetty-env.xml")
.addAsManifestResource(new File("src/test/resources/META-INF/aop.xml"), "aop.xml")
.addAsWebResource(new File("src/test/resources/error.jsp"), "error.jsp");
//System.out.println(descriptor.exportAsString());
//System.out.println(war.toString(true));
return war;
}