有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpringfox大摇大摆地使用SSO并调用另一个自定义函数

我已经用SSO在我的广告服务器上创建了我的招摇过市配置,如下所示。当用户单击授权按钮时,他可以导航到相应的位置进行身份验证,并获取id\u令牌,并重定向并将其交给swagger,其中id\u令牌将作为承载令牌在所有API请求头上传递

enter image description here

事情进展顺利,但问题是我需要在所有API请求的头中传递另一个令牌,而不是id_令牌。我有一个名为getApiTokens的自定义函数,它根据作为其输入参数传递的id\u令牌给出另一个令牌。从getApiTokens函数返回的新创建的令牌必须作为载体传递到所有API头上

enter image description here

谁能帮我一下吗

我正在为我的项目使用springfox-Swagger 2

我的大摇大摆。java代码如下所示

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Autowired
    private Configuration config;

    @Bean
    public Docket userApi() {
        final List<ResponseMessage> list = Lists.newArrayList();
        list.add(new ResponseMessageBuilder().code(401).message("Unauthorized").responseModel(new ModelRef("Result"))
                .build());;

        return new Docket(DocumentationType.SWAGGER_2).groupName("omnesys-api").apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.omnesys.api")).paths(PathSelectors.any())
                .build().securitySchemes(newArrayList(oauth())).securityContexts(newArrayList(securityContext()))
                .globalResponseMessage(RequestMethod.GET, list).globalResponseMessage(RequestMethod.POST, list);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("Omnesys API")
                .description("Omnesys API")
                .termsOfServiceUrl("https://omnesys.com/service").contact(contact()).license("Apache License Version 2.0")
                .licenseUrl("https://omnesys.com/service/LICENSE").version("2.0").build();
    }

    private Contact contact() {
        return new Contact("Omnesys", "https://omnesys.com", "admin@omnesys.com");
    }

    @Bean
    SecurityContext securityContext() {
        final AuthorizationScope readScope = new AuthorizationScope("read", "read your admin");
        final AuthorizationScope[] scopes = new AuthorizationScope[1];
        scopes[0] = readScope;
        final SecurityReference securityReference = SecurityReference.builder().reference("omnesys_auth").scopes(scopes)
                .build();
        return SecurityContext.builder().securityReferences(newArrayList(securityReference)).build();
    }

    @Bean
    SecurityScheme oauth() {
        return new OAuthBuilder().name("omnesys_auth").grantTypes(grantTypes()).scopes(scopes()).build();
    }

    List<AuthorizationScope> scopes() {
        final List<AuthorizationScope> scopes = Lists.<AuthorizationScope>newArrayList();
        scopes.add(new AuthorizationScope("resource-access", "Get Resource Access"));
        return scopes;
    }

    List<GrantType> grantTypes() {
        final GrantType grantType = new ImplicitGrantBuilder()
                .loginEndpoint(
                        new LoginEndpoint(config.getSecurity().getOauth2().getClient().getUserAuthorizationUri()))
                .build();
        return newArrayList(grantType);
    }

    @Bean
    public SecurityConfiguration securityInfo() {
        return new SecurityConfiguration("97aaf5ff-b64d-4ec2-a409-b434d7744930", "d3cc95e9-6ed8-448f-a448-1ab02b72967e", "swagger", "swagger", "", ApiKeyVehicle.HEADER, "", " ");
    }
}

共 (0) 个答案