- 浏览: 7834546 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (2425)
- 软件工程 (75)
- JAVA相关 (662)
- ajax/web相关 (351)
- 数据库相关/oracle (218)
- PHP (147)
- UNIX/LINUX/FREEBSD/solaris (118)
- 音乐探讨 (1)
- 闲话 (11)
- 网络安全等 (21)
- .NET (153)
- ROR和GOG (10)
- [网站分类]4.其他技术区 (181)
- 算法等 (7)
- [随笔分类]SOA (8)
- 收藏区 (71)
- 金融证券 (4)
- [网站分类]5.企业信息化 (3)
- c&c++学习 (1)
- 读书区 (11)
- 其它 (10)
- 收藏夹 (1)
- 设计模式 (1)
- FLEX (14)
- Android (98)
- 软件工程心理学系列 (4)
- HTML5 (6)
- C/C++ (0)
- 数据结构 (0)
- 书评 (3)
- python (17)
- NOSQL (10)
- MYSQL (85)
- java之各类测试 (18)
- nodejs (1)
- JAVA (1)
- neo4j (3)
- VUE (4)
- docker相关 (1)
最新评论
-
xiaobadi:
jacky~~~~~~~~~
推荐两个不错的mybatis GUI生成工具 -
masuweng:
(转)JAVA获得机器码的实现 -
albert0707:
有些扩展名为null
java 7中可以判断文件的contenttype了 -
albert0707:
非常感谢!!!!!!!!!
java 7中可以判断文件的contenttype了 -
zhangle:
https://zhuban.me竹板共享 - 高效便捷的文档 ...
一个不错的网络白板工具
在spring security 3中,在登录 后,如何根据不同的需要跳转到不同的页面呢 ?
其中要 自定义的过滤器是 AuthenticationSuccessHandler,
然后自定义的类要实现 AuthenticationSuccessHandler接口 ,代码如下 :
其中要关注的是determineTargetUrl方法,传入 的参数是 Authentication类型的,然后进行权限的 判断
其中要 自定义的过滤器是 AuthenticationSuccessHandler,
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xsi:schemaLocation=" http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <http use-expressions="true" > <intercept-url pattern="/login*" access="permitAll" /> <intercept-url pattern="/**" access="isAuthenticated()" /> <form-login login-page='/login.html' authentication-failure-url="/login.html?error=true" authentication-success-handler-ref="myAuthenticationSuccessHandler"/> <logout/> </http> <beans:bean id="myAuthenticationSuccessHandler" class="org.company.MySimpleUrlAuthenticationSuccessHandler" /> <authentication-manager> <authentication-provider> <user-service> <user name="user1" password="user1Pass" authorities="ROLE_USER" /> <user name="admin1" password="admin1Pass" authorities="ROLE_ADMIN" /> </user-service> </authentication-provider> </authentication-manager> </beans:beans>
然后自定义的类要实现 AuthenticationSuccessHandler接口 ,代码如下 :
public class MySimpleUrlAuthenticationSuccessHandler implements AuthenticationSuccessHandler { protected Log logger = LogFactory.getLog(this.getClass()); private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { handle(request, response, authentication); clearAuthenticationAttributes(request); } protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { String targetUrl = determineTargetUrl(authentication); if (response.isCommitted()) { logger.debug("Response has already been committed. Unable to redirect to " + targetUrl); return; } redirectStrategy.sendRedirect(request, response, targetUrl); } protected String determineTargetUrl(Authentication authentication) { boolean isUser = false; boolean isAdmin = false; Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); for (GrantedAuthority grantedAuthority : authorities) { if (grantedAuthority.getAuthority().equals("ROLE_USER")) { isUser = true; break; } else if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) { isAdmin = true; break; } } if (isUser) { return "/homepage.html"; } else if (isAdmin) { return "/console.html"; } else { throw new IllegalStateException(); } } protected void clearAuthenticationAttributes(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session == null) { return; } session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); } public void setRedirectStrategy(RedirectStrategy redirectStrategy) { this.redirectStrategy = redirectStrategy; } protected RedirectStrategy getRedirectStrategy() { return redirectStrategy; } }
其中要关注的是determineTargetUrl方法,传入 的参数是 Authentication类型的,然后进行权限的 判断
发表评论
-
复习:强迫线程顺序执行方式
2019-01-03 23:42 1465方法1: 三个线程,t1,t2,t3,如果一定要按顺序执行, ... -
(转)不错的前后端处理异常的方法
2019-01-02 23:16 1957前言 在 Web 开发中, 我们经常会需要处理各种异常, 这是 ... -
info q的极客时间大咖说等资料下载
2018-08-15 08:40 3406info q的极客时间大咖说等资料下载,还有不少思维导图 链 ... -
CXF 客户端超时时间设置(非Spring配置方式)
2018-07-03 22:38 2172import org.apache.cxf.endpoint. ... -
(转)synchronized关键字画像:正确打开方式
2018-06-14 09:25 438https://mp.weixin.qq.com/s/b3Sx ... -
CountDownLatch的例子
2018-06-13 14:10 622public class StatsDemo { ... -
两道面试题,带你解析Java类加载机制
2018-06-12 16:29 543https://mp.weixin.qq.com/s/YTa0 ... -
Spring中获取request的几种方法,及其线程安全性分析
2018-06-11 09:03 613https://mp.weixin.qq.com/s/KeFJ ... -
内部类小结
2018-06-06 10:25 385https://mp.weixin.qq.com/s/hErv ... -
JVM虚拟机小结1
2018-06-04 20:43 4451 jps -l //列出详细的类名和进程ID 2)jps ... -
windows下自带命令行工具查看CPU资源情况等
2018-06-04 12:53 3031微软提供了不少命令行 ... -
(收藏)深入分析Java的序列化与反序列化
2018-05-30 15:21 544https://mp.weixin.qq.com/s/T2Bn ... -
apache common包中的序列化工具
2018-05-30 09:10 1762什么是序列化 我们的 ... -
JAVA8 JVM的变化: 元空间(Metaspace)
2018-05-24 22:30 896本文将会分享至今为至我收集的关于永久代(Permanent G ... -
(转)服务器性能指标(一)——负载(Load)分析及问题排查
2018-05-21 21:03 1252原创: Hollis Hollis 负载 ... -
(转)对象复用
2018-05-20 15:27 799public class Student { priv ... -
mapreduce中入门中要注意的几点
2018-05-06 08:59 607在 mapreduce中,比如有如下的词: I love b ... -
HDFS的基本操作
2018-05-02 21:47 866-mkdir 在HDFS创建目录 ... -
一个不错的开源工具类,专门用来解析日志头部的,好用
2018-05-02 20:00 697一个不错的开源工具类,专门用来解析日志头部的,好用。 http ... -
介绍个不错的RESTFUL MOCK的工具wiremock
2018-04-27 21:02 1842介绍个不错的RESTFUL MOCK的工具wiremock,地 ...
相关推荐
运行SpringBootMainClass启动后,请在地址栏访问http://ip:port,在页面中登录,成功后会跳转至下一个页面,此时需要后退到刚才的页面,点击各个超链接来试验用户的授权情况。未登录时点击任何链接都会跳回首页。 ...
主要介绍了Spring Security跳转页面失败问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
springSecurity 实现登陆验证、传参,包括源代码和MYSQL的建库脚本。 传参的功能可以实现记录登陆之前打开的页面,登陆之后自动跳转到之前打开的页面。
这个是基于Spring的一个小例子 , 主要是为了帮助大家学习...4.如果不是admin,就跳转到 无权访问页面, 5.还有可以使用SpringMVC进行前后台的交互 还有可以使用自定义的过滤器来实现登录, 有不懂的问题 可以加我
默认情况下,Spring Security提供一个基本的登录页面。你可以通过配置来自定义登录页面的URL、登录表单字段等。 3.处理登录成功和失败: 使用.defaultSuccessUrl()来指定登录成功后跳转的页面; 使用.failureUrl()来...
该代码描述了Security实现根据请求跳转不同登录页以及登录后根据权限跳转到不同页配置 ,相关介绍可参见http://blog.csdn.net/honghailiang888/article/details/53765508
这个是基于Spring的一个小例子 , 主要是为了帮助大家学习SpringSecurity和SpringMvc 和Mybatis3.0 1.SS不用再数据库建表 2.使用了SS提供的登录方式,在输入用户名和密码时,访问到服务器后台 3.判断如果是用户名是...
security3.2最新版本配置,资源里面有4个小项目,都是利用maven搭建的,先在mysql中...示例中只运用了登录后的跳转。在我的博客有介绍security执行的流程图:http://blog.csdn.net/u011511684/article/details/31394493
主要介绍了Ajax登陆使用Spring Security缓存跳转到登陆前的链接,需要的朋友可以参考下
是spring一类的包,用于中跳转网页之间的权限管理,可以快速进行权限管理
实现方案 我们先来想一下,如果我们不依靠任何框架,自己如何实现后端 Session 集中存储。 这里我们假设我们的网站除了某些页面,比如首页可以直接...如果用户没有登录,我们需要将请求强制跳转到登录页面进行登录。
尽可能贴合 Spring Security 的设计 实现注解权限控制 登入: POST 用户名密码到 \login 请求到达 JwtAuthenticationFilter 中的 attemptAuthentication() 方法,获取 request 中的 POST 参数,包装成一个 ...
更改了RedirectUtils类的 response.sendRedirect(response.encodeRedirectURL(final...因此无论是有跳转目标还是没有跳转目标 会往页面发送 { status:"true", url: "........." } 通过页面接收url来决定页面的走向。
SpringSecurity的三个jar包,可以快速的完成网页跳转之间的权限管理。
SpringBoot整合SpringSecurity简单实现登入登出从零搭建这是SpringSecurity实现登录和登出的一个简单示例,基于 Spring Boot 1.5.6基本实现 : 用户信息存储在数据库中,登陆时从数据库中查询匹配用户信息。...
一个小demo前后端分离的情况下给到前端是否跳转到登录页的标识符
1、spring版本:4.3.2.RELEASE+spring security 版本:4.1.2.RELEASE(其它不做说明) 2、所展示内容全部用注解配置 3、springmvc已经配置好,不作说明 4、会涉及到springmvc,spel,el的东西,不熟悉的同学...
Spring boot作为后端,vue框架实现前端,后端整合swagger3测试工具,jwt实现验证码生成,awt生成图形验证码,整合邮箱验证,使用mybatis-generator自动生成实体类以及mapper,设置有拦截器验证登录状态,设置有跨域...
【资源说明】 该项目是个人毕设项目源码,评审分达到95分,都经过严格...## 技术环境: JDK1.8 SpringSecurity SpringBoot Mysql Mybatis Thymeleaf echarts 管理员账户密码: admin/admin 用户账户密码: user/123