SpringSecurity整合OAuth2.0

2023-05-16

SpringSecurity整合OAuth2

  • 一、概述与原理
    • 1.1 、OAuth2.0 是什么?
    • 1.2、OAuth2.0中角色解释
    • 1.3、OAuth2.0的4中授权模式
      • 1.3.1、授权码模式(重点 ⭐⭐⭐)
        • 1.3.1.1 原理
        • 1.3.1.2 代码
      • 1.3.2、密码模式(重点⭐⭐)
        • 1.3.2.1 原理
        • 1.3.2.2 代码
      • 1.3.3、简化模式(了解⭐)
      • 1.3.4、客户端模式(了解⭐)
    • 1.4 、SpringSecurity OAuth2.0 整合JWT(重点⭐⭐⭐)
      • 1.4.1、整合JWT
      • 1.4.2 、JWT内容扩展
      • 1.4.3 、解析JWT
      • 1.4.4、刷新JWT
    • 1.5 分布式单点登陆(⭐⭐⭐)
      • 1.5.1 SpringSecurity+ JWT(Token)+Redis 实现单点登陆流程图
      • 1.5.2 SpringSecurity+ OAuth2.0+JWT(Token) 实现【第三方】单点登陆流程图

一、概述与原理

1.1 、OAuth2.0 是什么?

OAuth(OpenAuthorization)是一个开放标准,允许用户能够让第三方应用访问该用户在某一网站上的存储的私密资源(用户信息、照片、视频、联系人列表、好友列表等),而无需将用户名和密码提供给第三方应用,Oauth仅需要提供一个令牌就可以访问用户存储在特定服务上的资源。
每一个令牌授权一个特定的网站在特定时段内访问特定的资源,OAuth 让用户可以授权第三方网站访问他们存储在另外服务提供者的某些特定信息,而非所有内容。OAuth2.0 为简化客户端开发提供了特定的授权流,包括 Web 应用、桌面应用、移动端应用等。

1.2、OAuth2.0中角色解释

在OAuth2.0的有四个角色需要清楚

Authorization Server认证服务器。用于认证用户,颁发token。如果客户端认证通过,则发放访问资源服务器的令牌
Resource Server资源服务器。拥有受保护资源,对非法请求拦截,对请求token解析。如果请求包含正确的访问令牌,则可以访问资源
Client客户端。它请求资源服务器时,会带上访问令牌,从而成功访问资源
Resource Owner资源拥有者。最终用户,他有访问资源的账号与密码(指的是用户)

1.3、OAuth2.0的4中授权模式

gitee项目源码练习链接:https://gitee.com/hhgs_admin/springsecurityoauth2-demo
项目git log实操内容
在这里插入图片描述

1.3.1、授权码模式(重点 ⭐⭐⭐)

1.3.1.1 原理

授权码模式:指的是当前应用先向第三方认证系统申请一个授权码,然后再用该码在第三方认证系统中获取令牌,之后每次访问系统资源的时候,将该令牌传到第三方认证授权服务器上进行校验,当前应用本身不具备校验令牌有效性的功能。
这种模式多应用在第三方登录, 例如jd,bilibili使用第三方:微信或qq登录

流程示意图:
在这里插入图片描述
(1)、资源拥有者(客户)打开客户端,客户端要求资源拥有者给予授权,它将浏览器被重定向到授权服务器,客户端给第三方认证服务器发送请求认证,例如:

http://localhost:8080/oauth/authorize?client_id=p2pweb&response_type=code&scope=app&
redirect_uri=http://xx.xx/notify

参数列表如下:

参数解释说明
client_id客户端接入标识。
response_type授权码模式固定为code。
scope客户端权限
redirect_uri跳转uri,当授权码申请成功后会跳转到此地址,并在后边带上code参数(授权码)。

(2)、浏览器出现向授权服务器授权页面,之后将用户同意授权。

(3)、授权服务器将授权码(AuthorizationCode)转经浏览器发送给client(通过redirect_uri)。

(4)、客户端拿着授权码向授权服务器索要访问access_token,请求如下:

http://localhost:8080/oauth/token?client_id=p2pweb&client_secret=gdjbcd&grant_type=authorization_code&
code=5PgfcD&redirect_uri=http://xx.xx/notify

参数列表如下:

