国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

springboot整合springsecurity+oauth2.0密碼授權(quán)模式

這篇具有很好參考價(jià)值的文章主要介紹了springboot整合springsecurity+oauth2.0密碼授權(quán)模式。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

springboot整合springsecurity+oauth2.0

本文采用的springboot去整合springsecurity,采用oauth2.0授權(quán)認(rèn)證,使用jwt對(duì)token增強(qiáng)。本文僅為學(xué)習(xí)記錄,如有不足多謝提出。

OAuth2 簡(jiǎn)介

OAuth 2.0是用于授權(quán)的行業(yè)標(biāo)準(zhǔn)協(xié)議。OAuth 2.0為簡(jiǎn)化客戶端開發(fā)提供了特定的授權(quán)流,包括Web應(yīng)用、桌面應(yīng)用、移動(dòng)端應(yīng)用等。

OAuth2 相關(guān)名詞解釋

  • Resource owner(資源擁有者):擁有該資源的最終用戶,他有訪問資源的賬號(hào)密碼;
  • Resource server(資源服務(wù)器):擁有受保護(hù)資源的服務(wù)器,如果請(qǐng)求包含正確的訪問令牌,可以訪問資源;
  • Client(客戶端):訪問資源的客戶端,會(huì)使用訪問令牌去獲取資源服務(wù)器的資源,可以是瀏覽器、移動(dòng)設(shè)備或者服務(wù)器;
  • Authorization server(認(rèn)證服務(wù)器):用于認(rèn)證用戶的服務(wù)器,如果客戶端認(rèn)證通過,發(fā)放訪問資源服務(wù)器的令牌。

四種授權(quán)模式

  • Authorization Code(授權(quán)碼模式):正宗的OAuth2的授權(quán)模式,客戶端先將用戶導(dǎo)向認(rèn)證服務(wù)器,登錄后獲取授權(quán)碼,然后進(jìn)行授權(quán),最后根據(jù)授權(quán)碼獲取訪問令牌;
  • Implicit(簡(jiǎn)化模式):和授權(quán)碼模式相比,取消了獲取授權(quán)碼的過程,直接獲取訪問令牌;
  • Resource Owner Password Credentials(密碼模式):客戶端直接向用戶獲取用戶名和密碼,之后向認(rèn)證服務(wù)器獲取訪問令牌;
  • Client Credentials(客戶端模式):客戶端直接通過客戶端認(rèn)證(比如client_id和client_secret)從認(rèn)證服務(wù)器獲取訪問令牌。

主要pom文件引入

<!--        springSecurity-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
<!--        Oauth2-->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.2.6.RELEASE</version>
        </dependency>
        <!--        jwt增強(qiáng)-->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-jwt</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency>
        
 #本文采用的springboot版本為2.6.3,由于Spring Security 在 Spring Boot 2.7.0 中已棄用的 WebSecurityConfigurerAdapter
 所有在配置。所以在配置SpringSecurity配置時(shí),原先configure采用bena配置SecurityFilterChain bean

編寫實(shí)體類

用戶類

package com.example.health.model;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

/**
 * 登錄用戶信息
 */
@Data
public class SecurityUser implements UserDetails {

    /**
     * 用戶id
     */
    private Long userId;
    /**
     * 用戶名
     */
    private String username;
    /**
     * 部門ID
     */
    private Long deptId;
    /**
     * 用戶密碼
     */
    private String password;
    /**
     * 用戶狀態(tài)
     */
    private Boolean enabled;
    /**
     * 權(quán)限數(shù)據(jù)
     */
    private Collection<SimpleGrantedAuthority> authorities;

    /**
     * 權(quán)限列表
     */
    private Set<String> permissions;

    public SecurityUser() {

    }

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

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

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

    /**
     * 賬戶是否未過期,過期無法驗(yàn)證
     */
    @JSONField(serialize = false)
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用戶是否解鎖,鎖定的用戶無法進(jìn)行身份驗(yàn)證
     *
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已過期的用戶的憑據(jù)(密碼),過期的憑據(jù)防止認(rèn)證
     *
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用 ,禁用的用戶不能身份驗(yàn)證
     *
     * @return
     */
    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

}

auth2獲取Token返回信息封裝

package com.example.health.model.dto;

