/** * Configures this instance based on the existing {@link org.apache.shiro.web.env.WebEnvironment} instance * available to the currently accessible {@link #getServletContext() servletContext}. * * @see org.apache.shiro.web.env.EnvironmentLoaderListener * @since 1.2 */ @Override public void init() throws Exception { WebEnvironment env = WebUtils.getRequiredWebEnvironment(getServletContext()); setSecurityManager(env.getWebSecurityManager()); FilterChainResolver resolver = env.getFilterChainResolver(); if (resolver != null) { setFilterChainResolver(resolver); } } }
@Bean public FilterRegistrationBean someFilterRegistration() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new ShiroFilter()); registration.addUrlPatterns("/admin/*","static/*"); registration.setName("shiro-admin-filter"); registration.setOrder(1); return registration; }
@Override public void init() throws Exception { super.init(); LOG.debug("Initializing the AAAShiroFilter"); } }
@Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); final String DEBUG_MESSAGE = "Setting AAAFilter enabled to " + enabled; LOG.debug(DEBUG_MESSAGE); } }
@Override public void destroy() { super.destroy(); setContextAttribute(KEY, null); }
@Override protected void doFilterInternal(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String target = request.getRequestURI(); if (contextPathLength != 0) { target = target.substring(contextPathLength); } if (target.indexOf('.') != -1 || JbootWebsocketManager.me().isWebsokcetEndPoint(target)) { chain.doFilter(request, response); return; } super.doFilterInternal(request, response, chain); } }
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"); } }
@Override public void init() throws Exception { super.init(); setContextAttribute(KEY, this); }
/** * Sets up Shiro on the servlet context lifecycle, and establishes a URL pattern to protect. * * @param config The Shiro configuration. * @param environment The DropWizard environment. */ private void initializeShiro(ShiroConfiguration config, Environment environment) { if (config.isEnabled()) { if (config.isDropwizardSessionHandler()) { environment.servlets().setSessionHandler(new SessionHandler()); } environment.servlets().addServletListeners(new EnvironmentLoaderListener()); String filterUrlPattern = config.getSecuredUrlPattern(); environment.servlets() .addFilter("shiro-filter", new ShiroFilter()) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, filterUrlPattern); } } }
@Override public void init() throws Exception { super.init(); final String DEBUG_MESSAGE = "Initializing the AAAFilter"; LOG.debug(DEBUG_MESSAGE); // sets the filter to the startup value. Because of non-determinism in // bundle loading, this passes an instance of itself along so that if // the // enable status changes, then AAAFilter enable status is changed. setEnabled(ServiceProxy.getInstance().getEnabled(this)); }