参数说明
client_id客户端准入标识。
client_secret客户端秘钥。
grant_type授权类型,填写authorization_code,表示授权码模式
code授权码,就是刚刚获取的授权码,注意:授权码只使用一次就无效了,需要重新申请。
redirect_uri申请授权码时的跳转url,一定和申请授权码时用的redirect_uri一致

(5)、授权服务器返回令牌(access_token)
.
授权码模式【第三方登录常用模式】:

这种模式是四种模式中最安全的一种模式。一般用于Web服务器端应用或第三方的原生App调用资源服务的时候。
因为在这种模式中access_token不会经过浏览器或移动端的App,而是直接从服务端去交换,这样就最大限度的减小了令牌泄漏的风险。
授权码模式不足的地方是每次都要网路请求去校验令牌,这可能导致在高并发的情况下造成系统瓶颈,这里优化点在于令牌可以在当前系统进行校验,后续可以采用JWT的方式存储令牌信息。

就拿京东直接第三方微信登录示例京东需要在微信开放平台上注册京东商城信息,填写好回调地址redirect_uri,微信平台会给京东生成appid、appsecret(备案)两个标识,这是在微信后台认证服务中要用到的两个重要唯一的标识

接下来用一张流程图来演示一下授权码模式的流程:例子:京东应用使用第三方微信登录
在这里插入图片描述

1.3.1.2 代码

1,导入依赖

      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-security</artifactId>
      </dependency>
      
      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
       </dependency>
       
     <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR12</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

核心配置文件目录如下:
在这里插入图片描述

2,配置SecurityConfig

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

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

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

3,配置认证服务器:AuthorizationServerConfig

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                //配置client-id
                .withClient("super")
                //配置client-secret
                .secret(passwordEncoder.encode("xxx"))
                //配置访问token的有效期
                .accessTokenValiditySeconds(3600)
                //配置redirect-url,用于授权成功后跳转
                //(实际这里写要访问的资源服务器的地址:例如:http://localhost:8080/login)
                .redirectUris("http://www.baidu.com")
                //配置申请的权限范围
                .scopes("user","order","payment")
                //配置grant_type,表示授权类型
                .authorizedGrantTypes("authorization_code");
    }
}

具体测试在gitee上源码项目和md文档中给出具体的测试流程及截图
.

1.3.2、密码模式(重点⭐⭐)

1.3.2.1 原理

密码模式使用较多,适应于第一方的单页面应用以及第一方的原生App,比如:闪聚支付平台运营平台用户使用此模式完成用户登录。 密码模式认证流程如下:
在这里插入图片描述

(1)资源拥有者将用户名、密码发送给客户端

(2)客户端拿着资源拥有者的用户名、密码向授权服务器请求令牌(access_token),请求如下:

http://localhost:8080/oauth/token?/uaa/oauth/token?client_id=p2pweb&client_secret=fgsdgrf&
grant_type=password&username=shangsan&password=123456

参数列表如下:

参数说明
client_id客户端准入标识。
client_secret客户端秘钥。
grant_type授权类型,填写password表示密码模式
username资源拥有者用户名。
password资源拥有者密码

(3)授权服务器将令牌(access_token)

发送给client 这种模式十分简单,但是却意味着直接将用户敏感信息泄漏给了client,因此这就说明这种模式只能用于client是 我们自己开发的情况下。
因此密码模式一般用于我们自己开发的,第一方原生App或第一方单页面应用。

1.3.2.2 代码

1,配置SecurityConfig

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    
    // 密码模式对比授权码模式,多增加了这个bean
    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

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

2,配置AuthorizationServerConfig

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private UserService userService;
    @Autowired
    private AuthenticationManager authenticationManager;

    /**
     * @description: 使用密码模式所需配置
     * @author liyonghui
     * @date 2021/12/5 14:27
     */
    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager).userDetailsService(userService);
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                //配置client-id
                .withClient("super")
                //配置client-secret
                .secret(passwordEncoder.encode("xxx"))
                //配置访问token的有效期
                .accessTokenValiditySeconds(3600)
                //配置redirect-url,用于授权成功后跳转
                .redirectUris("http://www.baidu.com")
                //配置申请的权限范围
                .scopes("user","order","payment")
                //授权类型-使用密码模式
                .authorizedGrantTypes("password");
    }
}

具体测试在gitee上源码项目和md文档中给出具体的测试流程及截图
.

1.3.3、简化模式(了解⭐)