import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Oauth2獲取Token返回信息封裝
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
public class Oauth2TokenDto {
    /**
     * 訪問令牌
     */
    private String token;
    /**
     * 刷新令牌
     */
    private String refreshToken;
    /**
     * 訪問令牌頭前綴
     */
    private String tokenHead;
    /**
     * 有效時(shí)間(秒)
     */
    private int expiresIn;
}

添加UserServiceImpl實(shí)現(xiàn)UserDetailsService接口,用于加載用戶信息:

package com.example.health.security.handle;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.health.common.constant.MessageConstant;
import com.example.health.mapper.SysUserMapper;
import com.example.health.model.SecurityUser;
import com.example.health.model.entity.SysUser;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.Objects;

@Service
public class UserServiceImpl implements UserDetailsService {

    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = sysUserMapper.selectOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserName, username));
        if (Objects.isNull(sysUser)) {
            throw new UsernameNotFoundException(MessageConstant.USERNAME_PASSWORD_ERROR);
        }
        SecurityUser securityUser = new SecurityUser();
        BeanUtils.copyProperties(sysUser, securityUser);
        securityUser.setEnabled(!Objects.equals(0, sysUser.getStatus()));
        return securityUser;
    }
}

添加AuthenticationEntryPointImpl實(shí)現(xiàn)AuthenticationEntryPoint接口,用于處理失敗處理類 :

/**
 * 認(rèn)證失敗處理類 返回未授權(quán)
 *
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable {

    private static final long serialVersionUID = -8970718410437077606L;

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        int code = HttpStatus.UNAUTHORIZED;
        String msg = String.format("請(qǐng)求訪問:%s,認(rèn)證失敗,無法訪問系統(tǒng)資源", request.getRequestURI());
        ServletUtils.renderString(response, JSON.toJSONString(ResultUtils.error(code, msg)));
    }
}

配置JWT內(nèi)容增強(qiáng)器

/**
 * JWT內(nèi)容增強(qiáng)器
 */
@Component
public class JwtTokenEnhancer implements TokenEnhancer {
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        SecurityUser securityUser = (SecurityUser) authentication.getPrincipal();
        Map<String, Object> info = new HashMap<>();
        //把用戶ID設(shè)置到JWT中
        info.put("user_id", securityUser.getUserId());
        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(info);
        return accessToken;
    }
}

添加認(rèn)證服務(wù)器配置,使用@EnableAuthorizationServer注解開啟:


/**
 * 認(rèn)證服務(wù)配置
 */
@AllArgsConstructor
@Configuration
@EnableAuthorizationServer
public class Oauth2Config extends AuthorizationServerConfigurerAdapter {

    private PasswordEncoder passwordEncoder;

    private UserServiceImpl userDetailsService;

    /**
     * 該對(duì)象用來支持 password 模式
     */
    private AuthenticationManager authenticationManager;

    private JwtTokenEnhancer jwtTokenEnhancer;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("client-app")
                .secret(passwordEncoder.encode("123456"))
                .scopes("all")
                .authorizedGrantTypes("password", "refresh_token")
                .accessTokenValiditySeconds(3600)
                .refreshTokenValiditySeconds(86400);
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
        List<TokenEnhancer> delegates = new ArrayList<>();
        delegates.add(jwtTokenEnhancer);
        delegates.add(accessTokenConverter());
        enhancerChain.setTokenEnhancers(delegates); //配置JWT的內(nèi)容增強(qiáng)器
        endpoints.authenticationManager(authenticationManager)
                .userDetailsService(userDetailsService) //配置加載用戶信息的服務(wù)
                .accessTokenConverter(accessTokenConverter())
                .tokenEnhancer(enhancerChain);
    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.allowFormAuthenticationForClients();
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
        jwtAccessTokenConverter.setKeyPair(keyPair());
        return jwtAccessTokenConverter;
    }

    @Bean
    public KeyPair keyPair() {
        //從classpath下的證書中獲取秘鑰對(duì)
        KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "123456".toCharArray());
        return keyStoreKeyFactory.getKeyPair("jwt", "123456".toCharArray());
    }

}

添加SpringSecurity配置,允許認(rèn)證相關(guān)路徑的訪問及表單登錄:

