zoukankan      html  css  js  c++  java
  • spring security和java web token整合

    思路:

    spring security

    1、用户输入用户名密码。

    2、验证:从库中(可以是内存、数据库等)查询该用户的密码、角色,验证用户名和密码是否正确。如果正确,则将填充Authentication(UsernamePasswordAuthenticationToken是其实现类),填充Authentication,会将用户的角色也填充进去。

    Authentication authentication= new UsernamePasswordAuthenticationToken(auth.getName(),
            auth.getCredentials(), AUTHORITIES);//设置用户名、密码、权限列表创建Authentication对象,AUTHORITIES为权限列表
    

    3、授权:根据WebSecurityConfigurerAdapter中的configure(HttpSecurity httpSecurity)配置,FilterSecurityInterceptor会 判断此用户是否可以访问handler。如果没有权限,则会抛出异常。

    4、SecurityContextHolder会管理填充好的Authentication,SecurityContextHolder利用ThreadLocal管理这些安全对象,这样在逻辑代码中随时取出用户的信息。

    java web token

    参考:https://www.cnblogs.com/BonnieWss/p/11129400.html

    spring security与jwt整合

    1、从请求头中取出jwt,并解析,如果能正确解析,说明可以通过验证,并取出其负载信息UserDetails

    2、将UserDetails填充Authentication

    Authentication authentication= new UsernamePasswordAuthenticationToken(userDetails,
            userDetails.getCredentials(), userDetails.getAuthorities);//设置用户名、密码、权限列表创建Authentication对象,AUTHORITIES为权限列表

    3、后续步骤和spring security一样

    具体代码参考:https://www.cnblogs.com/BonnieWss/p/11149699.html

  • 相关阅读:
    (二)WCF的Binding模型
    (一)WCF基础
    EF映射——从数据库更新实体
    没有什么不可能(1)
    MySQL SQL Training
    MySQL 并发事务问题以及事务的隔离级别
    MySQL 数据库面试题
    MySQL create table语法详解
    MySQL create table语法中的key与index的区别
    MySQL 官方样板数据库sakila
  • 原文地址:https://www.cnblogs.com/BonnieWss/p/11359023.html
Copyright © 2011-2022 走看看