<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    #

    Easily Secure your Microservices with Keycloak

    https://www.doag.org/formes/pubfiles/11143470/2019-NN-Sebastien_Blanc-Easily_Secure_your_Microservices_with_Keycloak-Praesentation.pdf

    posted @ 2022-01-03 10:03 paulwong 閱讀(145) | 評論 (0)編輯 收藏

    REDHEAD 7 LINUX 軟件集合

    https://www.softwarecollections.org/en/

    不用再GOOGLE尋找安裝方法。

    安裝MYSQL示例:
    # 2. Install the collection:
    $ sudo yum install rh-mariadb103

    # 3. Start using software collections:
    $ scl enable rh-mariadb103 bash

    $ service rh-mariadb103-mariadb start 
    $ mysql
    $ mysqld

    #開機(jī)加載命令
    cp /opt/rh/rh-mariadb103/enable /etc/profile.d/rh-mariadb103.sh

    posted @ 2021-12-22 14:28 paulwong 閱讀(199) | 評論 (0)編輯 收藏

    OIDC - KEYCLOAK - 自定義CLIENT SCOPE

    當(dāng)CLIENT或用戶在KEYCLOAK中成功登錄后,會返回JWT字符串,其中默認(rèn)含有權(quán)限的信息,但此信息以內(nèi)嵌的方式呈現(xiàn),非常不方便。
    "resource_access": {
        "app-springboot-confidential": {
          "roles": [
            "user"
          ]
        },
        "test-employee-service": {
          "roles": [
            "READ_EMPLOYEE"
          ]
        },
        "service-springboot": {
          "roles": [
            "READ_PRODUCTS"
          ]
        },
        "account": {
          "roles": [
            "manage-account",
            "manage-account-links"
          ]
        },
        "test-department-service": {
          "roles": [
            "READ_DEPARTMENT"
          ]
        }
      }

    • 需要將權(quán)限的信息輸出到一個(gè)KEY中,這時(shí)可以新增自定義CLIENT SCOPE。Mapper中新增KEYCLOAK已內(nèi)置的【realm roles/client roles】,定義輸出到JTW的字段名:my-roles。
    • 授權(quán)哪些CLIENT可以讀取此CLIENT SCOPE.
    • 在登錄參數(shù)scope中,加入此值:my-roles,這樣在輸出的JWT就會以平面的方式輸出所有roles
    "my-roles": [
        "user",
        "READ_EMPLOYEE",
        "READ_PRODUCTS",
        "manage-account",
        "manage-account-links",
        "READ_DEPARTMENT",
        "offline_access",
        "user"
      ]

    • SPRING SECURITY中取出權(quán)限信息:

    @Bean
        public ReactiveJwtAuthenticationConverter jwtAuthenticationConverter(ObjectMapper objectMapper) {
            
            JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
            jwtGrantedAuthoritiesConverter.setAuthorityPrefix("ROLE_");
            jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName("my-roles");
            
    //        KeycloakRealmRoleConverter keycloakRealmRoleConverter = new KeycloakRealmRoleConverter(objectMapper);
            
            ReactiveJwtGrantedAuthoritiesConverterAdapter reactiveJwtGrantedAuthoritiesConverterAdapter = 
                    new ReactiveJwtGrantedAuthoritiesConverterAdapter(
    //                        new KeycloakRealmRoleConverter(objectMapper);
                            jwtGrantedAuthoritiesConverter
                        );
            
            ReactiveJwtAuthenticationConverter jwtConverter = new ReactiveJwtAuthenticationConverter();
            jwtConverter.setJwtGrantedAuthoritiesConverter(reactiveJwtGrantedAuthoritiesConverterAdapter);
            
            return jwtConverter;
        }

    • 判斷是否有權(quán)限

    ServerHttpSecurity
                .authorizeExchange(
                    a -> a.pathMatchers("/", "/error").permitAll()
                          .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
                          .pathMatchers(HttpMethod.GET, "/protected/**").hasRole("READ_DEPARTMENT")
                          .anyExchange()
                          .authenticated()
                 )

    posted @ 2021-12-22 11:15 paulwong 閱讀(755) | 評論 (0)編輯 收藏

    WEBFLUX + SPRING SESSION + REACTIVE MONGODB

    添加依賴,pom.xml

    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
            
            
    <!-- spring session with mongodb -->
    <dependency>
       <groupId>org.springframework.session</groupId>
       <artifactId>spring-session-data-mongodb</artifactId>
    </dependency>
            
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
    </dependency>

    配置文件,application.yaml

    spring:
       session:
          store-type: mongodb
          timeout: 30s
          mongodb:
             collection-name: WEB_SESSIONS


    java配置,HttpSessionConfiguration.java:

    package com.paul.testmicroservicecommon.config;

    import org.springframework.boot.autoconfigure.session.MongoSessionProperties;
    import org.springframework.boot.autoconfigure.session.SessionProperties;
    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    import org.springframework.context.annotation.Bean;
    import org.springframework.session.config.ReactiveSessionRepositoryCustomizer;
    import org.springframework.session.data.mongo.ReactiveMongoSessionRepository;
    import org.springframework.session.data.mongo.config.annotation.web.reactive.EnableMongoWebSession;

    @EnableMongoWebSession
    @EnableConfigurationProperties(MongoSessionProperties.class)
    public class HttpSessionConfiguration {
        
        @Bean
        public ReactiveSessionRepositoryCustomizer<ReactiveMongoSessionRepository> customize(
            SessionProperties sessionProperties,
            MongoSessionProperties mongoSessionProperties
        ){
            return c -> {
                c.setMaxInactiveIntervalInSeconds((int)sessionProperties.getTimeout().getSeconds());
                c.setCollectionName(mongoSessionProperties.getCollectionName());
            };
        }

    }

    posted @ 2021-12-22 09:24 paulwong 閱讀(291) | 評論 (0)編輯 收藏

    OAUTH2 - 4流程




    Authorization Code Grant




    Implicit Grant Flow




    Client Credential





    Password Grant flow





    https://itnext.io/an-oauth-2-0-introduction-for-beginners-6e386b19f7a9

    posted @ 2021-12-16 16:14 paulwong 閱讀(180) | 評論 (0)編輯 收藏

    SPRING CLOUD - REACTIVE FEIGN

    目前SPRING CLOUD(2020)尚未支持REACTIVE FEIGN,但官方推薦使用feign-reactive。

    pom.xml
    <dependency>
        <groupId>com.playtika.reactivefeign</groupId>
        <artifactId>feign-reactor-spring-cloud-starter</artifactId>
        <version>3.1.2</version>
        <type>pom</type>
    </dependency>


    LoanDecisionClientReactive.java
    package com.paul.testspringcloudstream.loancheck.service;

    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestBody;

    import com.paul.testspringcloudstream.common.model.Loan;

    import reactivefeign.spring.config.ReactiveFeignClient;
    import reactor.core.publisher.Mono;

    @ReactiveFeignClient(name = "loan-decision")
    public interface LoanDecisionClientReactive {
        
        @PostMapping("/loan-decision")
        public Mono<Loan> getDecision(@RequestBody Loan loan);

    }

    LoanCheckConfiguration.java
    @Configuration
    @Import({
        MongoDbConsumerConfiguration.class,
    })
    @EnableDiscoveryClient
    @EnableReactiveFeignClients("com.paul.testspringcloudstream.loancheck.service")
    public class LoanCheckConfiguration {
    }


    使用同feign
    @Autowired
    private LoanDecisionClientReactive loanDecisionClientReactive;

    Reference
    https://blog.csdn.net/LCBUSHIHAHA/article/details/113817966

    官方SAMPLE
    https://github.com/kptfh/feign-reactive-sample

    posted @ 2021-12-01 16:45 paulwong 閱讀(586) | 評論 (0)編輯 收藏

    Spring bootstrap.yml 不管用,失效解決方案(spring cloud 2020.x.x)

    升級spring cloud版本之后發(fā)現(xiàn)bootstrap.yml 失效了,閱讀官方文檔得知,需要新增一個(gè)引用來開啟bootstrap.xml文件的讀取,新版spring cloud默認(rèn)是關(guān)閉讀取了。
    增加依賴如下即可:
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
    </dependency>
    官方文檔:
    https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#config-first-bootstrap

    posted @ 2021-12-01 10:29 paulwong 閱讀(679) | 評論 (0)編輯 收藏

    SPRING REACTOR 之Flux和Mono

    SPRING REACTOR 之Flux和Mono,有點(diǎn)象SPRING INTEGRATION的IntegrationFlow,有如下特點(diǎn)
    • 定義了針對某種類型數(shù)據(jù)的處理流程
    • 可以進(jìn)行類型轉(zhuǎn)換
    • 長期運(yùn)行,除非被要求中止
    • 流程中的每種操作可以在新的線程中執(zhí)行
    • 可以正常中止,如果中途有異常,則該流程也會中止
    • 要subscribe,流程才開始被啟動(dòng)
    • 可以分割成各個(gè)子流程
    • 可以聚合子流程
    • Mono發(fā)送一個(gè)數(shù)據(jù),就發(fā)送中止信號
    • Flux發(fā)送任意數(shù)據(jù),由程序決定何時(shí)發(fā)送中止信號

    編程則比較簡單,先根據(jù)不同的數(shù)據(jù)類型定義不同的Flux或Mono,業(yè)務(wù)操作用Function包裝后,放在map/flatmap中,再調(diào)用subscribe啟動(dòng)流程。

    posted @ 2021-11-23 14:30 paulwong 閱讀(612) | 評論 (0)編輯 收藏

    SPRING REACTOR 使用樣例

    SpringReactorTest.java

    package com.paul.testreactivestream.reactor;


    import java.util.List;

    import org.junit.jupiter.api.Test;

    import reactor.core.publisher.Flux;
    import reactor.core.publisher.Mono;
    import reactor.core.scheduler.Schedulers;

    public class SpringReactorTest {
        
        private void subscribeAndEnd(Flux<?> flux) {
            
            flux.map(c -> String.format("[%s] %s", Thread.currentThread().getName(), c))
                .subscribe(System.out::println);
            
            flux.blockLast();
        }
        
        @Test
        public void createAFlux_just() throws InterruptedException {
            Flux<String> fruitFlux = 
                    Flux.just("Apple", "Orange", "Grape", "Banana", "Strawberry")
                        .log()
                        ;
            fruitFlux.subscribe(
                         f -> System.out.println(
                                     String.format("[%s] Here's some fruit: %s", Thread.currentThread().getName(), f)
                                 )
                      )
                     ;
            fruitFlux.blockLast();
            
    //        Thread.currentThread().join();
        }
        
        @Test
        public void zipFluxesToObject() {
            Flux<String> characterFlux = 
                    Flux.just("Garfield", "Kojak", "Barbossa");
            
            Flux<String> foodFlux = 
                    Flux.just("Lasagna", "Lollipops", "Apples");
            
            Flux<String> zippedFlux = 
                    Flux.zip(characterFlux, foodFlux, (c, f) -> c + " eats " + f);
            
            this.subscribeAndEnd(zippedFlux);
        }
        
        @Test
        public void map() {
            Flux<Player> playerFlux = 
                    Flux.just("Michael Jordan", "Scottie Pippen", "Steve Kerr")
                        .map(n -> {
                            String[] split = n.split("\\s");
                            return new Player(split[0], split[1]);
                        })
                        ;
            this.subscribeAndEnd(playerFlux);
        }
        
        @Test
        public void flatMap() {
            Flux<Player> playerFlux = 
                    Flux.just("Michael Jordan", "Scottie Pippen", "Steve Kerr")
                        .flatMap(
                            n -> Mono.just(n)
                                     .map(p -> {
                                        String[] split = p.split("\\s");
                                        return new Player(split[0], split[1]);
                                      })
                                     .subscribeOn(Schedulers.parallel())
                         );
            this.subscribeAndEnd(playerFlux);
        }
        
        @Test
        public void buffer() {
            Flux<List<String>> fruitFlux = 
                    Flux.just(
                            "apple", "orange", "banana", "kiwi", "strawberry"
                         )
                        .buffer(3);
            this.subscribeAndEnd(fruitFlux);
        }
        
        @Test
        public void bufferAsyn() {
            Flux<String> flux =
                Flux.just(
                        "apple", "orange", "banana", "kiwi", "strawberry"
                     )
                    .buffer(3)
                    .flatMap(x ->
                        Flux.fromIterable(x)
                            .map(y -> y.toUpperCase())
                            .subscribeOn(Schedulers.parallel())
        //                    .log()
                     );
            this.subscribeAndEnd(flux);
        }
        
        @Test
        public void all() {
            Mono<Boolean> animalFlux = 
                    Flux.just(
                            "aardvark", "elephant", "koala", "eagle", "kangaroo"
                         )
                        .all(c -> c.contains("a"))
                        ;
            animalFlux.map(c -> String.format("[%s] %s", Thread.currentThread().getName(), c))
                      .subscribe(System.out::println);
        
        }

    }

    posted @ 2021-11-23 13:59 paulwong 閱讀(335) | 評論 (0)編輯 收藏

    SPRING REACTOR資源

    Spring Reactor 入門與實(shí)踐
    https://www.jianshu.com/p/7ee89f70dfe5

    Project Reactor 核心原理解析
    https://www.jianshu.com/p/df395eb28f69

    Project Reactor 之 publishOn 與 subscribeOn
    https://www.jianshu.com/p/769f6e9824fb

    Spring響應(yīng)式編程
    https://blog.csdn.net/get_set/category_7484996.html









    posted @ 2021-11-23 13:51 paulwong 閱讀(113) | 評論 (0)編輯 收藏

    僅列出標(biāo)題
    共115頁: First 上一頁 4 5 6 7 8 9 10 11 12 下一頁 Last 
    主站蜘蛛池模板: 国产精品免费久久久久影院 | 1000部拍拍拍18勿入免费凤凰福利| 无码AV片在线观看免费| 91大神免费观看| 麻豆一区二区免费播放网站| 永久免费视频v片www| 亚洲国产成人久久一区久久| 亚洲免费观看视频| 亚洲伊人久久大香线蕉在观 | 亚洲人成亚洲精品| 一本色道久久综合亚洲精品蜜桃冫 | 亚洲熟伦熟女专区hd高清| 国产精品亚洲专区一区| 中国在线观看免费的www| 91免费国产自产地址入| 国产精品久久免费视频| 亚洲精品字幕在线观看| 亚洲乱码卡三乱码新区| 黄色免费网址在线观看| 国产高清不卡免费视频| 成人免费视频88| 亚洲乱码无码永久不卡在线| 亚洲伊人久久大香线蕉影院| 免费人成在线观看播放a| 免费A级毛片av无码| 国产禁女女网站免费看| 亚洲AV无码专区电影在线观看| 国产精品亚洲自在线播放页码| 窝窝影视午夜看片免费| 91精品国产免费网站| 国产免费拔擦拔擦8x| 亚洲电影中文字幕| 国产亚洲精品免费| 久久久久久夜精品精品免费啦| 国产精品四虎在线观看免费| 久久精品国产亚洲夜色AV网站| 亚洲日韩在线中文字幕综合 | 久久精品亚洲男人的天堂| 亚洲国产高清视频在线观看| 日韩在线一区二区三区免费视频| 最近免费中文字幕高清大全|