在这里插入图片描述简化如下:相对于授权码模式,简化了拿授权码这一步操作,直接向授权服务器中拿令牌
在这里插入图片描述
(1)资源拥有者打开客户端,客户端要求资源拥有者给予授权,它将浏览器被重定向到授权服务器,重定向时会附加客户端的身份信息如:

http://localhost:8080/oauth/authorize? client_id=p2pweb&response_type=token&
scope=app&redirect_uri=http://xx.xx/notify

参数列表如下:

参数解释说明
client_id客户端接入标识。
response_type简化模式固定为token。
scope客户端权限。
redirect_uri跳转uri,当授权码申请成功后会跳转到此地址,并在后边带上code参数(授权码)。

参数描述同授权码模式 ,注意response_type=token,说明是简化模式。

(2)浏览器出现向授权服务器授权页面,之后将用户同意授权。

(3)授权服务器将授权码将令牌(access_token)以Hash的形式存放在重定向uri的fargment中发送给浏览器。注:

fragment 主要是用来标识 URI 所标识资源里的某个资源,在 URI 的末尾通过 (#)作为 fragment 的开头, 其中 # 不属于 fragment 的值。如https://domain/index#L18这个 URI 中 L18 就是 fragment 的值。大家只需要 知道js通过响应浏览器地址栏变化的方式能获取到fragment 就行了。
一般来说,简化模式用于第三方单页面应用。

1.3.4、客户端模式(了解⭐)

在这里插入图片描述
(1)客户端向授权服务器发送自己的身份信息,并请求令牌(access_token)

(2)确认客户端身份无误后,将令牌(access_token)发送给client,请求如下:


http://localhost:8080/oauth/token? client_id=p2pweb&client_secret=fgsdgrf&
grant_type=password&username=shangsan&password=123456 

http://localhost:8080/oauth/token?client_id=p2pweb&client_secret=fdafdag&grant_type=client_credentials

参数列表如下:

参数说明
client_id客户端准入标识
client_secret客户端秘钥。
grant_type授权类型,填写client_credentials表示客户端模式

这种模式是最方便但最不安全的模式。
因此这就要求我们对client完全的信任,而client本身也是安全的。
因此这种模式一般用来提供给我们完全信任的服务器端服务。比如,合作方系统对接,拉取一组用户信息。
客户端模式适应于没有用户参与的,完全信任的一方或合作方服务器端程序接入。

1.4 、SpringSecurity OAuth2.0 整合JWT(重点⭐⭐⭐)

gitee项目源码练习链接:https://gitee.com/hhgs_admin/springsecurityoauth2-demo
在这里插入图片描述

1.4.1、整合JWT

了解JWT是干啥的?: https://blog.csdn.net/qq_45399396/article/details/121721822

1,首先了解Oauth2.0中关于JWT配置的两个关键:JwtAccessTokenConverter 、TokenStore

JwtAccessTokenConverter: 帮助程序在JWT编码的令牌值和OAuth身份验证信息之间进行转换,把自己设置的jwt签名(密钥)加入accessTokenConverter中。
TokenStore:访问令牌转换器的令牌存储对象,初始化时,需要转换器将jwt的密钥设置进去

配置JwtTokenStoreConfig

@Configuration
public class JwtTokenStoreConfig {

    @Bean
    public TokenStore jwtTokenStore() {
         //创建带与之有关联的访问令牌转换器的令牌存储
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
        // 配置JWT使用的秘钥
        jwtAccessTokenConverter.setSigningKey("test_key");
        return jwtAccessTokenConverter;
    }
}

配置AuthorizationServerConfig

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private UserService userService;
    
    @Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private TokenStore jwtTokenStore;
    
    @Autowired
    private JwtAccessTokenConverter jwtAccessTokenConverter;

    /**
     * @description: 使用密码模式所需配置
     * @author liyonghui
     * @date 2021/12/5 14:27
     */
    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager).userDetailsService(userService)
                //配置存储令牌策略
                .tokenStore(jwtTokenStore)
                .accessTokenConverter(jwtAccessTokenConverter)
        ;
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                //配置client-id
                .withClient("super")
                //配置client-secret
                .secret(passwordEncoder.encode("xxx"))
                //配置redirect-url,用于授权成功后跳转
                .redirectUris("http://www.baidu.com")
                //配置申请的权限范围
                .scopes("user","order","payment")
                //授权类型-使用密码模式
                .authorizedGrantTypes("password")
        ;
    }
}

