@RequestMapping("/index")
public ModelAndView login(
@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout,
HttpServletRequest request) {
 
ModelAndView model = new ModelAndView();
if (error != null) {
model.addObject("error", "请输入有效的用户名和密码");
}
 
/* if (logout != null) {
model.addObject("msg", "您已经成功退出");
}*/
model.setViewName("index");
 
SecurityContextImpl securityContextImpl = (SecurityContextImpl) request
.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
if(securityContextImpl!=null){
String username=securityContextImpl.getAuthentication().getName();// 登录名
request.getSession().setAttribute("username", username);
// 登录密码,未加密的
System.out.println("Credentials:"
+ securityContextImpl.getAuthentication().getCredentials());
WebAuthenticationDetails details = (WebAuthenticationDetails) securityContextImpl
.getAuthentication().getDetails();
// 获得访问地址
//System.out.println("RemoteAddress" + details.getRemoteAddress());
// 获得sessionid
//System.out.println("SessionId" + details.getSessionId());
// 获得当前用户所拥有的权限
/* List<GrantedAuthority> authorities = (List<GrantedAuthority>) securityContextImpl
.getAuthentication().getAuthorities();
for (GrantedAuthority grantedAuthority : authorities) {
System.out.println("Authority" + grantedAuthority.getAuthority());
}*/
}
return model;
 
}

spring security在spring mvc的action中获取登录人信息的更多相关文章

  1. spring mvc在Controller中获取ApplicationContext

    spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...

  2. Spring Security构建Rest服务-0102-Spring Social开发第三方登录之qq登录

    图一 基于SpringSocial实现qq登录,要走一个OAuth流程,拿到服务提供商qq返回的用户信息. 由上篇介绍的可知,用户信息被封装在了Connection里,所以最终要拿到Connectio ...

  3. Spring Security +Oauth2 +Spring boot 动态定义权限

    Oauth2介绍:Oauth2是为用户资源的授权定义了一个安全.开放及简单的标准,第三方无需知道用户的账号及密码,就可获取到用户的授权信息,并且这是安全的. 简单的来说,当用户登陆网站的时候,需要账号 ...

  4. PART 5: INTEGRATING SPRING SECURITY WITH SPRING BOOT WEB

    转自:http://justinrodenbostel.com/2014/05/30/part-5-integrating-spring-security-with-spring-boot-web/ ...

  5. 【手摸手,带你搭建前后端分离商城系统】03 整合Spring Security token 实现方案,完成主业务登录

    [手摸手,带你搭建前后端分离商城系统]03 整合Spring Security token 实现方案,完成主业务登录 上节里面,我们已经将基本的前端 VUE + Element UI 整合到了一起.并 ...

  6. Keycloak 团队宣布他们正在弃用大多数 Keycloak 适配器,包括Spring Security和Spring Boot

    2月14日,Keycloak 团队宣布他们正在弃用大多数 Keycloak 适配器. 其中包括Spring Security和Spring Boot的适配器,这意味着今后Keycloak团队将不再提供 ...

  7. MVC 在控制器中获取某个视图动态的HTML代码

    ASP.NET MVC 在控制器中获取某个视图动态的HTML代码   如果我们需要动态的用AJAX从服务器端获取HTML代码,拼接字符串是一种不好的方式,所以我们将HTML代码写在cshtml文件中, ...

  8. 9.Struts2在Action中获取request-session-application对象

    为避免与Servlet API耦合在一起,方便Action类做单元测试. Struts2对HttpServletRequest.HttpSession.ServletContext进行了封装,构造了三 ...

  9. struts2:JSP页面及Action中获取HTTP参数(parameter)的几种方式

    本文演示了JSP中获取HTTP参数的几种方式,还有action中获取HTTP参数的几种方式. 1. 创建JSP页面(testParam.jsp) <%@ page language=" ...

随机推荐

  1. python学习【第二篇】初识python

    python的安装 windows 1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装路径:C:\python27 3.配置环境变量 [右键计算机] ...

  2. SharePoint让所有用户访问站点

    SharePoint让所有用户访问站点,可用在用户组里面添加:NT AUTHORITY\authenticated users

  3. Partial Sum

    Partial Sum Accepted : 80   Submit : 353 Time Limit : 3000 MS   Memory Limit : 65536 KB  Partial Sum ...

  4. SharePoint服务器端对象模型 之 访问网站和列表数据(Part 2)

    (二)列表(SPList) 列表是SharePoint中最为重要的数据容器,我们一般保存在SharePoint中的所有数据,都是保存在列表中(文档库也是一种列表),因此列表对象在SharePoint的 ...

  5. a database of all existing files

    mlocate.db(5): mlocate database - Linux man page  https://linux.die.net/man/5/mlocate.db Name mlocat ...

  6. Man-in-the-middle attack

    w https://en.wikipedia.org/wiki/Man-in-the-middle_attack https://zh.wikipedia.org/wiki/中间人攻击 需要通过一个安 ...

  7. docker desktop

    https://github.com/rogaha/docker-desktop http://blog.csdn.net/tinylab/article/details/45443563

  8. iOS 多线程之 NSThread的基本使用

    一个NSThread对象就代表一条线程 下面是NSThread开启线程的方法 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEv ...

  9. mustache模板技术(转)

    项目首页:http://mustache.github.com/  项目文档:http://mustache.github.com/mustache.5.html  Demo:  http://mus ...

  10. python下多线程的限制以及多进程中传递参数的方式

    python多线程有个全局解释器锁(global interpreter lock),这个锁的意思是任一时间只能有一个线程使用解释器,跟单cpu跑多个程序一个意思,大家都是轮着用的,这叫“并发”,不是 ...