当前位置: 首页>>代码示例>>Java>>正文


Java ShiroFilter类代码示例

本文整理汇总了Java中org.apache.shiro.web.servlet.ShiroFilter的典型用法代码示例。如果您正苦于以下问题:Java ShiroFilter类的具体用法?Java ShiroFilter怎么用?Java ShiroFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShiroFilter类属于org.apache.shiro.web.servlet包,在下文中一共展示了ShiroFilter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的package包/类
/**
 * Initializes the Shiro Security Framework.
 */
@Override
public void start(BundleContext context) throws Exception {
	cacheProviderTracker = new CacheProviderTracker(context, CacheProvider.class);
	cacheProviderTracker.open();
	// Register the Shiro EnvironmentLoaderListener first.
	Dictionary<String, Object> shiroListenerProps = new Hashtable<>();
	shiroListenerProps.put(Constants.SERVICE_VENDOR, "AdeptJ");
	shiroListenerProps.put("osgi.http.whiteboard.listener", "true");
	servRegShiroListener = context.registerService(ServletContextListener.class, new ExtEnvironmentLoaderListener(),
			shiroListenerProps);
	// Now Register the ShiroFilter.
	Dictionary<String, Object> shiroFilterProps = new Hashtable<>();
	shiroFilterProps.put(Constants.SERVICE_VENDOR, "AdeptJ");
	shiroFilterProps.put("osgi.http.whiteboard.filter.name", "Shiro Filter");
	shiroFilterProps.put("osgi.http.whiteboard.filter.pattern", "/*");
	shiroFilterProps.put("osgi.http.whiteboard.filter.asyncSupported", "true");
	shiroFilterProps.put("osgi.http.whiteboard.filter.dispatcher",
			new String[] { "REQUEST", "INCLUDE", "FORWARD", "ASYNC", "ERROR" });
	servRegShiroFilter = context.registerService(Filter.class, new ShiroFilter(), shiroFilterProps);
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:24,代码来源:ShiroActivator.java

示例2: setupRestApiContextHandler

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的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());
  }
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:23,代码来源:ZeppelinServer.java

示例3: initializeShiro

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的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");
    }
}
 
开发者ID:Multifarious,项目名称:dw-shiro-bundle,代码行数:21,代码来源:ShiroBundle.java

示例4: ProductServletConfigurator

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的package包/类
@Inject
public ProductServletConfigurator(ServerConfig serverConfig, ShiroFilter shiroFilter, GitFilter gitFilter, 
		GitPreReceiveCallback preReceiveServlet, GitPostReceiveCallback postReceiveServlet, 
		WicketServlet wicketServlet, WebSocketManager webSocketManager, ServletContainer jerseyServlet) {
	this.serverConfig = serverConfig;
	this.shiroFilter = shiroFilter;
       this.gitFilter = gitFilter;
	this.preReceiveServlet = preReceiveServlet;
	this.postReceiveServlet = postReceiveServlet;
	this.wicketServlet = wicketServlet;
	this.webSocketManager = webSocketManager;
	this.jerseyServlet = jerseyServlet;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:14,代码来源:ProductServletConfigurator.java

示例5: test

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的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();
    }

}
 
开发者ID:apache,项目名称:polygene-java,代码行数:28,代码来源:WebServletShiroTest.java

示例6: shiroFilterRegistrationBean

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的package包/类
@Bean
public FilterRegistrationBean shiroFilterRegistrationBean() {
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    ShiroFilter shiroFilter = new ShiroFilter();
    registrationBean.setFilter(shiroFilter);
    registrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.values());
    registrationBean.setOrder(0);
    return registrationBean;
}
 
开发者ID:dma-graveyard,项目名称:MaritimeCloudPortalTestbed,代码行数:10,代码来源:ApplicationConfig.java

示例7: buildDeploymentInfo

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的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;
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:66,代码来源:UnderTowServer.java

示例8: initJettyServer

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的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);
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:52,代码来源:JettyServer.java

示例9: main

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的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();
  }
}
 
开发者ID:Java-Publications,项目名称:vaadin-016-helloworld-14,代码行数:46,代码来源:Main.java

示例10: createDeployment

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的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;
}
 
开发者ID:buom,项目名称:shiro-hmac,代码行数:74,代码来源:AppTest.java

示例11: SecurityFilterImplTest

import org.apache.shiro.web.servlet.ShiroFilter; //导入依赖的package包/类
public SecurityFilterImplTest() {
    suppress(method(ShiroFilter.class, "init"));
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:4,代码来源:SecurityFilterImplTest.java


注:本文中的org.apache.shiro.web.servlet.ShiroFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。