一、实现需求

登录框架采用shiro,需根据不同客户端类型实现相对应定义页面跳转。

二、登录页jsp表单

    <div class="input-prepend" title="Username" data-rel="tooltip">
<span class="add-on"><i class="icon-user"></i></span> <input type="text" id="username" name="username" value="${username}" class="input-medium required"/>
</div>
<div class="clearfix"></div> <div class="input-prepend" title="Password" data-rel="tooltip">
<span class="add-on"><i class="icon-lock"></i></span><input type="password" id="password" name="password" class="input-medium required"/>
</div>
<div class="clearfix"></div> <div><input type="hidden" id="clienttype" name="clienttype" value="pc"/></div> <div class="input-prepend">
<label class="checkbox" for="rememberMe"><input type="checkbox" id="rememberMe" name="rememberMe"/> 记住我<a href="${ctx}/register">注册</a></label>
</div>
<div class="clearfix"></div> <p class="center span5">
<button type="submit" class="btn btn-primary">登录</button>
</p>

三、自定义过滤器类

创建自定义过滤器LoginFormAuthenticationFilter,继承FormAuthenticationFilter。然后通过重写onLoginSuccess方法与WebUtils工具类,实现自定义跳转。

 

 public class LoginFormAuthenticationFilter extends FormAuthenticationFilter {

     private static Logger logger = LoggerFactory.getLogger(LoginFormAuthenticationFilter.class);

     @Override
protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request,
ServletResponse response) throws Exception { ShiroUser user = (ShiroUser) SecurityUtils.getSubject().getPrincipal(); if(user != null) {
HttpServletRequest req = (HttpServletRequest) request;
String clientType = (String) req.getParameter("clienttype");
logger.debug("[LOGIN]login success(user:" + user.loginName + ", client:" + clientType + ")");
if("pc".equals(clientType)) { // 请求方为pc,执行原方法
return super.onLoginSuccess(token, subject, request, response);
} else { // 其他,根据类型跳转指定页面
WebUtils.getAndClearSavedRequest(request); // 清除登录前请求路径
String fallbackUrl = null;
fallbackUrl = "/static/" + clientType + ".jsp"; // 自定义跳转界面
WebUtils.redirectToSavedRequest(request, response, fallbackUrl);
}
}
return false;
}
}

四、修改shiro配置文件

在applicationContext-shiro.xml中配置自定义过滤器。

首先,修改beans元素属性;

xmlns:util=http://www.springframework.org/schema/util

xsi:schemaLocation:

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd

其次,修改shiroFilter内容,添加自定义过滤器属性。

     <!-- 请求分发过滤器 -->
