Search in sources :

Example 1 with ShiroFilter

use of org.apache.shiro.web.servlet.ShiroFilter in project adeptj-modules by AdeptJ.

the class ShiroActivator method start.

/**
 * 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);
}
Also used : ExtEnvironmentLoaderListener(com.adeptj.modules.security.shiro.listener.ExtEnvironmentLoaderListener) CacheProviderTracker(com.adeptj.modules.security.shiro.internal.CacheProviderTracker) ServletContextListener(javax.servlet.ServletContextListener) ShiroFilter(org.apache.shiro.web.servlet.ShiroFilter) Filter(javax.servlet.Filter) Hashtable(java.util.Hashtable) CacheProvider(com.adeptj.modularweb.cache.api.CacheProvider) ShiroFilter(org.apache.shiro.web.servlet.ShiroFilter)

Example 2 with ShiroFilter

use of org.apache.shiro.web.servlet.ShiroFilter in project jena by apache.

the class ExFusekiMain_2_AddShiro method addShiroFilter.

// From Barry Nouwt : https://lists.apache.org/thread.html/r1e3fa952ff9f4a9108e16f07f1edf78c67e08c9b081497c627e3b833%40%3Cusers.jena.apache.org%3E
public static void addShiroFilter(FusekiServer fusekiServer) {
    Server jettyServer = fusekiServer.getJettyServer();
    ServletContextHandler servletContextHandler = (ServletContextHandler) jettyServer.getHandler();
    ServletHandler servletHandler = servletContextHandler.getServletHandler();
    // for shiro
    EnvironmentLoaderListener ell = new EnvironmentLoaderListener();
    servletContextHandler.addEventListener(ell);
    // Copies
    List<FilterMapping> mappings = new ArrayList<FilterMapping>(Arrays.asList(servletHandler.getFilterMappings()));
    List<FilterHolder> holders = new ArrayList<FilterHolder>(Arrays.asList(servletHandler.getFilters()));
    {
        // add Shiro Filter and mapping
        FilterHolder holder1 = new FilterHolder();
        holder1.setFilter(new ShiroFilter());
        FilterMapping mapping1 = new FilterMapping();
        mapping1.setFilterName(holder1.getName());
        mapping1.setPathSpec("/*");
        mapping1.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
        mappings.add(0, mapping1);
        holders.add(0, holder1);
    }
    FilterMapping[] mappings3 = new FilterMapping[mappings.size()];
    mappings3 = mappings.toArray(mappings3);
    FilterHolder[] holders3 = new FilterHolder[holders.size()];
    holders3 = holders.toArray(holders3);
    servletHandler.setFilters(holders3);
    servletHandler.setFilterMappings(mappings3);
    // Specify the Session ID Manager
    SessionIdManager idmanager = new DefaultSessionIdManager(jettyServer);
    jettyServer.setSessionIdManager(idmanager);
    // Specify the session handler
    SessionHandler sessionsHandler = new SessionHandler();
    sessionsHandler.setUsingCookies(false);
    servletHandler.setHandler(sessionsHandler);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) EnvironmentLoaderListener(org.apache.shiro.web.env.EnvironmentLoaderListener) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) Server(org.eclipse.jetty.server.Server) ArrayList(java.util.ArrayList) FilterMapping(org.eclipse.jetty.servlet.FilterMapping) SessionIdManager(org.eclipse.jetty.server.SessionIdManager) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ShiroFilter(org.apache.shiro.web.servlet.ShiroFilter)

Aggregations

ShiroFilter (org.apache.shiro.web.servlet.ShiroFilter)2 CacheProvider (com.adeptj.modularweb.cache.api.CacheProvider)1 CacheProviderTracker (com.adeptj.modules.security.shiro.internal.CacheProviderTracker)1 ExtEnvironmentLoaderListener (com.adeptj.modules.security.shiro.listener.ExtEnvironmentLoaderListener)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Filter (javax.servlet.Filter)1 ServletContextListener (javax.servlet.ServletContextListener)1 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)1 EnvironmentLoaderListener (org.apache.shiro.web.env.EnvironmentLoaderListener)1 Server (org.eclipse.jetty.server.Server)1 SessionIdManager (org.eclipse.jetty.server.SessionIdManager)1 DefaultSessionIdManager (org.eclipse.jetty.server.session.DefaultSessionIdManager)1 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)1 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)1 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)1