欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解基于Spring Cloud幾行配置完成單點登錄開發(fā)

 更新時間:2018年02月02日 15:23:37   作者:冷冷gg  
這篇文章主要介紹了詳解基于Spring Cloud幾行配置完成單點登錄開發(fā),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

單點登錄概念

單點登錄(Single Sign On),簡稱為 SSO,是目前比較流行的企業(yè)業(yè)務整合的解決方案之一。SSO的定義是在多個應用系統(tǒng)中,用戶只需要登錄一次就可以訪問所有相互信任的應用系統(tǒng)。登錄邏輯如上圖

基于Spring 全家桶的實現(xiàn)

技術選型:

  1. Spring Boot
  2. Spring Cloud
  3. Spring Security oAuth2

客戶端:

maven依賴

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.security.oauth</groupId>
  <artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-jwt</artifactId>
</dependency>

EnableOAuth2Sso 注解

入口類配置@@EnableOAuth2Sso

@SpringBootApplication
public class PigSsoClientDemoApplication {

  public static void main(String[] args) {
    SpringApplication.run(PigSsoClientDemoApplication.class, args);
  }

}

配置文件

security:
 oauth2:
  client:
   client-id: pig
   client-secret: pig
   user-authorization-uri: http://localhost:3000/oauth/authorize
   access-token-uri: http://localhost:3000/oauth/token
   scope: server
  resource:
   jwt:
    key-uri: http://localhost:3000/oauth/token_key
 sessions: never

SSO認證服務器

認證服務器配置

@Configuration
@Order(Integer.MIN_VALUE)
@EnableAuthorizationServer
public class PigAuthorizationConfig extends AuthorizationServerConfigurerAdapter {
  @Override
  public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
        .withClient(authServerConfig.getClientId())
        .secret(authServerConfig.getClientSecret())
        .authorizedGrantTypes(SecurityConstants.REFRESH_TOKEN, SecurityConstants.PASSWORD,SecurityConstants.AUTHORIZATION_CODE)
        .scopes(authServerConfig.getScope());
  }

  @Override
  public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints
        .tokenStore(new RedisTokenStore(redisConnectionFactory))
        .accessTokenConverter(jwtAccessTokenConverter())
        .authenticationManager(authenticationManager)
        .exceptionTranslator(pigWebResponseExceptionTranslator)
        .reuseRefreshTokens(false)
        .userDetailsService(userDetailsService);
  }

  @Override
  public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
    security
        .allowFormAuthenticationForClients()
        .tokenKeyAccess("isAuthenticated()")
        .checkTokenAccess("permitAll()");
  }

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

  @Bean
  public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
    jwtAccessTokenConverter.setSigningKey(CommonConstant.SIGN_KEY);
    return jwtAccessTokenConverter;
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Java中jar包運行后顯示:沒有主清單屬性的解決方案

    Java中jar包運行后顯示:沒有主清單屬性的解決方案

    這篇文章主要介紹了Java中jar包運行后顯示:沒有主清單屬性的解決方案,文中給大家分析了三個主要原因,并通過代碼示例和圖文講解的非常詳細,需要的朋友可以參考下
    2024-04-04
  • sa-token?路由攔截式鑒權使用示例詳解

    sa-token?路由攔截式鑒權使用示例詳解

    這篇文章主要為大家介紹了sa-token?路由攔截式鑒權使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • Maven屬性與版本管理詳細步驟分解

    Maven屬性與版本管理詳細步驟分解

    這篇文章主要介紹了Maven中關于屬性與版本控制管理的步驟操作,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-08-08
  • Spring手動獲取bean的四種方式

    Spring手動獲取bean的四種方式

    本文主要介紹了Spring手動獲取bean的四種方式,包括BeanFactoryPostProcessor接口,ApplicationContextAware接口,注解 @PostConstruct 初始化時獲取,啟動類ApplicationContext獲取這四種方法,感興趣的可以了解一下
    2024-01-01
  • Springboot無法注入service問題

    Springboot無法注入service問題

    這篇文章主要介紹了Springboot無法注入service的問題及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • Java 中的 String對象為什么是不可變的

    Java 中的 String對象為什么是不可變的

    String對象是不可變的,但這僅意味著你無法通過調用它的公有方法來改變它的值。本文給大家介紹java中的string對象為什么是不可變的,需要的朋友一起了解了解吧
    2015-10-10
  • Intellij?IDEA根據(jù)maven依賴名查找它是哪個pom.xml引入的(圖文詳解)

    Intellij?IDEA根據(jù)maven依賴名查找它是哪個pom.xml引入的(圖文詳解)

    這篇文章主要介紹了Intellij?IDEA根據(jù)maven依賴名查找它是哪個pom.xml引入的,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • Java 8中HashMap的底層原理解析

    Java 8中HashMap的底層原理解析

    HashMap作為Java中常用的數(shù)據(jù)結構之一,在JDK 1.8中經(jīng)過了一系列的優(yōu)化和改進,深入理解其底層原理,包括哈希算法、數(shù)組與鏈表結構、紅黑樹的引入等,有助于更好地使用和理解HashMap的性能特性,這篇文章主要介紹了Java 8中HashMap的底層原理,需要的朋友可以參考下
    2023-11-11
  • SpringBoot優(yōu)化啟動速度的方法實現(xiàn)

    SpringBoot優(yōu)化啟動速度的方法實現(xiàn)

    本篇文章主要介紹了SpringBoot優(yōu)化啟動速度的方法實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • ManyToMany單向、雙向:@JoinTable的使用

    ManyToMany單向、雙向:@JoinTable的使用

    這篇文章主要介紹了ManyToMany單向、雙向:@JoinTable的使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12

最新評論