Commit 4088cc30 authored by Matija Obreza's avatar Matija Obreza

Updated Swagger

- Using swagger 2.9.2
- Set default.oauthclient.clientId and secret
parent 3b3ca49a
......@@ -96,8 +96,7 @@
<jackson.version>2.6.4</jackson.version>
<jaxb-api.version>2.2.12</jaxb-api.version>
<liquibase.version>3.5.3</liquibase.version>
<!-- TODO Upgrade past 2.7.0 which is buggy -->
<swagger.version>2.6.1</swagger.version>
<swagger.version>2.9.2</swagger.version>
<!--Container -->
<jetty.version>9.4.5.v20170502</jetty.version>
......
......@@ -19,16 +19,20 @@ import static com.google.common.collect.Lists.newArrayList;
import static springfox.documentation.builders.PathSelectors.ant;
import static springfox.documentation.builders.PathSelectors.regex;
import com.google.common.base.Predicate;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.google.common.base.Predicate;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.AuthorizationCodeGrantBuilder;
import springfox.documentation.builders.OAuthBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.ClientCredentialsGrant;
import springfox.documentation.service.Contact;
......@@ -40,6 +44,8 @@ import springfox.documentation.service.TokenRequestEndpoint;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.SecurityConfiguration;
import springfox.documentation.swagger.web.SecurityConfigurationBuilder;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
......@@ -72,7 +78,7 @@ public class SwaggerConfig {
// General info
.apiInfo(apiInfo())
// Security
.securitySchemes(newArrayList(oauthClientCredentials(), oauthAuthorizationCode(), oauthUserPassword())).securityContexts(newArrayList(securityContext()));
.securitySchemes(newArrayList(oauthClientCredentials(), oauthAuthorizationCode(), oauthUserPassword(), apiKey())).securityContexts(newArrayList(securityContext()));
}
private Predicate<String> apiPaths() {
......@@ -81,8 +87,8 @@ public class SwaggerConfig {
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Genesys API").description("This is the description of the API to the Genesys").termsOfServiceUrl(
"https://www.genesys-pgr.org/content/terms-and-conditions").contact(contact()).license("Apache License Version 2.0").licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.version(version).build();
"https://www.genesys-pgr.org/content/terms-and-conditions").contact(contact()).license("Apache License Version 2.0").licenseUrl(
"http://www.apache.org/licenses/LICENSE-2.0").version(version).build();
}
@Bean
......@@ -95,7 +101,6 @@ public class SwaggerConfig {
// return new BasicAuth("login");
// }
@Bean
SecurityScheme oauthAuthorizationCode() {
return new OAuthBuilder().name("Other clients").grantTypes(newArrayList(new AuthorizationCodeGrantBuilder()
// token request
......@@ -106,22 +111,36 @@ public class SwaggerConfig {
.build())).scopes(newArrayList(scopes())).build();
}
@Bean
SecurityScheme oauthClientCredentials() {
return new OAuthBuilder().name("OAuth Client Credentials").grantTypes(newArrayList(new ClientCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(newArrayList(
scopes())).build();
}
@Bean
SecurityScheme oauthUserPassword() {
return new OAuthBuilder().name("Resource Owner").grantTypes(newArrayList(new ResourceOwnerPasswordCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(newArrayList(
scopes())).build();
return new OAuthBuilder().name("Resource Owner").grantTypes(newArrayList(new ResourceOwnerPasswordCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(
newArrayList(scopes())).build();
}
@Bean
SecurityContext securityContext() {
final SecurityReference securityReference = SecurityReference.builder().reference("oauth2").scopes(scopes()).build();
return SecurityContext.builder().securityReferences(newArrayList(securityReference)).forPaths(ant("/api/v0/.*")).build();
return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(ant("/api/v.*")).build();
}
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("read", "write");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Arrays.asList(new SecurityReference("apiKey", authorizationScopes));
}
private ApiKey apiKey() {
return new ApiKey("apiKey", "Authorization", "header");
}
@Bean
public SecurityConfiguration security() {
return SecurityConfigurationBuilder.builder().clientId("defaultclient@localhost").clientSecret("changeme").realm("genesys").appName("Genesys API client").scopeSeparator(
";").additionalQueryStringParams(null).useBasicAuthenticationWithAccessCodeGrant(false).build();
}
AuthorizationScope[] scopes() {
......
......@@ -35,8 +35,8 @@ paginator.api.maxPageSize=1000
# Default account info
default.admin.email=admin@example.com
default.admin.password=Admin123!
default.oauthclient.clientId=
default.oauthclient.clientSecret=
default.oauthclient.clientId=defaultclient@localhost
default.oauthclient.clientSecret=changeme
default.oauth.accessToken.validity=21600
default.oauth.refreshToken.validity=604800
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment