spring-boot swagger2 set global token, the interface description page can not be brought into the token

1, swagger configuration class

// Verify
    private List<ApiKey> securitySchemes() {
        List<ApiKey> apiKeyList = new ArrayList();
        apiKeyList.add(new ApiKey("token", "token", "header"));
        return apiKeyList;
    }

    private List<SecurityContext> securityContexts() {
        List<SecurityContext> securityContexts = new ArrayList<>();
        securityContexts.add(SecurityContext.builder().securityReferences(defaultAuth())
                .forPaths (PathSelectors.regex ( "^ (?! auth). * $")) // filter To verify the path
                .build());
        return securityContexts;
    }

    // set a global certification
    List<SecurityReference> defaultAuth() {
        AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
        authorizationScopes[0] = authorizationScope;
        List<SecurityReference> securityReferences = new ArrayList<>();
        securityReferences.add (new new SecurityReference ( " token ", authorizationScopes)); // Verify increase ( there are many tutorials explain in this place is Authorization, can not lead into the global token, because securitySchemes () method header write token, so this where I read token on it )
        return securityReferences;
    }

    /**
     * Adding summary information
     */
    private ApiInfo apiInfo() {
        // customized with ApiInfoBuilder
        return new ApiInfoBuilder()
                .title ( "Document Interface")
                //. Description ( "Description Interface for use")
                //.contact(new Contact("minhope", null, null))
                . .Version ( "version:" + Global.getSwaggerDescribeVersion ()) build ();
    }

  

  

  

Guess you like

Origin www.cnblogs.com/webttt/p/12016135.html