SpringSecurity + JWT,从入门到精通!

spring Security + jwt使用 spring Security + jwt 阅读详情
权限系统躲不开的概念,在Shiro和Spring Security之间,你一般选啥?在前后端分离的项目中,你知道怎么Spring security整合Jwt么,来看看这篇文章哈!

作者:小小____

https://segmentfault.com/a/1190000023052493

思维导图如下

RBAC 全称为基于角色的权限控制,本段将会从什么是 RBAC,模型分类,什么是权限,用户组的使用,实例分析等几个方面阐述 RBAC

思维导图

绘制思维导图如下

什么是 RBAC

RBAC 全称为用户角色权限控制,通过角色关联用户,角色关联权限,这种方式,间阶的赋予用户的权限,如下图所示

对于通常的系统而言,存在多个用户具有相同的权限,在分配的时候,要为指定的用户分配相关的权限,修改的时候也要依次的对这几个用户的权限进行修改,有了角色这个权限,在修改权限的时候,只需要对角色进行修改,就可以实现相关的权限的修改。这样做增加了效率,减少了权限漏洞的发生。

模型分类

对于 RBAC 模型来说,分为以下几个模型 分别是 RBAC0,RBAC1,RBAC2,RBAC3,这四个模型,这段将会依次介绍这四个模型,其中最常用的模型有 RBAC0.

RBAC0

RBAC0 是最简单的 RBAC 模型,这里面包含了两种。

用户和角色是多对一的关系,即一个用户只充当一种角色,一个角色可以有多个角色的担当。
用户和角色是多对多的关系,即,一个用户可以同时充当多个角色,一个角色可以有多个用户。
此系统功能单一,人员较少,这里举个栗子,张三既是行政,也负责财务,此时张三就有俩个权限,分别是行政权限,和财务权限两个部分。

RBAC1

相对于 RBAC0 模型来说,增加了子角色,引入了继承的概念。

RBAC2 模型

这里 RBAC2 模型,在 RBAC0 模型的基础上,增加了一些功能,以及限制

角色互斥

即,同一个用户不能拥有两个互斥的角色,举个例子,在财务系统中,一个用户不能拥有会计员和审计这两种角色。

基数约束

即,用一个角色,所拥有的成员是固定的,例如对于 CEO 这种角色,同一个角色,也只能有一个用户。

先决条件

即,对于该角色来说,如果想要获得更高的角色,需要先获取低一级别的角色。举个栗子,对于副总经理和经理这两个权限来说,需要先有副总经理权限,才能拥有经理权限,其中副总经理权限是经理权限的先决条件。

运行时互斥

即,一个用户可以拥有两个角色,但是这俩个角色不能同时使用,需要切换角色才能进入另外一个角色。举个栗子,对于总经理和专员这两个角色,系统只能在一段时间,拥有其一个角色,不能同时对这两种角色进行操作。

RBAC3 模型

即,RBAC1,RBAC2,两者模型全部累计,称为统一模型。

什么是权限

权限是资源的集合,这里的资源指的是软件中的所有的内容,即,对页面的操作权限,对页面的访问权限,对数据的增删查改的权限。举个栗子。对于下图中的系统而言,

拥有,计划管理,客户管理,合同管理,出入库通知单管理,粮食安全追溯,粮食统计查询,设备管理这几个页面,对这几个页面的访问,以及是否能够访问到菜单,都属于权限。

用户组的使用

对于用户组来说,是把众多的用户划分为一组,进行批量授予角色,即,批量授予权限。举个栗子,对于部门来说,一个部门拥有一万多个员工,这些员工都拥有相同的角色,如果没有用户组,可能需要一个个的授予相关的角色,在拥有了用户组以后,只需要,把这些用户全部划分为一组,然后对该组设置授予角色,就等同于对这些用户授予角色。

优点:减少工作量,便于理解,增加多级管理,等。

首先添加依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

然后添加相关的访问接口

package com.example.demo.web;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class Test {
    @RequestMapping("/test")
    public String test(){
        return "test";
    }
}
关注公众号:MarkerHub,回复[999]获取前后端入门教程,以及企业面试题!

