package com.mango.jtt.springSecurity;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.security.web.savedrequest.SavedRequest;
import com.mango.jtt.po.MangoUser;
import com.mango.jtt.service.IUserService;
/**
* 登录授权成功后操作控制,如果是直接点击登录的情况下,根据授权权限跳转不同页面; 否则跳转到原请求页面
*
* @author HHL
* @date
*
*/
public class MyAuthenticationSuccessHandler extends
SavedRequestAwareAuthenticationSuccessHandler {
private Map<String, String> authDispatcherMap;
private RequestCache requestCache = new HttpSessionRequestCache();
@Autowired
private IUserService userService;
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
// 获取用户权限
Collection<? extends GrantedAuthority> authCollection = authentication
.getAuthorities();
if (authCollection.isEmpty()) {
return;
}
// 认证成功后,获取用户信息并添加到session中
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
MangoUser user = userService.getUserByName(userDetails.getUsername());
request.getSession().setAttribute("user", user);
String url = null;
// 从别的请求页面跳转过来的情况,savedRequest不为空
SavedRequest savedRequest = requestCache.getRequest(request, response);
if (savedRequest != null) {
url = savedRequest.getRedirectUrl();
}
// 直接点击登录页面,根据登录用户的权限跳转到不同的页面
if (url == null) {
for (GrantedAuthority auth : authCollection) {
url = authDispatcherMap.get(auth.getAuthority());
}
getRedirectStrategy().sendRedirect(request, response, url);
}
super.onAuthenticationSuccess(request, response, authentication);
}
public RequestCache getRequestCache() {
return requestCache;
}
public void setRequestCache(RequestCache requestCache) {
this.requestCache = requestCache;
}
public Map<String, String> getAuthDispatcherMap() {
return authDispatcherMap;
}
public void setAuthDispatcherMap(Map<String, String> authDispatcherMap) {
this.authDispatcherMap = authDispatcherMap;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Spring Security4.1.3跳转控制配置
共266个文件
svn-base:151个
java:28个
class:28个
5星 · 超过95%的资源 需积分: 16 89 下载量 62 浏览量
2016-12-23
17:03:49
上传
评论 1
收藏 377KB ZIP 举报
温馨提示
该代码描述了Security实现根据请求跳转不同登录页以及登录后根据权限跳转到不同页配置 ,相关介绍可参见http://blog.csdn.net/honghailiang888/article/details/53765508
资源推荐
资源详情
资源评论
收起资源包目录
Spring Security4.1.3跳转控制配置 (266个子文件)
fileSnapshots.bin 19KB
taskArtifacts.bin 19KB
fileHashes.bin 19KB
.buildpath 577B
MyAuthenticationSuccessHandler.class 5KB
OrderController.class 3KB
MyAuthenticationEntryPoint.class 3KB
Order.class 3KB
MyAuthenticationFailureHandler.class 2KB
MyUserDetailsService.class 2KB
MangoDaoImpl.class 2KB
Product.class 2KB
XmlAspect.class 2KB
LogAspect.class 1KB
LogUtil.class 1KB
UserServiceImpl.class 1KB
ProductController.class 1KB
MangoUser.class 1KB
ManagerController.class 1KB
PageController.class 1KB
OrderServiceImpl.class 1KB
ProductServiceImpl.class 1KB
UserController.class 1KB
DateUtil.class 1KB
SecurityController.class 832B
APPWideExceptionHandler.class 678B
TaskJob.class 443B
BaseBean.class 379B
IProductService.class 322B
IMangoDao.class 307B
IOrderService.class 271B
IUserService.class 202B
.classpath 732B
org.eclipse.wst.common.component 753B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 2KB
wc.db 124KB
entries 3B
format 3B
build.gradle 2KB
favicon.ico 66KB
MyAuthenticationSuccessHandler.java 3KB
OrderController.java 2KB
Order.java 2KB
MyAuthenticationEntryPoint.java 2KB
Product.java 1KB
MyAuthenticationFailureHandler.java 1KB
MyUserDetailsService.java 1KB
MangoUser.java 1KB
MangoDaoImpl.java 1KB
XmlAspect.java 1KB
OrderServiceImpl.java 996B
ManagerController.java 910B
LogAspect.java 874B
PageController.java 871B
ProductController.java 839B
DateUtil.java 818B
UserServiceImpl.java 810B
LogUtil.java 776B
ProductServiceImpl.java 767B
UserController.java 744B
SecurityController.java 624B
IMangoDao.java 588B
IOrderService.java 480B
IProductService.java 436B
APPWideExceptionHandler.java 434B
TaskJob.java 369B
BaseBean.java 331B
IUserService.java 228B
nonono.jpg 20KB
team.jpg 5KB
jquery.js 56KB
.jsdtscope 530B
default.jsp 2KB
product_detail.jsp 1KB
login.jsp 1012B
login.jsp 995B
index.jsp 856B
order_pay.jsp 788B
security_deny.jsp 605B
order_submit.jsp 600B
index.jsp 435B
taglibs.jsp 425B
header.jsp 202B
footer.jsp 166B
404.jsp 40B
cache.properties.lock 17B
MANIFEST.MF 39B
org.eclipse.wst.jsdt.ui.superType.name 6B
com.genuitec.eclipse.j2eedt.core.prefs 1009B
org.eclipse.jdt.core.prefs 598B
org.springsource.ide.eclipse.gradle.core.prefs 294B
org.springsource.ide.eclipse.gradle.refresh.prefs 274B
org.eclipse.core.resources.prefs 146B
org.eclipse.vjet.eclipse.core.prefs 74B
.project 2KB
jdbc.properties 2KB
jdbc.properties 2KB
cache.properties 31B
4fe3a0545bddc84d121b7e9e65be6423a87b6aa0.svn-base 66KB
共 266 条
- 1
- 2
- 3
资源评论
- liusxblog2017-08-23非常不错,感谢
Herman-Hong
- 粉丝: 547
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功