private SecurityScheme apiImplicitScheme() { final List<AuthorizationScope> authorizationScopes = Arrays.stream(Scope.values()) .map(s -> new AuthorizationScope(s.toString(), s.toString())) .collect(Collectors.toList()); final LoginEndpoint loginEndpoint = new LoginEndpoint("/oauth/authorize"); final GrantType grantType = new ImplicitGrant(loginEndpoint, "access_token"); return new OAuth(API_REFERENCE, authorizationScopes, Lists.newArrayList(grantType)); }
private OAuth securitySchema() { ArrayList<AuthorizationScope> authorizationScopeList = new ArrayList<>(); swaggerProperties().getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); ArrayList<GrantType> grantTypes = new ArrayList<>(); swaggerProperties().getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl))); return new OAuth(swaggerProperties().getAuthorization().getName(), authorizationScopeList, grantTypes); }
@Bean public Docket restApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .securitySchemes(asList( new OAuth( "petstore_auth", asList(new AuthorizationScope("write_pets", "modify pets in your account"), new AuthorizationScope("read_pets", "read your pets")), Arrays.<GrantType>asList(new ImplicitGrant(new LoginEndpoint("http://petstore.swagger.io/api/oauth/dialog"), "tokenName")) ), new ApiKey("api_key", "api_key", "header") )) .select() .paths(Predicates.and(ant("/**"), Predicates.not(ant("/error")), Predicates.not(ant("/management/**")), Predicates.not(ant("/management*")))) .build(); }