最后启动项目,在日志中查看相关的密码

访问接口,可以看到相关的登录界面

输入用户名和相关的密码

用户名:user
密码 984cccf2-ba82-468e-a404-7d32123d0f9c

登录成功

增加用户名和密码

在配置文件中,书写相关的登录和密码

spring:
  security:
    user:
      name: ming
      password: 123456
      roles: admin
      

在登录页面,输入用户名和密码,即可正常登录

基于内存的认证

需要自定义类继承 WebSecurityConfigurerAdapter 代码如下

package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;


@Configuration
public class MyWebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Bean
    PasswordEncoder passwordEncoder(){
        return NoOpPasswordEncoder.getInstance();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("admin").password("123").roles("admin");
    }
}

即,配置的用户名为 admin,密码为 123,角色为 admin

HttpSecurity

这里对一些方法进行拦截

package com.ming.demo.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;

@Configuration
@EnableWebSecurity
public class SecurityConfig  extends WebSecurityConfigurerAdapter {
    
    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("itguang").password("123456").roles("USER").and()
                .withUser("admin").password("{noop}" + "123456").roles("ADMIN");
    }





    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().permitAll()
                .and()
                .formLogin()
                .permitAll()
                .and()
                .logout()
                .permitAll();
    }


}


即,这里完成了对所有的方法访问的拦截。

这是一个小 demo,目的,登录以后返回 jwt 生成的 token

导入依赖

添加 web 依赖

导入 JWT 和 Security 依赖

 
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>

创建一个 JwtUser 实现 UserDetails

创建 一个相关的 JavaBean

package com.example.demo;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class JwtUser implements UserDetails {
    private String username;
    private String password;
    private Integer state;
    private Collection<? extends GrantedAuthority> authorities;
    public JwtUser(){

    }

    public JwtUser(String username, String password, Integer state,  Collection<? extends GrantedAuthority> authorities){
        this.username = username;
        this.password = password;
        this.state = state;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}

编写工具类生成令牌

编写工具类,用来生成 token,以及刷新 token,以及验证 token。关注公众号:MarkerHub,回复[999]获取前后端入门教程,以及企业面试题!

package com.example.demo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class JwtTokenUtil implements Serializable {
    private String secret;
    private Long expiration;
    private String header;

    private String generateToken(Map<String, Object> claims) {
        Date expirationDate = new Date(System.currentTimeMillis() + expiration);
        return Jwts.builder().setClaims(claims).setExpiration(expirationDate).signWith(SignatureAlgorithm.HS512, secret).compact();
    }

    private Claims getClaimsFromToken(String token) {
        Claims claims;
        try {
            claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();

        } catch (Exception e) {
            claims = null;
        }
        return claims;
    }

    public String generateToken(UserDetails userDetails) {
        Map<String, Object> claims = new HashMap<>(2);
        claims.put("sub", userDetails.getUsername());
        claims.put("created", new Date());
        return generateToken(claims);

    }

    public String getUsernameFromToken(String token) {
        String username;
        try {
            Claims claims = getClaimsFromToken(token);
            username = claims.getSubject();

        } catch (Exception e) {
            username = null;

        }
        return username;

    }

    public Boolean isTokenExpired(String token) {
        try {
            Claims claims = getClaimsFromToken(token);
            Date expiration = claims.getExpiration();
            return expiration.before(new Date());
        } catch (Exception e) {
            return false;
        }
    }

    public String refreshToken(String token) {
        String refreshedToken;
        try {
            Claims claims = getClaimsFromToken(token);
            claims.put("created", new Date());
            refreshedToken = generateToken(claims);

        } catch (Exception e) {
            refreshedToken = null;

        }
        return refreshedToken;
    }

    public Boolean validateToken(String token, UserDetails userDetails) {
        JwtUser user = (JwtUser) userDetails;
        String username = getUsernameFromToken(token);
        return (username.equals(user.getUsername()) && !isTokenExpired(token));

    }

}

编写拦截器

编写 Filter 用来检测 JWT

package com.example.demo;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class JwtAuthenticationTokenFilter  extends OncePerRequestFilter {
    @Autowired
    private UserDetailsService userDetailsService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;


    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        String authHeader = httpServletRequest.getHeader(jwtTokenUtil.getHeader());
        if (authHeader != null && StringUtils.isNotEmpty(authHeader)) {
            String username = jwtTokenUtil.getUsernameFromToken(authHeader);
            if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
                UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
                if (jwtTokenUtil.validateToken(authHeader, userDetails)) {
                    UsernamePasswordAuthenticationToken authentication  =
                    new UsernamePasswordAuthenticationToken(userDetails,null,userDetails.getAuthorities());
                    authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
                    SecurityContextHolder.getContext().setAuthentication(authentication);

                }
            }
        }
        filterChain.doFilter(httpServletRequest, httpServletResponse);

    }
}

