Search in sources :

Example 1 with KickoutSessionFilter

use of com.cdeledu.core.shiro.filter.KickoutSessionFilter in project wechat by dllwh.

the class ShiroConfig method kickoutSessionFilter.

/**
 * @方法描述 : 限制同一账号登录同时登录人数控制
 * @return
 */
public KickoutSessionFilter kickoutSessionFilter() {
    KickoutSessionFilter kickoutSessionFilter = new KickoutSessionFilter();
    // 使用cacheManager获取相应的cache来缓存用户登录的会话;用于保存用户—会话之间的关系的;
    // 这里我们还是用之前shiro使用的redisManager()实现的cacheManager()缓存管理
    // 也可以重新另写一个,重新配置缓存时间之类的自定义缓存属性
    // kickoutSessionFilter.setCacheManager(cacheManager());
    // 用于根据会话ID,获取会话进行踢出操作的;
    // kickoutSessionFilter.setSessionManager(sessionManager());
    // 是否踢出后来登录的,默认是false;即后者登录的用户踢出前者登录的用户;踢出顺序。
    kickoutSessionFilter.setKickoutAfter(false);
    // 同一个用户最大的会话数,默认1;比如2的意思是同一个用户允许最多同时两个人登录;
    kickoutSessionFilter.setMaxSession(1);
    // 被踢出后重定向到的地址;
    kickoutSessionFilter.setKickoutUrl(FilterHelper.KICKED_OUT);
    return kickoutSessionFilter;
}
Also used : KickoutSessionFilter(com.cdeledu.core.shiro.filter.KickoutSessionFilter)

Example 2 with KickoutSessionFilter

use of com.cdeledu.core.shiro.filter.KickoutSessionFilter in project wechat by dllwh.

the class ShiroConfig method shiroFilter.

/**
 * ----------------------------------------------------- Fields end
 */
/**
 * @方法描述 :
 *
 *       <pre>
 *  Shiro主过滤器本身功能十分强大,其强大之处就在于它支持任何基于URL路径表达式的、自定义的过滤器的执行
 *  Web应用中,Shiro可控制的Web请求必须经过Shiro主过滤器的拦截,Shiro对基于Spring的Web应用提供了完美的支持
 *       </pre>
 *
 * @return
 */
// @Bean("shiroFilter")
public ShiroFilterFactoryBean shiroFilter() {
    ShiroFilterFactoryBean shiroFilterFactory = new ShiroFilterFactoryBean();
    // Shiro的核心安全接口,这个属性是必须的
    shiroFilterFactory.setSecurityManager(securityManager());
    // 要求登录时的链接(可根据项目的URL进行替换),非必须的属性,如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
    shiroFilterFactory.setLoginUrl(FilterHelper.LOGIN_ACTION);
    // 登录成功后要跳转的链接
    shiroFilterFactory.setSuccessUrl(FilterHelper.LOGIN_ACTION);
    // 用户访问未对其授权的资源时,所显示的连接;
    shiroFilterFactory.setUnauthorizedUrl(FilterHelper.UNAUTHORIZED);
    /**
     * 自定义拦截器
     */
    Map<String, Filter> filtersMap = new LinkedHashMap<String, Filter>();
    // 登录校验
    filtersMap.put("loginFilter", new LoginFilter());
    // 角色判断校验
    filtersMap.put("roleFilter", new RoleFilter());
    // 权限校验
    filtersMap.put("permissionFilter", new PermissionFilter());
    filtersMap.put("kickoutFilter", kickoutSessionFilter());
    // 用户session
    filtersMap.put("userSessionFilter", new UserSessionFilter());
    shiroFilterFactory.setFilters(filtersMap);
    /**
     * Shiro连接约束配置,即权限控制map.
     * 第一个'/'代表的路径是相对于HttpServletRequest.getContextPath()的值来的
     */
    Map<String, String> filterMap = new LinkedHashMap<String, String>();
    filterMap.put("/loginController**", "anon");
    filterMap.put("/sysPage/**", "anon,kickoutFilter");
    filterMap.put("/homeController/**", "loginFilter");
    filterMap.put("/dataSourceController**", "authc,roleFilter[administrator]");
    filterMap.put("/**", "authc,loginFilter,permissionFilter,kickoutFilter");
    shiroFilterFactory.setFilterChainDefinitionMap(filterMap);
    return shiroFilterFactory;
}
Also used : ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) RoleFilter(com.cdeledu.core.shiro.filter.RoleFilter) UserSessionFilter(com.cdeledu.core.shiro.filter.UserSessionFilter) LoginFilter(com.cdeledu.core.shiro.filter.LoginFilter) PermissionFilter(com.cdeledu.core.shiro.filter.PermissionFilter) KickoutSessionFilter(com.cdeledu.core.shiro.filter.KickoutSessionFilter) Filter(javax.servlet.Filter) RoleFilter(com.cdeledu.core.shiro.filter.RoleFilter) LoginFilter(com.cdeledu.core.shiro.filter.LoginFilter) PermissionFilter(com.cdeledu.core.shiro.filter.PermissionFilter) LinkedHashMap(java.util.LinkedHashMap) UserSessionFilter(com.cdeledu.core.shiro.filter.UserSessionFilter)

Aggregations

KickoutSessionFilter (com.cdeledu.core.shiro.filter.KickoutSessionFilter)2 LoginFilter (com.cdeledu.core.shiro.filter.LoginFilter)1 PermissionFilter (com.cdeledu.core.shiro.filter.PermissionFilter)1 RoleFilter (com.cdeledu.core.shiro.filter.RoleFilter)1 UserSessionFilter (com.cdeledu.core.shiro.filter.UserSessionFilter)1 LinkedHashMap (java.util.LinkedHashMap)1 Filter (javax.servlet.Filter)1 ShiroFilterFactoryBean (org.apache.shiro.spring.web.ShiroFilterFactoryBean)1