/**
 * SpringSecurity配置
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    /**
     * 認(rèn)證失敗處理類
     */
    @Autowired
    private AuthenticationEntryPointImpl unauthorizedHandler;


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

    /**
     * anyRequest          |   匹配所有請(qǐng)求路徑
     * access              |   SpringEl表達(dá)式結(jié)果為true時(shí)可以訪問
     * anonymous           |   匿名可以訪問
     * denyAll             |   用戶不能訪問
     * fullyAuthenticated  |   用戶完全認(rèn)證可以訪問(非remember-me下自動(dòng)登錄)
     * hasAnyAuthority     |   如果有參數(shù),參數(shù)表示權(quán)限,則其中任何一個(gè)權(quán)限可以訪問
     * hasAnyRole          |   如果有參數(shù),參數(shù)表示角色,則其中任何一個(gè)角色可以訪問
     * hasAuthority        |   如果有參數(shù),參數(shù)表示權(quán)限,則其權(quán)限可以訪問
     * hasIpAddress        |   如果有參數(shù),參數(shù)表示IP地址,如果用戶IP和參數(shù)匹配,則可以訪問
     * hasRole             |   如果有參數(shù),參數(shù)表示角色,則其角色可以訪問
     * permitAll           |   用戶可以任意訪問
     * rememberMe          |   允許通過remember-me登錄的用戶訪問
     * authenticated       |   用戶登錄后可訪問
     */
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {

        httpSecurity
                // CSRF禁用,因?yàn)椴皇褂胹ession
                .csrf().disable()
                // 禁用HTTP響應(yīng)標(biāo)頭
                .headers().cacheControl().disable().and()
                // 認(rèn)證失敗處理類
                .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
                // 基于token,所以不需要session
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                // 過濾請(qǐng)求
                .authorizeRequests()
                // 對(duì)于登錄login 注冊(cè)register 驗(yàn)證碼captchaImage 允許匿名訪問
                .antMatchers("/login", "/register", "/captchaImage").permitAll()
                .antMatchers("/all/**").permitAll()
                // 靜態(tài)資源,可匿名訪問
                .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
                // 除上面外的所有請(qǐng)求全部需要鑒權(quán)認(rèn)證
                .anyRequest().authenticated()
                .and()
                .headers().frameOptions().disable();
    }

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

}

編寫登錄接口,以及測(cè)試接口

/**
 * 自定義Oauth2獲取令牌接口
 */
@RestController
@RequestMapping("/oauth")
public class AuthController {

    @Autowired
    private TokenEndpoint tokenEndpoint;

    /**
     * Oauth2登錄認(rèn)證
     */
    @RequestMapping(value = "/token", method = RequestMethod.POST)
    public BaseResponse<Oauth2TokenDto> postAccessToken(Principal principal, @RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException, HttpRequestMethodNotSupportedException {
        OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
        Oauth2TokenDto oauth2TokenDto = Oauth2TokenDto.builder()
                .token(oAuth2AccessToken.getValue())
                .refreshToken(oAuth2AccessToken.getRefreshToken().getValue())
                .expiresIn(oAuth2AccessToken.getExpiresIn())
                .tokenHead("Bearer ").build();

        return ResultUtils.success(oauth2TokenDto);
    }
}


@RestController
@RequestMapping("/all")
public class AllController {

    @GetMapping(value = "/getStr")
    public BaseResponse<?> getStr() {
        return ResultUtils.success(“All”);
    }

}

@RestController
@RequestMapping("/test")
public class TestController {


    @GetMapping(value = "/getStr")
    public BaseResponse<?> getStr()  {
        return ResultUtils.success("test");
    }
}

測(cè)試使用password授權(quán)方式

springboot整合springsecurity+oauth2.0密碼授權(quán)模式
springboot整合springsecurity+oauth2.0密碼授權(quán)模式
springboot整合springsecurity+oauth2.0密碼授權(quán)模式文章來源地址http://www.zghlxwxcb.cn/news/detail-444896.html

到了這里,關(guān)于springboot整合springsecurity+oauth2.0密碼授權(quán)模式的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • SpringSecurity:OAuth2 Client 結(jié)合GitHub授權(quán)案例(特簡(jiǎn)單版)

    SpringSecurity:OAuth2 Client 結(jié)合GitHub授權(quán)案例(特簡(jiǎn)單版)