具体测试在gitee上源码项目和md文档中给出具体的测试流程及截图
.

1.4.2 、JWT内容扩展

1,TokenEnhancer: JWT的内容扩展接口,实现存储访问令牌之前增强访问令牌的策略。

实现TokenEnhancer接口,设置增强内容

public class JwtTokenEnhancer implements TokenEnhancer {

    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
        Map<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("enhance", "enhance info");
        objectObjectHashMap.put("ceshi", "测试一下!");
        ((DefaultOAuth2AccessToken) oAuth2AccessToken).setAdditionalInformation(objectObjectHashMap);
        return oAuth2AccessToken;
    }
}

配置JwtTokenStoreConfig

@Configuration
public class JwtTokenStoreConfig {

    @Bean
    public TokenStore jwtTokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
        //配置JWT使用的秘钥
        jwtAccessTokenConverter.setSigningKey("test_key");
        return jwtAccessTokenConverter;
    }

    @Bean
    public JwtTokenEnhancer jwtTokenEnhancer() {
         // JWT内容增强
        return new JwtTokenEnhancer();
    }
}

配置AuthorizationServerConfig

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private UserService userService;
    
    @Autowired
    private AuthenticationManager authenticationManager;
   
    @Autowired
    private TokenStore jwtTokenStore;
    
    @Autowired
    private JwtAccessTokenConverter jwtAccessTokenConverter;
    
    @Autowired
    private JwtTokenEnhancer jwtTokenEnhancer;

    /**
     * @description: 使用密码模式所需配置
     * @author liyonghui
     * @date 2021/12/5 14:27
     */
    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
          
        List<TokenEnhancer> delegates = new ArrayList<>();
        delegates.add(jwtTokenEnhancer);
        delegates.add(jwtAccessTokenConverter);

        //配置JWT内容增强
        TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        tokenEnhancerChain.setTokenEnhancers(delegates);

        endpoints.authenticationManager(authenticationManager).userDetailsService(userService)
                //配置存储令牌策略
                .tokenStore(jwtTokenStore)
                .accessTokenConverter(jwtAccessTokenConverter)
                .tokenEnhancer(tokenEnhancerChain) ;
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                //配置client-id
                .withClient("super")
                //配置client-secret
                .secret(passwordEncoder.encode("xxx"))
                //配置redirect-url,用于授权成功后跳转
                .redirectUris("http://www.baidu.com")
                //配置申请的权限范围
                 .scopes("user","order","payment")
                //授权类型-使用密码模式
                .authorizedGrantTypes("password") ;
    }
}

具体测试在gitee上源码项目和md文档中给出具体的测试流程及截图
.

1.4.3 、解析JWT

主要通过Jwts的paese方法,设置密钥,设置token,通过body()方法拿到解析后的主体

@RestController
@RequestMapping("/user")
public class UserController {
    /**
     * @description: 解析JWT
     * @author liyonghui
     * @date 2021/12/5 16:18
     */
    @RequestMapping("getCurrentUser1")
    public Object getCurrentUser1(Authentication authentication, HttpServletRequest request) {
        String head = request.getHeader("Authorization");
        String token = head.replace("bearer" ,"");
          
        return Jwts.parser().setSigningKey("test_key".getBytes(StandardCharsets.UTF_8))
                .parseClaimsJws(token)
                .getBody();
    }
}

具体测试在gitee上源码项目和md文档中给出具体的测试流程及截图
.

1.4.4、刷新JWT

这个配置起来简单,就是授权模式配置中,加入刷新令牌的方式,则可以通过refresh_token再去请求获取新的令牌

 @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                //配置client-id
                .withClient("super")
                //配置client-secret
                .secret(passwordEncoder.encode("xxx"))
                //配置刷新令牌的有效期
                .refreshTokenValiditySeconds(864000)
                //配置redirect-url,用于授权成功后跳转
                .redirectUris("http://localhost:8081/login")
                //自动授权
                .autoApprove(true)
                //配置申请的权限范围
                .scopes("all")
                //授权类型-使用密码模式(添加了刷新令牌 refresh_token)
                .authorizedGrantTypes("password","refresh_token","authorization_code")
        ;
    }

具体测试在gitee上源码项目和md文档中给出具体的测试流程及截图
.

1.5 分布式单点登陆(⭐⭐⭐)

