spring swagger ui login oauth2

Solutions on MaxInterview for spring swagger ui login oauth2 by the best coders in the world

showing results for - "spring swagger ui login oauth2"
Jacobo
21 Apr 2016
1@Configuration
2@EnableSwagger2
3public class SpringFoxConfig implements WebMvcConfigurer {
4
5	private String accessTokenUri = "http://localhost:8080/oauth/token";
6
7	@Bean
8	public Docket api() {
9
10		return new Docket(DocumentationType.SWAGGER_2).select()
11				.apis(RequestHandlerSelectors.basePackage("com.gft.desafioapi")).paths(PathSelectors.any()).build()
12				.apiInfo(apiInfo())
13				.tags(new Tag("Fornecedores", "Gerencia os fornecedores"), new Tag("Clientes", "Gerencia os clientes"),
14						new Tag("Produtos", "Gerencia os produtos"), new Tag("Vendas", "Gerencia as vendas"))
15				.securityContexts(Collections.singletonList(securityContext()))
16				.securitySchemes(Arrays.asList(securitySchema()));
17	}
18
19	private OAuth securitySchema() {
20
21		List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
22		authorizationScopeList.add(new AuthorizationScope("read", "read all"));
23
24		List<GrantType> grantTypes = new ArrayList<>();
25		GrantType passwordCredentialsGrant = new ResourceOwnerPasswordCredentialsGrant(accessTokenUri);
26
27		grantTypes.add(passwordCredentialsGrant);
28
29		return new OAuth("oauth2", authorizationScopeList, grantTypes);
30
31	}
32
33	private SecurityContext securityContext() {
34		return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.ant("/api/**"))
35				.build();
36	}
37
38	private List<SecurityReference> defaultAuth() {
39
40		final AuthorizationScope[] authorizationScopes = { new AuthorizationScope("read", "read all") };
41
42		return Collections.singletonList(new SecurityReference("oauth2", authorizationScopes));
43	}
44
45	@Bean
46	public SecurityConfiguration securityInfo() {
47		return new SecurityConfiguration("admin", "admin", "", "", "Bearer access token", ApiKeyVehicle.HEADER,
48				HttpHeaders.AUTHORIZATION, "");
49	}
50
51	public ApiInfo apiInfo() {
52		return new ApiInfoBuilder().title("GFT - Desafio API")
53				.description("API construida para o desafio do programa START GFT").version("1")
54				.contact(new Contact("GFT", "https://www.gft.com", "lucas.pedroso@gft.com")).build();
55	}
56}
similar questions
queries leading to this page
spring swagger ui login oauth2