编写 userDetailsService 的实现类

在上方代码中,编写 userDetailsService,类,实现其验证过程

package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.management.relation.Role;
import java.util.List;

@Service
public class JwtUserDetailsServiceImpl  implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user = userMapper.selectByUserName(s);
        if (user == null) {
            throw new UsernameNotFoundException(String.format("'%s'.这个用户不存在", s));

        }
        List<SimpleGrantedAuthority> collect = user.getRoles().stream().map(Role::getRolename).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
        return new JwtUser(user.getUsername(), user.getPassword(), user.getState(), collect);

    }
}

编写登录

编写登录业务的实现类 其 login 方法会返回一个 JWTUtils 的 token

@Service
public class UserServiceImpl  implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    public User findByUsername(String username) {
        User user = userMapper.selectByUserName(username);
        return user;

    }

    public RetResult login(String username, String password) throws AuthenticationException {
        UsernamePasswordAuthenticationToken upToken = new UsernamePasswordAuthenticationToken(username, password);
        final Authentication authentication = authenticationManager.authenticate(upToken);
        SecurityContextHolder.getContext().setAuthentication(authentication);
        UserDetails userDetails = userDetailsService.loadUserByUsername(username);
        return new RetResult(RetCode.SUCCESS.getCode(),jwtTokenUtil.generateToken(userDetails));

    }
}

最后配置 Config

@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter {
    @Autowired
    private UserDetailsService userDetailsService;
    @Autowired
    private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;

    @Autowired
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
        authenticationManagerBuilder.userDetailsService(this.userDetailsService).passwordEncoder(passwordEncoder());

    }

    @Bean(name = BeanIds.AUTHENTICATION_MANAGER)

    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and().authorizeRequests()
                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                .antMatchers("/auth/**").permitAll()
                .anyRequest().authenticated()
                .and().headers().cacheControl();


        http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);

        ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http.authorizeRequests();

        registry.requestMatchers(CorsUtils::isPreFlightRequest).permitAll();

    }

    @Bean
    public CorsFilter corsFilter() {
        final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration cors = new CorsConfiguration();
        cors.setAllowCredentials(true);
        cors.addAllowedOrigin("*");
        cors.addAllowedHeader("*");
        cors.addAllowedMethod("*");
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", cors);
        return new CorsFilter(urlBasedCorsConfigurationSource);

    }
}

运行,返回 token

运行,返回结果为 token

这里配置 SpringSecurity 之 JSON 登录

这里需要重写 UsernamePasswordAnthenticationFilter 类,以及配置 SpringSecurity

重写 UsernamePasswordAnthenticationFilter

public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter {

    @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {

        
        if(request.getContentType().equals(MediaType.APPLICATION_JSON_UTF8_VALUE)
                ||request.getContentType().equals(MediaType.APPLICATION_JSON_VALUE)){

            
            ObjectMapper mapper = new ObjectMapper();
            UsernamePasswordAuthenticationToken authRequest = null;
            try (InputStream is = request.getInputStream()){
                AuthenticationBean authenticationBean = mapper.readValue(is,AuthenticationBean.class);
                authRequest = new UsernamePasswordAuthenticationToken(
                        authenticationBean.getUsername(), authenticationBean.getPassword());
            }catch (IOException e) {
                e.printStackTrace();
                authRequest = new UsernamePasswordAuthenticationToken(
                        "", "");
            }finally {
                setDetails(request, authRequest);
                return this.getAuthenticationManager().authenticate(authRequest);
            }
        }

        
        else {
            return super.attemptAuthentication(request, response);
        }
    }
}

配置 SecurityConfig

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .cors().and()
            .antMatcher("/**").authorizeRequests()
            .antMatchers("/", "/login**").permitAll()
            .anyRequest().authenticated()
            
            .and().formLogin().loginPage("/")
            .and().csrf().disable();

    
    http.addFilterAt(customAuthenticationFilter(),
    UsernamePasswordAuthenticationFilter.class);
}


@Bean
CustomAuthenticationFilter customAuthenticationFilter() throws Exception {
    CustomAuthenticationFilter filter = new CustomAuthenticationFilter();
    filter.setAuthenticationSuccessHandler(new SuccessHandler());
    filter.setAuthenticationFailureHandler(new FailureHandler());
    filter.setFilterProcessesUrl("/login/self");

    
    filter.setAuthenticationManager(authenticationManagerBean());
    return filter;
}


这样就完成使用 json 登录 SpringSecurity

需要在 Config 类中配置如下内容

 
    @Bean
    public BCryptPasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

即,使用此方法,对密码进行加密, 在业务层的时候,使用此加密的方法

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    private UserRepository userRepository;

    @Resource
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    @Override
    public User add(User user) {
        user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
        User user2 = userRepository.save(user);
        return user2;
    }
    @Override
    public ResultInfo login(User user) {
        ResultInfo resultInfo=new ResultInfo();
        User user2 = userRepository.findByName(user.getName());
        if (user2==null) {
            resultInfo.setCode("-1");
            resultInfo.setMessage("用户名不存在");
            return resultInfo;
        }

        
        if (!bCryptPasswordEncoder.matches(user.getPassword(),user2.getPassword())) {
            resultInfo.setCode("-1");
            resultInfo.setMessage("密码不正确");
            return resultInfo;
        }
        resultInfo.setMessage("登录成功");
        return resultInfo;
    }
}

即,使用 BCryptPasswordEncoder 对密码进行加密,保存数据库

这里使用数据库认证 SpringSecurity

设计数据表

这里设计数据表

着重配置 SpringConfig

@Configurable
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private UserService userService;

    @Bean
    PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        
        auth.userDetailsService(userService);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/admin/**").hasRole("admin")
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginProcessingUrl("/login").permitAll()
                .and()
                .csrf().disable();
    }
}

这里着重配置 SpringConfig

着重讲解了 RBAC 的权限配置,以及简单的使用 SpringSecurity,以及使用 SpringSecurity + JWT 完成前后端的分离,以及配置 json 登录,和密码加密方式,

Security+jwt+验证码实现验证和授权 微服务Security+jwt+验证码实现认证和授权简要介绍基本流程核心代码测试 简要介绍 本次博客采用Spring Security、jwt、验证码的形式实现登录验证,项目本上是一个前后端分离项目。如果你的项目在登陆时不需要验证码,你只需要在后续的代码中,将有关验证码的过滤器删除。 基本流程 1、前端请求后端"/captcha"验证码接口,后端生成验证码文本及编码并将其存入redis缓存,然后返回验证码文本(五个字符)和验证码base64编码给前端。 2、前端显示验证码图片,用户输入用户名、密码、验证码 阅读详情

相关推荐

RBAC&&Shiro

RBAC&&ShiroRBAC1、 什么是 RBAC2、 RBAC96 模型1 RBAC 模型2 RBAC03 RBAC14 RBAC2Shiro1、Shiro 的简介A、 为什么学习 ShiroB、 解决的方案C、 什么是 shiroD、 Shiro 中的体系的组成E、 shiro 的架构2、Shiro 的环境搭建第一步 导包第二步: 书写 shiro.ini 文件第三步: 书写测试代码3、Shiro 验证时异常分析4、Shiro--认证流程A、 通过 shiro 相关的 API 创建了S

liu_to_liu的博客 1331

Spring Security+JWT简述

目录一. 什么是Spring Security1. 登陆校验的流程2. SpringSecurity基础案例二. Spring Security原理流程 一. 什么是Spring Security Spring Security是Spring家族的一个安全管理框架, 相比于另一个安全框架Shiro, 它具有更丰富的功能。一般中大型项目都是使用SpringSecurity做安全框架, 而Shiro上手比较简单 spring security 的核心功能: 认证(你是谁): 只有你的用户名或密码正确才能

姜守威的博客 2万+

SpringBoot整合SpringSecurity实现JWT认证

前言 微服务架构,前后端分离目前已成为互联网项目开发的业界标准,其核心思想就是前端(APP、小程序、H5页面等)通过调用后端的API接口,提交及返回JSON数据进行交互。 在前后端分离项目中,首先要解决的就是登录及授权的问题。微服务架构下,传统的session认证限制了应用的扩展能力,无状态的JWT认证方法应运而生,该认证机制特别适用于分布式站点的单点登录(SSO)场景 目录 该文会通过创建...

我的博客 3万+

SpringBoot+Security+Vue前后端分离开发权限管理系统

适用人群所有的IT从业者,尤其适合快速掌握新技术,快速增长工作经验人群,对教育公平,教育公益,教育爱心公益人士课程概述该互联网实战项目是基于 Spring Boot 2+ SpringSecurity5+Element UI+Vue Admin Template+蚂蚁可视化AntV 等技术栈开发的项目,采用分布式,多模块,前后端分离开发。包括图形展示、权限管理、用户管理等功能。【后端技术】技术说明Spring Boot2MVC框架 开发的一站式解决方案Spring Security5 认证和授权框架MyBatisPlus3.3.1 基于 MyBatis 框架的快速研发框架MyBatisCode工具生成 MyBatis 相关代码Jackson提供了处理 JSON 数据的工具Lombok简化对象封装工具 Druid   数据库连接池 【前端技术】Vue       互联网最火的前端框架Vue Router路由框架Vuex全局状态管理框架Axios前端 HTTP 框架Element UI前端 UI 框架Vue Element Admin前端模板Antv  蚂蚁金服可视化技术,阿里巴巴可视化技术,天猫,淘宝,支付宝,花呗均使用AntV【开发工具】IntelliJ IDEA开发 IDESQLyog数据库连接客户端PostmanHTTP 请求工具【开发环境】工具版本JDK1.8MySQL5.7

SpringBoot+SpringSecurity+JWT实现认证和授权

一、背景: 在 B/S 系统中,登录功基本都是依靠 Cookie 来实现的,用户登录成功之后主要需要客户端和服务端完成以下两项工作: (1)服务端将登录状态记录到 Session 中,或者签发Token; (2)客户端利用Cookie保存于服务端对应的 Session ID 或 Token。之后每次请求都会带上Cookie信息(包含Session ID或者Token),当服务端收到请求后,通过验证 Cookie 中的信息来判断用户是否登录 。 单点登录:单点登录(Single Sign On, S.

oyc的博客 5万+

SpringBoot+SpringSecurity+JWT整合

SpringSecurity入门简单案例适合新手学习

seeyouagain_的博客 1万+

SpringSecurity-从入门到精通

SpringSecurity从入门到精通 介绍 0. 简介 ​ Spring Security 是 Spring 家族中的一个安全管理框架。相比与另外一个安全框架Shiro,它提供了更丰富的功能,社区资源也比Shiro丰富。 ​ 一般来说中大型的项目都是使用SpringSecurity 来做安全框架。小项目有Shiro的比较多,因为相比与SpringSecurity,Shiro的上手更加的简单。 ​ 一般Web应用的需要进行认

Lifelong learning 6万+

整合SpringSecurity和JWT实现登录认证和授权

文章目录前言一、SpringSecurity是什么?二、JWT是什么?1. JWT的组成2. JWT实现认证和授权的原理三、整合步骤1. 引入相关依赖2. yml配置中加入jwt配置信息3. 添加JWT token的工具类4. 添加SpringSecurity的配置类5. 添加自定义结果处理类5.1 添加CustomAccessDeniedHandler5.2 添加CustomAuthenticationEntryPoint6. 添加JwtUser类7. 添加过滤器JwtAuthenticationTok

Java升级之路的博客 5181

SpringSecurity 整合 JWT

项目集成Spring Security(一) 在上一篇基础上继续集成 JWT ,实现用户身份验证。 前言 前后端分离项目中,如果直接把 API 接口对外开放,我们知道这样风险是很大的,所以在上一篇中我们引入了 Spring Security ,但是我们在登陆后缺少了请求凭证部分。 什么是JWT? JWT是 Json Web Token 的缩写。它是基于 RFC 7519 标准定义的一种可以安全...

niceyoo的博客 1万+

10分钟快速搭建OpenClaw(基于Windows+飞书)

OpenClaw 是一款功能强大的 AI 智能体工具,能够帮助用户管理邮件、日历等日常事务。本文详细介绍了在 Windows11 系统上安装和配置 OpenClaw 的完整步骤,包括 Node.js 环境搭建、Git 安装、OpenClaw 部署以及飞书机器人创建与对接。通过简单的命令行操作和可视化界面配置,用户可以快速完成 AI 助手部署,实现智能办公自动化。文中还提供了飞书机器人权限设置等关键环节的图文指引,帮助用户轻松完成系统集成。

Hello, New World! 2927

大白话讲解Numpy中什么是一维、二维、三维数组,以及5种创建方式

NumPy中提供了多种创建数组的方式,其中最基本的方式就是通过array()函数创建数组在使用该函数时直接传入列表或元组即可。 通过array()函数分别创建一维数组、二维组和三维数组,那么什么是维度呢?一维、二维、三维有什么区别? 1、什么是维度? 维度可以理解为描述数据的一种 “方向” 或者 “层次”。在数组中,维度的数量决定了我们需要用多少个索引来访问一个元素 2、一维、二维、三维的区别? (1)一维:一维数组就像是一条直线上排列的一组数据,例如: a = np.array([1, 2

1365

SpringSecurity从入门到精通【三更草堂笔记】

SpringSecurity入门到精通

qq_45847507的博客 8780

特征金字塔网络(Feature Pyramid Network, FPN)

特征金字塔网络(FPN)是计算机视觉领域的一个里程碑式工作,通过高效的多尺度特征融合,显著提升了目标检测和分割任务的性能。其核心在于自底向上路径、自顶向下路径和横向连接的协同工作,兼顾了高分辨率和强语义信息。FPN的通用性和高效性使其成为许多现代检测框架的标配模块。

Rhett_Butler0922的博客 1728

SpringSecurity+JWT快速入门

SpringSecurity+JWT快速入门

胡云峰的博客 5741

期货套利策略(二)

接上一篇期货套利策略,随着对期货套利策略的深入了解,我发现套利策略不是那么好做的。下面将会讲碰到的一些问题。 上一篇文章中没有考虑滑点的问题,这里我们把滑点问题考虑进去。这里先说一些天勤api的买入点,天琴的买入点是当前K线的收盘价。碰到数据传输问题,还有计算等各方面问题,实际情况是无法在当前K线的收盘价买入的。这里我们把这方面问题考虑进去,利用api.wait_update()调到下一个k线数据...

qq_31611005的博客 1714

英伟达 Jetson AGX Thor 官方入门教程(二)CUDA、Docker、JetPack 设置

本文详细介绍了NVIDIA Jetson AGX Thor开发套件的安装与配置流程。主要内容包括:1) BSP安装的三种方法(Jetson ISO、SDK Manager和Linux刷写脚本)及其适用场景;2) Docker环境的完整配置步骤及测试方法;3) CUDA工具包的两种安装方式(容器化和原生安装)及其性能对比;4) JetPack SDK的安装选项。文章提供了详细的命令行操作指南和故障排除建议,帮助开发者快速搭建AI开发环境,充分发挥Jetson平台的硬件性能优势。

机器人控制与仿真应用 1738

SpringBoot3.0 + SpringSecurity6.0+JWT

SpringBoot3.0 + SpringSecurity6.0+JWTSpring Security 是 Spring 家族中的一个安全管理框架。一般Web应用的需要进行认证和授权。认证:验证当前访问系统的是不是本系统的用户,并且要确认具体是哪个用户授权:经过认证后判断当前用户是否有权限进行某个操作搭建一个SpringBoot工程① 设置父工程 添加依赖 配置文件application.yml ② 创建启动类 ③ 创建Controller 启动项目,查看接口文档地址:http://localhost:4

胖胖爱吃肉~的博客 2万+

基于MATLAB的鲁棒主成分分析(Robust PCA)图像去噪

鲁棒主成分分析(Robust PCA)是一种有效的图像去噪方法,它能够在保持图像细节的同时去除噪声。本文将介绍如何使用MATLAB实现基于鲁棒PCA的图像去噪,并提供相应的源代码。它假设噪声是随机的、高斯分布的,并将图像分解为一个低秩矩阵和一个稀疏矩阵的和。低秩矩阵表示图像的结构和纹理信息,稀疏矩阵表示图像中的噪声和细节信息。接下来,我们将图像矩阵减去均值,得到规范化的图像矩阵。然后,我们将灰度图像转换为矩阵形式,并计算图像的均值。通过分离出低秩矩阵和稀疏矩阵,我们就得到了去噪后的图像和残差图像。

DevRevolt的博客 1125

SpringSecurity + JWT,从入门到精通

权限系统躲不开的概念,在Shiro和Spring Security之间,你一般选啥?在前后端分离的项目中,你知道怎么Spring security整合JWT么,来看看这篇文章哈! 思维导图如下: RBAC 全称为基于角色的权限控制,本段将会从什么是 RBAC,模型分类,什么是权限,用户组的使用,实例分析等几个方面阐述 RBAC 思维导图 绘制思维导图如下 什么是 RBAC RBAC 全称为用户角色权限控制,通过角色关联用户,角色关联权限,这种方式,间阶的赋予用户的权限,如下图所示 对于通常的系统而言,

星之宇的博客 843

AI问数,智慧赋能:基于大语言模型的数据播报员应用实践探索

AI问数技术正在改变企业与数据交互的方式,它以自然语言为桥梁,让数据不再是少数专家的专利,而是成为所有业务人员的决策伙伴。这不仅是技术的创新,更是管理理念的革新。在数字化转型的关键阶段,企业应积极拥抱AI问数技术,通过降低数据使用门槛、提升数据利用效率、释放数据潜在价值,实现真正的数据驱动决策,为企业的高质量发展注入源源不断的智慧动能。AI问数,正在开启一个数据普惠的新时代。

getusushu的博客 64

网络工程师如何利用Python自动Telnet到N个路由器并执行配置?

telnetlib是Python标准库中的一个模块,专门用于实现Telnet协议。通过telnetlib,我们可以方便地与支持Telnet协议的远程设备进行通信。telnetlib提供了基本的Telnet功能,如连接远程主机、发送命令、读取响应等,使得编写Telnet自动化脚本变得非常简单。文档:可以选择中文:虽然telnetlib的功能相对基础,但对于大多数Telnet操作来说已经足够。通过telnetlib,可以轻松地实现与网络设备的交互,完成自动化配置任务。

网络技术联盟站 299

SpringSecurity + JWT 实现登录认证

Component@Override// 1.获取 JWT 令牌if (!// 2.判断 JWT 令牌正确性// 3.获取用户信息,存储 Security 中= null= null) {// 4.创建用户对象null,// 绑定 request 对象。

xaiobit_hl的博客 2654

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

用户登录认证和权限授权(SpringSecurity、JWT、session)

登录认证和权限授权是所有项目中必不可少的功能,本篇文章首先将通过最简单的方式(Session和JWT)实现登录认证和权限授权,然后再整合Springsecurity框架实现。

qq_51076441的博客 1万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

SpringSecurity 与 JWT

记录总结

QQ418579986的博客 3870

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

上一篇: 阿里官方Redis开发规范!
下一篇: 重磅!阿里推出国产开源的jdk!
Java思维导图
博客等级 码龄10年 306粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值