org.apache.shiro.web.env.EnvironmentLoaderListener Java Examples

The following examples show how to use org.apache.shiro.web.env.EnvironmentLoaderListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZeppelinServer.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
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());
    webapp
        .addFilter(ShiroFilter.class, "/api/*", EnumSet.allOf(DispatcherType.class))
        .setInitParameter("staticSecurityManagerEnabled", "true");
    webapp.addEventListener(new EnvironmentLoaderListener());
  }
}
 
Example #2
Source File: ShiroBundle.java    From dw-shiro-bundle with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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");
    }
}
 
Example #3
Source File: ExampleApplication.java    From okta-auth-java with Apache License 2.0 5 votes vote down vote up
private void configureShiro(final Environment environment) {

        // One line to enable Shiro
        environment.jersey().register(ShiroFeature.class); // JAX-RS Feature

        // Dropwizard does not load servlet fragments, so we must configure the servlet filter
        environment.servlets().addServletListeners(new EnvironmentLoaderListener());
        environment.servlets().addFilter("ShiroFilter", ShiroFilter.class)
                .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
    }
 
Example #4
Source File: WebServletShiroTest.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@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();
    }

}
 
Example #5
Source File: AirpalModule.java    From airpal with Apache License 2.0 5 votes vote down vote up
@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);
}