<bean id="loginDispacher" class="cn.com.mcfly.web.filter.LoginFormAuthenticationFilter"/>
<!-- Shiro Filter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/login" />
<property name="filters">
<util:map>
<entry key="authc" value-ref="loginDispacher"/>
</util:map>
</property>
<!--<property name="successUrl" value="/" />-->
<property name="filterChainDefinitions">
<value>
/static/** = anon
/login = authc
/logout = logout
...
/** = user
</value>
</property>
</bean>

shiro登录实现自定义路径跳转的更多相关文章

  1. 使用Shiro登录成功后,跳转到之前访问的页面实现

    转:http://blog.csdn.net/lhacker/article/details/20450855 很多时候,我们需要做到,当用户登录成功后,跳转回登录前的页面.如果用户是点击" ...

  2. 简单实现Shiro单点登录(自定义Token令牌)

    1. MVC Controller 映射 sso 方法. /** * 单点登录(如已经登录,则直接跳转) * @param userCode 登录用户编码 * @param token 登录令牌,令牌 ...

  3. Shiro登录成功之后跳到指定URL

    通常我们使用shiro,登录之后就会跳到我们上一次访问的URL,如果我们是直接访问登录页面的话,shiro就会根据我们配置的successUrl去重定向,如果我们没有配置successUrl的话,那么 ...

  4. Vue.js Extension Pack 和 jsconfig.json 可以定位跳转到@开头的路径等自定义路径

    Vue.js Extension Pack | vsCode插件 可以定位跳转到@开头的路径等自定义路径 webpack自定义别名后,VScode路径提示问题 //tsconfig.json 或者 j ...

  5. spring boot(十四)shiro登录认证与权限管理

    这篇文章我们来学习如何使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉及到这方面的需求.在Java领域一般有Spring Security ...

  6. shiro登录验证简单理解

    这两天接手了下师兄的项目,要给系统加个日志管理模块,其中需要记录登录功能的日志,那么首先要知道系统的登录是在哪里实现验证的. 该系统把所有登录验证还有权限控制的工作都交给了shiro. 这篇文章就先简 ...

  7. Springboot项目搭建(3)-shiro登录

    shiro简述+实现简单登录:https://www.jianshu.com/p/7f724bec3dc3

  8. Shiro登录中遇到了问题

    Shiro登录中遇到了问题 记录二次开发中遇到的问题, 如果系统学习Shiro, 推荐跟我学Shrio. 问题 项目是要将验证从本地改为LDAP验证, 但是因为jeecms的验证和授权中, 用户和角色 ...

  9. Spring Boot Shiro权限管理--自定义 FormAuthenticationFilter验证码整合

    思路shiro使用FormAuthenticationFilter进行表单认证,验证校验的功能应该加在FormAuthenticationFilter中,在认证之前进行验证码校验. 需要写FormAu ...

随机推荐

  1. C语言--第0次作业评分和总结(5班)

    作业链接http://www.cnblogs.com/ranh941/p/7496793.html 一.评分要求 *得分点1:建博客(5分) *得分点2:第0次作业(45分) **问题0:阅读推荐博客 ...

  2. 特殊符号 sort_wc_uniq命令 tee_tr_split命令

     *     任意个 任意字符 ?    任意一个字符  #     注释字符   \     转意符   |     管道符  (之前有说过) cut  命令: cut  -d "&quo ...

  3. rest-framework之版本控制

    rest-framework之版本控制 本文目录 一 作用 二 内置的版本控制类 三 局部使用 四 全局使用 五 示例 源码分析 回到目录 一 作用 用于版本的控制 回到目录 二 内置的版本控制类 f ...

  4. linux下使用小票打印

    linux下使用小票打印 打印机: Xprinter XP-58IIH指令支持: ESC/POS接口: USB, 蓝牙 Linux系统: Centos7 蓝牙配对很快, 配对好后就是连接状态. 但很快 ...

  5. 【mysql】索引原理-MySQL索引原理以及查询优化

    转载:https://www.cnblogs.com/bypp/p/7755307.html 一.介绍 1.什么是索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性 ...

  6. 芯灵思SINA33开发板怎样创建编译环境

    首先在Vmware安装好Centos,在此不再重复步骤,大家可以看以前的帖子有详细的步骤.本节主要介绍如何在Centos 搭建编译环境 Step 1 更新 CentOS 源 CentOS 由于很追求稳 ...

  7. redux笔记 进阶

    1 拆分UI组件和容器组件 import React from 'react' const AppUI = (props) =>{ return ( <div className=&quo ...

  8. Jenkins部署项目

    第三首先部署好Jenkins 新建一个自由项目 svn地址,credentials是指认证,点击Ad那里添加,并选择username和password方式,并输入用户名和密码 H/5 * * * * ...

  9. loging日志文件

    此文件要放到django 项目中的setting文件夹,可以对文件进行一些配置和修改 # 定义一下log文件存放的位置 BASE_LOG_DIR = os.path.join(BASE_DIR, &q ...

  10. 设置 IntelliJ IDEA 的彩色代码主题

    首先,给出一系列 IntelliJ IDEA 代码的彩色主题,供大家选择: VibrantUnknown(Darcula) FadeComments NicePython Solarized Have ...