1.5.1 SpringSecurity+ JWT(Token)+Redis 实现单点登陆流程图

在这里插入图片描述

1.5.2 SpringSecurity+ OAuth2.0+JWT(Token) 实现【第三方】单点登陆流程图

应用链接https://blog.csdn.net/qq_45399396/article/details/128284450
基于第三方登录
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SpringSecurity整合OAuth2.0 的相关文章

  • 登录会话超时后,Spring Security重定向到最后请求的页面

    我已经实现了 Spring Security 来登录我的门户网站 除了一个问题之外 它工作正常 我已将会话超时设置为 5 分钟 一旦发生超时 然后用户单击任何 URL 它将被重定向到注销页面 但是当用户重新认证时 用户直接登陆到最后访问的页
  • jasig cas 重定向过多问题

    我正在尝试使用 spring security 和 spring security cas 带有 Jasig CAS 的 SSO 来保护 spring boot Web 应用程序 尝试访问受保护的资源时 我遇到了太多重定向错误 该项目可用h
  • 如何使用 Spring Security 中的新密码编码器

    从 Spring Security 3 1 4 RELEASE 开始 旧的org springframework security authentication encoding PasswordEncoder 已被弃用 https jir
  • 如何优雅地处理Spring Security中未由ControllerAdvice处理的异常?

    我最近在我的 Spring 4 Hibernate Web 应用程序中实现了 Spring Security 来处理登录 注销和不同的用户角色 经过大量阅读后 它现在看起来工作得很好 但我注意到由于错误的 Spring Security 配
  • Spring Security - 多个身份验证提供者

    我的 Web 应用程序有多个身份验证管理器 一个用于 API 一个用于 WEB 访问 api 应该只有一个基本的身份验证服务 通过 spring security 标记进行配置 如下所示
  • Spring Security Saml 和 SP 应用程序的无状态会话

    我尝试运行启动示例 spring security saml boot https github com vdeotaris spring boot security saml sample https github com vdenota
  • @EnableGlobalMethodSecurity 与 @EnableWebSecurity

    我正在使用 Spring 4 开发 REST API 我想使用 Spring Security 来保护一些端点 但根据我所读到的内容 可以使用以下任一方法来完成 EnableGlobalMethodSecurity or EnableWeb
  • Grails - SpringSecurityPlugin 不生成控制器

    我是 Grails 新手 我按照说明安装 SpringSecurityPlugin 版本 2 0 RC2 并执行命令 grails s2 quickstart 用户角色 应该在其他文件中生成 登录控制器 and 注销控制器 但这些控制器不会
  • Spring security 已登录用户的重定向问题

    在使用我的基于 GWT 的 Web 应用程序实现 Spring Security 时 我找到 一切都按预期正常工作 除了以下事实 我打开了 login jsp 并给出了有效的用户登录凭据 提交后 成功重定向到主页 现在 当我在地址栏中编辑
  • Spring MockMvcBuilders 安全过滤器

    我已经设法使用 spring mvc 创建 REST API 我的目的是用 JWToken 保护资源 现在我正在尝试编写三个测试 1 使用授予的用户 密码获取 Token 身份验证失败 gt test OK2 获取未授予用户 密码的Toke
  • 为 Oauth2 Spring Boot 创建自定义 OpenId 提供程序

    我使用 Oauth2 框架进行授权和访问控制 以保护我的 Spring Boot 微服务 api Oauth2 框架工作正常 但现在我的客户需要一个专用的 OpenId 提供程序 用于在 Oauth2 框架之上进行身份验证 我已经在 Goo
  • Grails 弹簧安全/Acegi。自定义用户+密码过期管理

    我正在开发一个 Grails 遗留项目 存在一个名为 User 的域类 它包含密码 用户名 角色等 该项目使用 Spring Security 进行角色管理 我想添加凭据过期 强制用户更新其密码 我修改了 User 类 不是它实现了用户详情
  • 即使 IDP 使用 SAML 成功登录后,获取身份验证对象仍为空

    我已经在我的应用程序中配置了 spring saml 和 spring security 我给出了不同的 url 模式来识别请求 如果我追加 rest在应用程序 URL 中 它将创建具有基本身份验证的 spring security 上下文
  • 在 Spring Boot 测试中的纯二进制 websocket 连接期间保留 TestSecurityContextHolder

    我有一个使用二进制 websocket 的 spring boot 1 5 2 RELEASE 应用程序 即没有 Stomp AMQP 纯二进制缓冲区 在我的测试中 我能够来回发送消息 效果非常好 但是 在对应用程序进行 websocket
  • Grails Spring 安全角色和组

    我已经配置了我的 spring security 来与组一起工作 我使用此脚本来创建域类 grails s2 quickstart com yourapp User Role groupClassName RoleGroup 我假设一个用户
  • Spring Security @PreAuthorize 基于自定义布尔属性值[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我有一个应用程序 用户在其中输入自定义角色名称和权限 例如 用户可以创建一个名为 Human Resources 具有以下属性 sho
  • Spring Boot x509 测试 - pcf

    In 云铸造厂我已对其进行配置 以便将客户端证书转发到我的 Spring Boot 应用程序 该证书被放置在x forwarded client certheader 中 spring boot 应用程序读取 this 并检查 CN 是否已
  • 如何使用 Spring Security 3.0.x 处理 HTTP 403

    我在 Spring Security 3 0 x 特别是目前的 3 0 2 方面遇到了一个小问题 我正在开发的整个应用程序运行完美 除非没有权限的人尝试登录 当发生这种情况时 用户会被重定向到 欢迎 页面 因为他的用户名 密码有效 并且他会
  • 仅验证选定的休息端点:spring boot

    我有一个 Spring Boot Web 应用程序 暴露了一些休息端点 我想知道如何仅为选定的其余端点启用基本身份验证 假设我只想 employee id 请求进行身份验证并忽略所有其他其余端点 我正在使用以下代码 我的问题是antMatc
  • 通过 facebook 登录后设置 spring security 记住我 cookie

    我正在构建一个移动网络应用程序 可以选择通过 facebook twitter 登录 我希望应用程序通过 Spring security 的记住我功能记住登录 以便用户需要经常登录 我有可以调用 facebook 并获取可识别用户身份的 a

随机推荐

  • 蓝桥杯大赛

    第十一届蓝桥杯单片机比赛心得 前期的准备十月份省赛十一月份国赛错过结果发布 想要做一点事情 xff0c 传承 前期的准备 本次蓝桥杯大赛由于疫情原因延迟了将近7个月举行 xff0c 原先是3月份举行 xff0c 拖到了10月份 xff0c
  • 蓝桥杯模块练习之关闭外设

    蓝桥杯单片机比赛系列1初探关闭外设 关闭LED关闭继电器和蜂鸣器 关闭LED 本节将会介绍板子上的最简单最基础的部分 比赛一般上来需要关闭无关外设 xff0c 蓝桥杯的板子比较特殊 xff0c 51上电默认P0 O1 P2 P3都是高电平
  • 蓝桥杯模块练习之温度传感器DS18B20

    蓝桥杯单片机比赛系列4温度传感器DS18B20 温度传感器DS18B20原理相关电路onewire总线几个需要知道的暂存器和命令 代码解释修改代码自写代码 实现代码 温度传感器DS18B20原理 相关电路 DS18B20遵循onewire总
  • 被锡膏坑了一把

    锡膏 61 锡珠 43 助焊剂 把锡膏放大来看如下图 我是去年买的一罐锡膏 xff0c 138度的 xff0c 用了一两次 xff0c 然后就放在哪里没动它 xff0c 盖子也盖好了 xff0c 没有放冰箱 今年又拿出来用 xff0c 用钢
  • 蓝桥杯模块练习之AD/DA

    蓝桥杯单片机比赛系列6AD DA转换 AD DA原理相关电路pcf8591器件地址 代码解释修改代码AD自写代码ADDA AD DA原理 相关电路 通过pcf8591芯片实现ad转换 板子上ad采集主要采集滑动变阻器的电压值和与光敏电阻串联
  • 蓝桥杯模块练习之EEPROM

    蓝桥杯单片机比赛系列7EEPROM EEPROM原理相关电路AT24C02器件地址 EEPROM自写代码 EEPROM原理 相关电路 有了系列6的基础 xff0c 上手eeprom就简单多了 xff0c 板子上对应的器件是AT24C02 A
  • Openmv学习day1——色块识别

    find blobs函数 image find blobs thresholds roi 61 Auto x stride 61 2 y stride 61 1 invert 61 False area threshold 61 10 pi
  • 蓝桥杯嵌入式模块练习之扩展版MEME

    三轴传感器 PA4 7都不能作为其他用处 xff0c 三周传感器需要使用到这四个引脚资源 当然 xff0c 如果不用中断 xff0c 也可以只结PA4 5 xff0c PA6 7可接到温度传感器和温湿度传感器 这个外设的通信协议也是I2C跟
  • Github Pages 搭建网站

    个人站点 访问 https 用户名 gitub io 搭建步骤 1 创建个人站点 gt 新建仓库 xff08 仓库名必须是 用户名 github io xff09 2 在仓库下新建index heml文件即可 3 Github pages仅
  • 普通io口模拟串口通信

    之前公司在做项目的时候需要用到多串口 xff0c 板载串口资源不足 xff0c 就在网上找相关内容 xff0c 结合自己的理解做出虚拟串口 模拟串口需要用到两个普通io引脚 xff0c 一个定时器 软件串口的实现 IO模拟串口 波特率 xf
  • UART,SPI,IIC,RS232通信时序和规则

    一 UART 1 串口通信方式 2 串口通信步骤 注意 xff1a 串口协议规定 xff0c 闲置时必须是高电平 校验位 xff1a 是使用奇偶校验 停止位必须高电平 一个0和多个0区分是靠掐时间 异步通信 xff1a 时钟各不一样 二 I
  • kvaser pcie can 在ros中使用socketcan开发

    kvaser pcie can 在ros中使用socketcan开发 0 系统配置 Ubuntu 16 04 6 LTS Linux version 4 15 0 45 generic 1 官网下载地址 https www kvaser c
  • 算法训练 - 连接字符串 编程将两个字符串连接起来。例如country与side相连接成为countryside。   输入两行,每行一个字符串(只包含小写字母,长度不超过100);输出一行一个字符

    问题描述 编程将两个字符串连接起来 例如country与side相连接成为countryside 输入两行 xff0c 每行一个字符串 xff08 只包含小写字母 xff0c 长度不超过100 xff09 xff1b 输出一行一个字符串 例
  • 笔记 FreeRtos任务创建失败原因

    问题 使用NXP的S32芯片开发 xff0c 环境是S32DS 2018 xff0c 创建了三个任务 xff0c 最后发现只有一个任务在运行 找问题 S32DS自带了Freertos的分析调试工具 xff0c 打开后可以显示任务的状态 xf
  • 3.提升不同专业能力的差别?

    有段时间没写博客了 今天来谈谈最近工作的一些感悟 首先 我觉得工资和个人能力是成正相关的 这应该是是所有人都认同的吧 如果工资是一个函数的话 也可以说 工资 Y 是一个与个人能力 X 有关的一次函数Y aX b 方然我们不能忽略行业之间的差
  • 网络通讯学习(1)---TCP通讯

    TCP IP四层模型 UDP TCP协议 TCP xff08 The Transmission Control Protocol xff09 xff1a 传输控制协议 UDP TCP协议都属于传输层协议 xff0c 都位于IP协议以上 xf
  • 网络通讯学习(3)-----UDP通讯(仅了解)

    理论 UDP xff08 用户数据报协议 xff09 是一个无连接 xff0c 不可靠的数据传输 xff0c 其特点是简单 xff0c 快捷 相比与TCP xff0c UDP不需要建立连接 xff08 不需connect accept函数
  • WIFI模块不支持MQTT协议,可通过MCU实现

    1 话题原因 我们使用某款WIFI模块 xff0c 在物联网开发时 xff0c 平台端的开发者想要使用MQTT协议 xff0c 但是我们当前使用的模块不支持MQTT协议 xff08 好像ESP8266可以通过重新烧录固件的方式支持 xff0
  • (一) 路径规划算法---Astar与C++可视化在RVIZ的三维点云地图

    Astar与C 43 43 可视化在RVIZ的三维点云地图 文章目录 Astar与C 43 43 可视化在RVIZ的三维点云地图1 功能包介绍2 算法功能包的组成与介绍2 1文件系统组成2 2 头文件说明2 3 源文件说明 3 相关坐标系说
  • SpringSecurity整合OAuth2.0

    SpringSecurity整合OAuth2 一 概述与原理1 1 OAuth2 0 是什么 xff1f 1 2 OAuth2 0中角色解释1 3 OAuth2 0的4中授权模式1 3 1 授权码模式 xff08 重点 xff09 1 3