    本隨筆說明:這僅作為OAuth2 Client初次使用的案例,所以寫得很簡(jiǎn)單,有許多的不足之處。 OAuth2 Client(OAuth2客戶端)是指使用OAuth2協(xié)議與授權(quán)服務(wù)器進(jìn)行通信并獲取訪問令牌的應(yīng)用程序或服務(wù)。OAuth2客戶端代表最終用戶(資源擁有者)向授權(quán)服務(wù)器請(qǐng)求授權(quán),并使用授權(quán)后的

    2024年02月03日
    瀏覽(22)
  • Spring Security Oauth2.1 最新版 1.1.0 整合 gateway 完成授權(quán)認(rèn)證(擁抱 springboot 3.1)

    Spring Security Oauth2.1 最新版 1.1.0 整合 gateway 完成授權(quán)認(rèn)證(擁抱 springboot 3.1)

    目錄 背景 demo地址 版本 Spring Boot 3.1 Spring Authorization Server 1.1.0 基礎(chǔ) spring security OAuth2 模塊構(gòu)成 授權(quán)方式 認(rèn)證方式 集成過程 官方demo 代碼集成 依賴 授權(quán)服務(wù)AuthorizationServerConfig配置 重要組件 測(cè)試 查看授權(quán)服務(wù)配置 訪問授權(quán)服務(wù) 授權(quán) 回調(diào) 獲取?access_token 獲取用戶信息 個(gè)性

    2024年02月08日
    瀏覽(19)
  • Spring Security Oauth2.1 最新版 1.1.0 整合 (基于 springboot 3.1.0)gateway 完成授權(quán)認(rèn)證

    Spring Security Oauth2.1 最新版 1.1.0 整合 (基于 springboot 3.1.0)gateway 完成授權(quán)認(rèn)證

    目錄 背景 demo地址 版本 Spring Boot 3.1 Spring Authorization Server 1.1.0 基礎(chǔ) spring security OAuth2 模塊構(gòu)成 授權(quán)方式 認(rèn)證方式 集成過程 官方demo 代碼集成 依賴 授權(quán)服務(wù)AuthorizationServerConfig配置 重要組件 測(cè)試 查看授權(quán)服務(wù)配置 訪問授權(quán)服務(wù) 授權(quán) 回調(diào) 獲取?access_token 獲取用戶信息 個(gè)性

    2024年02月11日
    瀏覽(24)
  • Gateway+Springsecurity+OAuth2.0+JWT 實(shí)現(xiàn)分布式統(tǒng)一認(rèn)證授權(quán)!

    Gateway+Springsecurity+OAuth2.0+JWT 實(shí)現(xiàn)分布式統(tǒng)一認(rèn)證授權(quán)!

    目錄 1. OAuth2.0授權(quán)服務(wù) 2. 資源服務(wù) 3. Gateway網(wǎng)關(guān) 4. 測(cè)試 ? 在SpringSecurity+OAuth2.0 搭建認(rèn)證中心和資源服務(wù)中心-CSDN博客??????? 基礎(chǔ)上整合網(wǎng)關(guān)和JWT實(shí)現(xiàn)分布式統(tǒng)一認(rèn)證授權(quán)。 ? 大致流程如下: 1、客戶端發(fā)出請(qǐng)求給網(wǎng)關(guān)獲取令牌 2、網(wǎng)關(guān)收到請(qǐng)求,直接轉(zhuǎn)發(fā)給授權(quán)服務(wù)

    2024年01月24日
    瀏覽(20)
  • Spring Authorization Server 1.1 擴(kuò)展實(shí)現(xiàn) OAuth2 密碼模式與 Spring Cloud 的整合實(shí)戰(zhàn)

    Spring Authorization Server 1.1 擴(kuò)展實(shí)現(xiàn) OAuth2 密碼模式與 Spring Cloud 的整合實(shí)戰(zhàn)

    項(xiàng)目源碼 :youlai-mall 通過 Spring Cloud Gateway 訪問認(rèn)證中心進(jìn)行認(rèn)證并獲取得到訪問令牌。 再根據(jù)訪問令牌 access_token 獲取當(dāng)前登錄的用戶信息。 Spring Security OAuth2 的最終版本是2.5.2,并于2022年6月5日正式宣布停止維護(hù)。Spring 官方為此推出了新的替代產(chǎn)品,即 Spring Authorization

