zoukankan      html  css  js  c++  java
  • SecurityContextHolder

    SecurityContextHolder.getContext().getAuthentication().getPrincipal()

     
    SecurityContextHolder.getContext().getAuthentication().getPrincipal()
     
     

    安全包括两个主要操作。

      第一个被称为“认证”,是为用户建立一个他所声明的主题。主题一般式指用户,设备或可以在你系统中执行动作的其他系统。

      第二个叫“授权”,指的是一个用户能否在你的应用中执行某个操作,在到达授权判断之前,身份的主题已经由身份验证过程建立。

    1. 在web.xml文件中加入Filter声明

    Xml代码  
    1.   
    2. <</span>filter>  
    3.     <</span>filter-name>springSecurityFilterChain</</span>filter-name>  
    4.     <</span>filter-class>org.springframework.web.filter.DelegatingFilterProxy</</span>filter-class>  
    5. </</span>filter>  
    6. <</span>filter-mapping>  
    7.     <</span>filter-name>springSecurityFilterChain</</span>filter-name>  
    8.     <</span>url-pattern>/*</</span>url-pattern>  
    9. </</span>filter-mapping>  

    获得当前已认证的用户的名字(obtain the name of the currently authenticated user)
     (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    官方案例如下:

    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    if (principal instanceof UserDetails) {

      String username = ((UserDetails)principal).getUsername();

    } else {

      String username = principal.toString();

    }

    访问受保护的资源

  • 相关阅读:
    IP保留地址
    HTML5读取本地文件
    angularjs中动态为audio绑定src
    canvas移动端常用技巧图片loading
    angularjs三级联动
    angular实现select的ng-options
    ng-bind-html在ng-repeat中问题的解决办法
    JS判断是否在微信浏览器打开
    angular实现select的ng-options
    创建 AngularJS 自定义过滤器,带自定义参数
  • 原文地址:https://www.cnblogs.com/husfsh-16300/p/6656920.html
Copyright © 2011-2022 走看看