Search in sources :

Example 1 with AccessControlFilter

use of org.apache.shiro.web.filter.AccessControlFilter in project shiro by apache.

the class ShiroFilterFactoryBean method applyLoginUrlIfNecessary.

private void applyLoginUrlIfNecessary(Filter filter) {
    String loginUrl = getLoginUrl();
    if (StringUtils.hasText(loginUrl) && (filter instanceof AccessControlFilter)) {
        AccessControlFilter acFilter = (AccessControlFilter) filter;
        // only apply the login url if they haven't explicitly configured one already:
        String existingLoginUrl = acFilter.getLoginUrl();
        if (AccessControlFilter.DEFAULT_LOGIN_URL.equals(existingLoginUrl)) {
            acFilter.setLoginUrl(loginUrl);
        }
    }
}
Also used : AccessControlFilter(org.apache.shiro.web.filter.AccessControlFilter)

Example 2 with AccessControlFilter

use of org.apache.shiro.web.filter.AccessControlFilter in project nutzboot by nutzam.

the class NbResourceBasedWebEnvironment method configure.

protected void configure() {
    this.objects.clear();
    WebSecurityManager securityManager = createWebSecurityManager();
    setWebSecurityManager(securityManager);
    String loginUrl = conf.get(ShiroEnvStarter.PROP_URL_LOGIN, "/user/login");
    String unauthorizedUrl = conf.get(ShiroEnvStarter.PROP_URL_UNAUTH, "/user/login");
    String logoutUrl = conf.get(ShiroEnvStarter.PROP_URL_LOGOUT_REDIRECT, "/");
    for (Map.Entry<String, Filter> en : DefaultFilter.createInstanceMap(null).entrySet()) {
        Filter filter = en.getValue();
        if (filter instanceof LogoutFilter) {
            ((LogoutFilter) filter).setRedirectUrl(logoutUrl);
        } else if (filter instanceof AuthenticatingFilter) {
            ((AuthenticatingFilter) filter).setLoginUrl(loginUrl);
        } else if (filter instanceof AccessControlFilter) {
            ((AccessControlFilter) filter).setLoginUrl(unauthorizedUrl);
        }
        objects.put(en.getKey(), en.getValue());
    }
    for (String objectName : Strings.splitIgnoreBlank(conf.get("shiro.objects", ""))) {
        objects.put(objectName, ioc.get(null, objectName));
    }
    FilterChainResolver resolver = createFilterChainResolver();
    if (resolver != null) {
        setFilterChainResolver(resolver);
    }
    NutShiro.DefaultLoginURL = loginUrl;
    NutShiro.DefaultNoAuthURL = unauthorizedUrl;
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) AuthenticatingFilter(org.apache.shiro.web.filter.authc.AuthenticatingFilter) AccessControlFilter(org.apache.shiro.web.filter.AccessControlFilter) AccessControlFilter(org.apache.shiro.web.filter.AccessControlFilter) DefaultFilter(org.apache.shiro.web.filter.mgt.DefaultFilter) Filter(javax.servlet.Filter) LogoutFilter(org.apache.shiro.web.filter.authc.LogoutFilter) AuthenticatingFilter(org.apache.shiro.web.filter.authc.AuthenticatingFilter) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) LogoutFilter(org.apache.shiro.web.filter.authc.LogoutFilter) Map(java.util.Map)

Aggregations

AccessControlFilter (org.apache.shiro.web.filter.AccessControlFilter)2 Map (java.util.Map)1 Filter (javax.servlet.Filter)1 AuthenticatingFilter (org.apache.shiro.web.filter.authc.AuthenticatingFilter)1 LogoutFilter (org.apache.shiro.web.filter.authc.LogoutFilter)1 DefaultFilter (org.apache.shiro.web.filter.mgt.DefaultFilter)1 FilterChainResolver (org.apache.shiro.web.filter.mgt.FilterChainResolver)1 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)1