    2024年02月04日
    瀏覽(25)
  • SpringSecurity學(xué)習(xí)(八)OAuth2.0、授權(quán)服務(wù)器、資源服務(wù)器、JWT令牌的使用

    SpringSecurity學(xué)習(xí)(八)OAuth2.0、授權(quán)服務(wù)器、資源服務(wù)器、JWT令牌的使用

    OAuth2是一個(gè)認(rèn)證協(xié)議,SpringSecurity對(duì)OAuth2協(xié)議提供了響應(yīng)的支持,開發(fā)者可以非常方便的使用OAuth2協(xié)議。 簡(jiǎn)介 四種授權(quán)模式 Spring Security OAuth2 GitHub授權(quán)登錄 授權(quán)服務(wù)器與資源服務(wù)器 使用JWT OAuth是一個(gè)開放標(biāo)準(zhǔn),允許用戶讓第三方應(yīng)用訪問該用戶在某一網(wǎng)站上存儲(chǔ)的私密資源

    2024年02月02日
    瀏覽(36)
  • 權(quán)限管理 springboot集成springSecurity Oauth2 JWT

    權(quán)限管理 springboot集成springSecurity Oauth2 JWT

    目錄 一、SpringSeurity的基礎(chǔ)操作 1、引入主要依賴 2、加密器 3、實(shí)現(xiàn)自定義登錄邏輯 4、訪問限制 5、自定義異常處理? 6、通過注解的方式配置訪問控制 二、Auth2認(rèn)證方案 1、什么是Auth2認(rèn)證 2、Oauth2最常用的授權(quán)模式? 3、依賴引入 4、添加配置類 5、測(cè)試 6、存在到Redis里,后續(xù)

    2023年04月14日
    瀏覽(26)
  • Spring Cloud Gateway 整合OAuth2.0 實(shí)現(xiàn)統(tǒng)一認(rèn)證授權(quán)

    Spring Cloud Gateway 整合OAuth2.0 實(shí)現(xiàn)統(tǒng)一認(rèn)證授權(quán) GateWay——向其他服務(wù)傳遞參數(shù)數(shù)據(jù) https://blog.csdn.net/qq_38322527/article/details/126530849 @EnableAuthorizationServer Oauth2ServerConfig 驗(yàn)證簽名 網(wǎng)關(guān)服務(wù)需要RSA的公鑰來驗(yàn)證簽名是否合法,所以認(rèn)證服務(wù)需要有個(gè)接口把公鑰暴露出來 接下來搭建網(wǎng)

    2024年02月13日
    瀏覽(23)
  • SpringCloud整合spring security+ oauth2+Redis實(shí)現(xiàn)認(rèn)證授權(quán)

    SpringCloud整合spring security+ oauth2+Redis實(shí)現(xiàn)認(rèn)證授權(quán)

    在微服務(wù)構(gòu)建中,我們一般用一個(gè)父工程來通知管理依賴的各種版本號(hào)信息。父工程pom文件如下: 在SpringCloud微服務(wù)體系中服務(wù)注冊(cè)中心是一個(gè)必要的存在,通過注冊(cè)中心提供服務(wù)的注冊(cè)和發(fā)現(xiàn)。具體細(xì)節(jié)可以查看我之前的博客,這里不再贅述。我們開始構(gòu)建一個(gè)eureka注冊(cè)中

    2024年02月06日
    瀏覽(25)
  • 電商項(xiàng)目part06 微服務(wù)網(wǎng)關(guān)整合OAuth2.0授權(quán)中心

    電商項(xiàng)目part06 微服務(wù)網(wǎng)關(guān)整合OAuth2.0授權(quán)中心

    網(wǎng)關(guān)整合 OAuth2.0 有兩種思路,一種是授權(quán)服務(wù)器生成令牌, 所有請(qǐng)求統(tǒng)一在網(wǎng)關(guān)層驗(yàn)證,判斷權(quán) 限等操作;另一種是由各資源服務(wù)處理,網(wǎng)關(guān)只做請(qǐng)求轉(zhuǎn)發(fā)。 比較常用的是第一種,把API網(wǎng)關(guān)作 為OAuth2.0的資源服務(wù)器角色,實(shí)現(xiàn)接入客戶端權(quán)限攔截、令牌解析并轉(zhuǎn)發(fā)當(dāng)前登錄

    2024年02月11日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包