From 33169dbd8c2e167e183de60acbeafc13efccd870 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 17 Aug 2019 01:11:47 +0530 Subject: [PATCH] BAEL-16781 Moving top articles to their respective packages --- .../{config => swagger2}/SwaggerConfig.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) rename oauth-resource-server-2/src/main/java/com/baeldung/{config => swagger2}/SwaggerConfig.java (58%) diff --git a/oauth-resource-server-2/src/main/java/com/baeldung/config/SwaggerConfig.java b/oauth-resource-server-2/src/main/java/com/baeldung/swagger2/SwaggerConfig.java similarity index 58% rename from oauth-resource-server-2/src/main/java/com/baeldung/config/SwaggerConfig.java rename to oauth-resource-server-2/src/main/java/com/baeldung/swagger2/SwaggerConfig.java index 60620e004..822ccdc56 100644 --- a/oauth-resource-server-2/src/main/java/com/baeldung/config/SwaggerConfig.java +++ b/oauth-resource-server-2/src/main/java/com/baeldung/swagger2/SwaggerConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.config; +package com.baeldung.swagger2; import java.util.Arrays; @@ -31,27 +31,50 @@ public class SwaggerConfig { @Bean public Docket api() { - return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build().securitySchemes(Arrays.asList(securityScheme())).securityContexts(Arrays.asList(securityContext())); + return new Docket(DocumentationType.SWAGGER_2).select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() + .securitySchemes(Arrays.asList(securityScheme())) + .securityContexts(Arrays.asList(securityContext())); } @Bean public SecurityConfiguration security() { - return SecurityConfigurationBuilder.builder().clientId(CLIENT_ID).clientSecret(CLIENT_SECRET).useBasicAuthenticationWithAccessCodeGrant(true).build(); + return SecurityConfigurationBuilder.builder() + .clientId(CLIENT_ID) + .clientSecret(CLIENT_SECRET) + .useBasicAuthenticationWithAccessCodeGrant(true) + .build(); } private SecurityScheme securityScheme() { - GrantType grantType = new AuthorizationCodeGrantBuilder().tokenEndpoint(new TokenEndpoint(AUTH_SERVER + "/token", "oauthtoken")).tokenRequestEndpoint(new TokenRequestEndpoint(AUTH_SERVER + "/authorize", CLIENT_ID, CLIENT_ID)).build(); + GrantType grantType = new AuthorizationCodeGrantBuilder() + .tokenEndpoint(new TokenEndpoint(AUTH_SERVER + "/token", "oauthtoken")) + .tokenRequestEndpoint( + new TokenRequestEndpoint(AUTH_SERVER + "/authorize", CLIENT_ID, CLIENT_ID)) + .build(); - SecurityScheme oauth = new OAuthBuilder().name("spring_oauth").grantTypes(Arrays.asList(grantType)).scopes(Arrays.asList(scopes())).build(); + SecurityScheme oauth = new OAuthBuilder().name("spring_oauth") + .grantTypes(Arrays.asList(grantType)) + .scopes(Arrays.asList(scopes())) + .build(); return oauth; } private SecurityContext securityContext() { - return SecurityContext.builder().securityReferences(Arrays.asList(new SecurityReference("spring_oauth", scopes()))).forPaths(PathSelectors.regex("/foos.*")).build(); + return SecurityContext.builder() + .securityReferences( + Arrays.asList(new SecurityReference("spring_oauth", scopes()))) + .forPaths(PathSelectors.regex("/foos.*")) + .build(); } private AuthorizationScope[] scopes() { - AuthorizationScope[] scopes = { new AuthorizationScope("read", "for read operations"), new AuthorizationScope("write", "for write operations"), new AuthorizationScope("foo", "Access foo API") }; + AuthorizationScope[] scopes = { + new AuthorizationScope("read", "for read operations"), + new AuthorizationScope("write", "for write operations"), + new AuthorizationScope("foo", "Access foo API") }; return scopes; } }