From 597e4f7a59a99af7e3b674f9b1e23d1c392c9991 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Mon, 22 Jul 2019 15:30:20 +0100 Subject: [PATCH 01/19] Evaluating swagger-ui part of application --- pom.xml | 78 ++++++++ src/main/java/webapp/WEB-INF/web.xml | 3 + src/main/java/webapp/index.html | 10 ++ src/main/java/webapp/openapi.json | 256 +++++++++++++++++++++++++++ 4 files changed, 347 insertions(+) create mode 100644 src/main/java/webapp/WEB-INF/web.xml create mode 100644 src/main/java/webapp/index.html create mode 100644 src/main/java/webapp/openapi.json diff --git a/pom.xml b/pom.xml index 560a63c..b546c88 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,11 @@ springfox-bean-validators 2.8.0 + + org.webjars + swagger-ui + 3.23.0 + @@ -139,4 +144,77 @@ + + + swagger-ui + + + + + maven-dependency-plugin + + + swagger ui + prepare-package + + unpack + + + + + org.webjars + swagger-ui + 3.23.0 + + + ${project.build.directory}/swagger-ui + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + ${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/3.23.0 + + **/*.* + + swagger-ui + + + + + + + com.google.code.maven-replacer-plugin + replacer + 1.5.3 + + + prepare-package + + replace + + + + + ${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/3.23.0/index.html + + + https://petstore.swagger.io/v2/swagger.json + http://localhost:8080/metatdataswaggerui/openapi.json + + + + + + + + + + diff --git a/src/main/java/webapp/WEB-INF/web.xml b/src/main/java/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..bef8421 --- /dev/null +++ b/src/main/java/webapp/WEB-INF/web.xml @@ -0,0 +1,3 @@ + + COOKIE + \ No newline at end of file diff --git a/src/main/java/webapp/index.html b/src/main/java/webapp/index.html new file mode 100644 index 0000000..fe4f3d4 --- /dev/null +++ b/src/main/java/webapp/index.html @@ -0,0 +1,10 @@ + + + +
+

+ Metadata Swagger UI +

+
+ + \ No newline at end of file diff --git a/src/main/java/webapp/openapi.json b/src/main/java/webapp/openapi.json new file mode 100644 index 0000000..1bd3c9a --- /dev/null +++ b/src/main/java/webapp/openapi.json @@ -0,0 +1,256 @@ +{ + "openapi": "3.0.2", + "info": { + "title": "AMP T2D Property registry API", + "description": "Property registry API for the project AMP-T2D", + "version": "1.0SNAPSHOT", + "termsOfService": "www.ebi.ac.uk/terms", + "contact": { + "name": "Property registry API Admin", + "url": "www.ebi.ac.uk", + "email": "prop@gmail.com" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/license/" + } + }, + "servers": [ + { + "url": "https://www.ebi.ac.uk/ega/ampt2d/propertyreg/1.0/", + "description": "Production server" + } + ], + "paths": { + "/phenotypes": { + "get": { + "tags": [ + "Phenotype Entity" + ], + "summary": "find all phenotypes.", + "description": "Get all phenotypes of Type2Diabetes.", + "operationId": "GetPhenotypeEntity", + "parameters": [ + { + "name": "page", + "in": "query", + "description": "Number of pages.", + "schema": { + "type": "string" + } + }, + { + "name": "size", + "in": "query", + "description": "size of page.", + "schema": { + "type": "string" + } + }, + { + "name": "sort", + "in": "query", + "description": "Ascending or descending.", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK, Successful response", + "content": { + "application/json": { + "schema": { + "title": "Model", + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "generated id of phenotype" + }, + "phenotypeGroup": { + "type": "string", + "enum": [ + "ANTHROPOMETRIC", + "CARDIOVASCULAR", + "GLYCEMIC" + ], + "description": "phenotype group" + }, + "description": { + "type": "string", + "description": "description of phenotype" + }, + "type": { + "type": "string", + "enum": [ + "DICHOTOMOUS", + "MULTICHOTOMOUS" + ], + "description": "description of phenotype" + }, + "allowedValues": { + "type": "string", + "description": "allowed values of phenotype" + } + } + } + } + } + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + }, + "404": { + "description": "Not found" + } + } + }, + "post": { + "tags": [ + "Phenotype Entity" + ], + "summary": "save phenotype.", + "description": "Store a phenotype of Type2Diabetes.", + "operationId": "PostPhenotypeEntity", + "requestBody": { + "description": "Store a phenotype of Type2Diabetes.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Phenotype" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "OK, Successful operation", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "links": { + "type": "array", + "items": { + "type": "object", + "properties": { + "href": { + "type": "string" + }, + "rel": { + "type": "string" + }, + "templated": { + "type": "boolean" + } + } + } + }, + "id": { + "type": "string" + }, + "phenotypeGroup": { + "type": "string", + "enum": [ + "ANTHROPOMETRIC", + "CARDIOVASCULAR", + "GLYCEMIC" + ] + }, + "description": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "DICHOTOMOUS", + "MULTICHOTOMOUS" + ] + }, + "allowedValues": { + "type": "string" + } + } + } + } + } + }, + "201": { + "description": "Created" + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + }, + "404": { + "description": "Not found" + } + } + } + } + }, + "components": { + "schemas": { + "Phenotype": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "generated id of phenotype" + }, + "phenotypeGroup": { + "type": "string", + "enum": [ + "ANTHROPOMETRIC", + "CARDIOVASCULAR", + "GLYCEMIC" + ], + "description": "phenotype group" + }, + "description": { + "type": "string", + "description": "description of phenotype" + }, + "type": { + "type": "string", + "enum": [ + "DICHOTOMOUS", + "MULTICHOTOMOUS" + ], + "description": "description of phenotype" + }, + "allowedValues": { + "type": "string", + "description": "allowed values of phenotype" + } + }, + "xml": { + "name": "Phenotype" + } + } + }, + "securitySchemes": { + "keycloak_auth": { + "type": "oauth2", + "flows": { + "authorizationCode": { + "tokenUrl": "http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/token", + "authorizationUrl": "http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/auth", + "scopes": { + "opened": "openid" + } + } + } + } + } + } +} \ No newline at end of file From ba9aa038db58347196ba5d85532d9243540484b2 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Tue, 17 Sep 2019 20:02:05 +0100 Subject: [PATCH 02/19] removing springfox dependancy --- pom.xml | 30 +- .../PropertyRegistryServiceApplication.java | 2 +- .../registry/config/SwaggerConfiguration.java | 3 +- .../config/security/EnableSecurityConfig.java | 2 + .../ampt2d/registry/entities/Phenotype.java | 6 - .../ampt2d/registry/entities/Property.java | 5 - src/main/java/webapp/WEB-INF/web.xml | 3 - src/main/java/webapp/index.html | 10 - src/main/java/webapp/openapi.json | 256 ------------------ src/main/webapp/property.yaml | 115 ++++++++ .../ac/ebi/ampt2d/registry/OAuthHelper.java | 13 +- ...opertyRegistryServiceApplicationTests.java | 4 +- 12 files changed, 131 insertions(+), 318 deletions(-) delete mode 100644 src/main/java/webapp/WEB-INF/web.xml delete mode 100644 src/main/java/webapp/index.html delete mode 100644 src/main/java/webapp/openapi.json create mode 100644 src/main/webapp/property.yaml diff --git a/pom.xml b/pom.xml index b546c88..d60aa93 100644 --- a/pom.xml +++ b/pom.xml @@ -19,13 +19,14 @@ org.springframework.boot spring-boot-starter-parent - 1.5.10.RELEASE + 2.1.8.RELEASE - org.springframework.security.oauth - spring-security-oauth2 + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + 2.1.8.RELEASE org.springframework.boot @@ -84,27 +85,6 @@ spring-boot-starter-tomcat provided - - - io.springfox - springfox-swagger2 - 2.8.0 - - - io.springfox - springfox-swagger-ui - 2.8.0 - - - io.springfox - springfox-data-rest - 2.8.0 - - - io.springfox - springfox-bean-validators - 2.8.0 - org.webjars swagger-ui @@ -206,7 +186,7 @@ https://petstore.swagger.io/v2/swagger.json - http://localhost:8080/metatdataswaggerui/openapi.json + http://localhost:8080/amp-t2d-property-registry-0.1.0/property.yaml diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplication.java b/src/main/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplication.java index 6218e79..0bdf6c4 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplication.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplication.java @@ -20,7 +20,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class PropertyRegistryServiceApplication extends SpringBootServletInitializer { diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java index 79d60fd..2437624 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java @@ -16,7 +16,7 @@ * */ package uk.ac.ebi.ampt2d.registry.config; - +/* import com.fasterxml.classmate.TypeResolver; import com.google.common.base.Predicate; import com.google.common.base.Predicates; @@ -122,3 +122,4 @@ UiConfiguration uiConfig() { } } +*/ \ No newline at end of file diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index 95d267f..811e57a 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -34,6 +34,8 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { private static final String[] AUTH_WHITELIST = { // -- swagger ui + "/**", + "/*", "/v2/api-docs", "/swagger-resources", "/swagger-resources/**", diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Phenotype.java b/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Phenotype.java index 82a81ea..52bfb34 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Phenotype.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Phenotype.java @@ -18,7 +18,6 @@ package uk.ac.ebi.ampt2d.registry.entities; import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.annotations.ApiModelProperty; import org.hibernate.validator.constraints.NotBlank; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -55,7 +54,6 @@ public enum Type { CONTINUOUS } - @ApiModelProperty(position = 1, required = true) @JsonProperty @NotNull @Size(min = 1, max = 255) @@ -63,28 +61,24 @@ public enum Type { @Column(nullable = false, unique = true, updatable = false) private String id; - @ApiModelProperty(position = 2, required = true) @JsonProperty @NotNull @Enumerated(EnumType.STRING) @Column(nullable = false) private Group phenotypeGroup; - @ApiModelProperty(position = 3, required = true) @NotNull @NotBlank @JsonProperty @Column(nullable = false, columnDefinition = "TEXT") private String description; - @ApiModelProperty(position = 4, required = true) @JsonProperty @NotNull @Enumerated(EnumType.STRING) @Column(nullable = false) private Type type; - @ApiModelProperty(position = 5, required = true) @JsonProperty @NotNull @Column(nullable = false) diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Property.java b/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Property.java index 0681180..d5e5986 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Property.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/entities/Property.java @@ -18,7 +18,6 @@ package uk.ac.ebi.ampt2d.registry.entities; import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.annotations.ApiModelProperty; import org.hibernate.validator.constraints.NotBlank; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -68,7 +67,6 @@ public enum Meaning { } - @ApiModelProperty(position = 1) @JsonProperty @NotNull @Size(min = 1, max = 255) @@ -76,21 +74,18 @@ public enum Meaning { @Column(nullable = false, unique = true, updatable = false) private String id; - @ApiModelProperty(position = 2) @JsonProperty @NotNull @Enumerated(EnumType.STRING) @Column(nullable = false) private Type type; - @ApiModelProperty(position = 3) @JsonProperty @NotNull @Enumerated(EnumType.STRING) @Column(nullable = false) private Meaning meaning; - @ApiModelProperty(position = 4) @JsonProperty @NotNull @NotBlank diff --git a/src/main/java/webapp/WEB-INF/web.xml b/src/main/java/webapp/WEB-INF/web.xml deleted file mode 100644 index bef8421..0000000 --- a/src/main/java/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,3 +0,0 @@ - - COOKIE - \ No newline at end of file diff --git a/src/main/java/webapp/index.html b/src/main/java/webapp/index.html deleted file mode 100644 index fe4f3d4..0000000 --- a/src/main/java/webapp/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - -
-

- Metadata Swagger UI -

-
- - \ No newline at end of file diff --git a/src/main/java/webapp/openapi.json b/src/main/java/webapp/openapi.json deleted file mode 100644 index 1bd3c9a..0000000 --- a/src/main/java/webapp/openapi.json +++ /dev/null @@ -1,256 +0,0 @@ -{ - "openapi": "3.0.2", - "info": { - "title": "AMP T2D Property registry API", - "description": "Property registry API for the project AMP-T2D", - "version": "1.0SNAPSHOT", - "termsOfService": "www.ebi.ac.uk/terms", - "contact": { - "name": "Property registry API Admin", - "url": "www.ebi.ac.uk", - "email": "prop@gmail.com" - }, - "license": { - "name": "Apache 2.0", - "url": "https://www.apache.org/license/" - } - }, - "servers": [ - { - "url": "https://www.ebi.ac.uk/ega/ampt2d/propertyreg/1.0/", - "description": "Production server" - } - ], - "paths": { - "/phenotypes": { - "get": { - "tags": [ - "Phenotype Entity" - ], - "summary": "find all phenotypes.", - "description": "Get all phenotypes of Type2Diabetes.", - "operationId": "GetPhenotypeEntity", - "parameters": [ - { - "name": "page", - "in": "query", - "description": "Number of pages.", - "schema": { - "type": "string" - } - }, - { - "name": "size", - "in": "query", - "description": "size of page.", - "schema": { - "type": "string" - } - }, - { - "name": "sort", - "in": "query", - "description": "Ascending or descending.", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK, Successful response", - "content": { - "application/json": { - "schema": { - "title": "Model", - "type": "object", - "properties": { - "id": { - "type": "string", - "description": "generated id of phenotype" - }, - "phenotypeGroup": { - "type": "string", - "enum": [ - "ANTHROPOMETRIC", - "CARDIOVASCULAR", - "GLYCEMIC" - ], - "description": "phenotype group" - }, - "description": { - "type": "string", - "description": "description of phenotype" - }, - "type": { - "type": "string", - "enum": [ - "DICHOTOMOUS", - "MULTICHOTOMOUS" - ], - "description": "description of phenotype" - }, - "allowedValues": { - "type": "string", - "description": "allowed values of phenotype" - } - } - } - } - } - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not found" - } - } - }, - "post": { - "tags": [ - "Phenotype Entity" - ], - "summary": "save phenotype.", - "description": "Store a phenotype of Type2Diabetes.", - "operationId": "PostPhenotypeEntity", - "requestBody": { - "description": "Store a phenotype of Type2Diabetes.", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Phenotype" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "OK, Successful operation", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "links": { - "type": "array", - "items": { - "type": "object", - "properties": { - "href": { - "type": "string" - }, - "rel": { - "type": "string" - }, - "templated": { - "type": "boolean" - } - } - } - }, - "id": { - "type": "string" - }, - "phenotypeGroup": { - "type": "string", - "enum": [ - "ANTHROPOMETRIC", - "CARDIOVASCULAR", - "GLYCEMIC" - ] - }, - "description": { - "type": "string" - }, - "type": { - "type": "string", - "enum": [ - "DICHOTOMOUS", - "MULTICHOTOMOUS" - ] - }, - "allowedValues": { - "type": "string" - } - } - } - } - } - }, - "201": { - "description": "Created" - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not found" - } - } - } - } - }, - "components": { - "schemas": { - "Phenotype": { - "type": "object", - "properties": { - "id": { - "type": "string", - "description": "generated id of phenotype" - }, - "phenotypeGroup": { - "type": "string", - "enum": [ - "ANTHROPOMETRIC", - "CARDIOVASCULAR", - "GLYCEMIC" - ], - "description": "phenotype group" - }, - "description": { - "type": "string", - "description": "description of phenotype" - }, - "type": { - "type": "string", - "enum": [ - "DICHOTOMOUS", - "MULTICHOTOMOUS" - ], - "description": "description of phenotype" - }, - "allowedValues": { - "type": "string", - "description": "allowed values of phenotype" - } - }, - "xml": { - "name": "Phenotype" - } - } - }, - "securitySchemes": { - "keycloak_auth": { - "type": "oauth2", - "flows": { - "authorizationCode": { - "tokenUrl": "http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/token", - "authorizationUrl": "http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/auth", - "scopes": { - "opened": "openid" - } - } - } - } - } - } -} \ No newline at end of file diff --git a/src/main/webapp/property.yaml b/src/main/webapp/property.yaml new file mode 100644 index 0000000..980bf9f --- /dev/null +++ b/src/main/webapp/property.yaml @@ -0,0 +1,115 @@ +openapi: "3.0.2" +info: + title: "AMP T2D Property registry API" + description: "Property registry API for the project AMP-T2D" + version: "1.0SNAPSHOT" + termsOfService: "www.ebi.ac.uk/terms" + contact: + name: "Property registry API Admin" + url: "www.ebi.ac.uk" + email: "prop@gmail.com" + license: + name: "Apache 2.0" + url: "https://www.apache.org/license/" +servers: + - url: http://localhost:8080/amp-t2d-property-registry-0.1.0/ + description: Production server +paths: + /phenotypes: + get: + tags: + - Phenotype Entity + summary: "find all phenotypes." + description: "Get all phenotypes of Type2Diabetes." + operationId: GetPhenotypeEntity + parameters: + - name: page + in: query + description: "Number of pages." + schema: + type: string + - name: size + in: query + description: "size of page." + schema: + type: string + - name: sort + in: query + description: "Ascending or descending." + schema: + type: string + responses: + 200: + description: OK, Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/Phenotype' + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not found + post: + tags: + - Phenotype Entity + summary: "save phenotype." + description: "Store a phenotype of Type2Diabetes." + operationId: PostPhenotypeEntity + requestBody: + description: Store a phenotype of Type2Diabetes. + content: + 'application/json': + schema: + $ref: '#/components/schemas/Phenotype' + required: true + responses: + 200: + description: OK, Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/Phenotype' + 201: + description: Created + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not found + +components: + schemas: + Phenotype: + type: object + properties: + id: + type: string + description: generated phid of phenotype + phenotypeGroup: + type: string + enum: [ANTHROPOMETRIC,CARDIOVASCULAR,GLYCEMIC] + description: phenotype group + description: + type: string + description: description of phenotype + type: + type: string + enum: [DICHOTOMOUS, MULTICHOTOMOUS] + description: description of phenotype + allowedValues: + type: string + description: allowed values of phenotype + xml: + name: Phenotype + securitySchemes: + keycloak_auth: + type: oauth2 + flows: + authorizationCode: + tokenUrl: http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/token + authorizationUrl: http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/auth + scopes: + opened: openid diff --git a/src/test/java/uk/ac/ebi/ampt2d/registry/OAuthHelper.java b/src/test/java/uk/ac/ebi/ampt2d/registry/OAuthHelper.java index 7cf2f31..d8e3114 100644 --- a/src/test/java/uk/ac/ebi/ampt2d/registry/OAuthHelper.java +++ b/src/test/java/uk/ac/ebi/ampt2d/registry/OAuthHelper.java @@ -18,8 +18,8 @@ package uk.ac.ebi.ampt2d.registry; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor; -import org.springframework.context.annotation.Bean; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.User; @@ -34,8 +34,6 @@ import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; import org.springframework.stereotype.Component; import org.springframework.test.web.servlet.request.RequestPostProcessor; -import uk.ac.ebi.ampt2d.registry.config.security.CustomAuthoritiesExtractor; -import uk.ac.ebi.ampt2d.registry.repositories.RegistryUserRepository; import java.io.Serializable; import java.util.Collection; @@ -46,6 +44,7 @@ @Component @EnableAuthorizationServer +@ConditionalOnProperty(name = "security.enabled", havingValue = "true") public class OAuthHelper extends AuthorizationServerConfigurerAdapter { @Autowired @@ -55,7 +54,7 @@ public class OAuthHelper extends AuthorizationServerConfigurerAdapter { private ClientDetailsService clientDetailsService; @Autowired - private RegistryUserRepository registryUserRepository; + private AuthoritiesExtractor authoritiesExtractor; public RequestPostProcessor bearerToken(final String clientid) { return mockRequest -> { @@ -69,7 +68,7 @@ private OAuth2AccessToken createAccessToken(final String clientId) { ClientDetails client = clientDetailsService.loadClientByClientId(clientId); Map clientEmailMap = new HashMap<>(); clientEmailMap.put("email", clientId); - Collection authorities = authoritiesExtractor(registryUserRepository).extractAuthorities(clientEmailMap); + Collection authorities = authoritiesExtractor.extractAuthorities(clientEmailMap); Set resourceIds = client.getResourceIds(); Set scopes = client.getScope(); @@ -98,8 +97,4 @@ public void configure(final ClientDetailsServiceConfigurer clients) throws Excep .withClient("testAdmin@gmail.com"); } - @Bean - public AuthoritiesExtractor authoritiesExtractor(RegistryUserRepository registryUserRepository) { - return new CustomAuthoritiesExtractor(registryUserRepository); - } } \ No newline at end of file diff --git a/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java b/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java index 8808130..b17efa4 100644 --- a/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java +++ b/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java @@ -268,7 +268,7 @@ public void testPaging() throws Exception { .andExpect(jsonPath("$._embedded.properties.length()").value(2)); } - +/* @Test public void testAuthorization() throws Exception { // Any url other than root and swagger is Secured @@ -333,5 +333,5 @@ public void testAuthorization() throws Exception { mockMvc.perform(post("/properties").with(oAuthHelper.bearerToken("testUser@gmail.com")) .content(propertyContent)).andExpect(status().isCreated()); } - +*/ } From 0fa0b83ad6c9e0a2e9db9667135f74cef06779e6 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Thu, 26 Sep 2019 10:07:35 +0100 Subject: [PATCH 03/19] Enable swagger and moving spring boot v2.x --- pom.xml | 2 +- .../registry/config/security/EnableSecurityConfig.java | 6 ++++-- src/main/resources/application.properties | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index d60aa93..5ceceb7 100644 --- a/pom.xml +++ b/pom.xml @@ -186,7 +186,7 @@ https://petstore.swagger.io/v2/swagger.json - http://localhost:8080/amp-t2d-property-registry-0.1.0/property.yaml + http://ves-hx-e9.ebi.ac.uk:8080/amp-t2d-property-registry-0.1.0/property.yaml diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index 811e57a..5535ec2 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -34,8 +34,9 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { private static final String[] AUTH_WHITELIST = { // -- swagger ui - "/**", - "/*", + "/swagger-ui/", + "/swagger-ui/index.html", + "/property.yaml", "/v2/api-docs", "/swagger-resources", "/swagger-resources/**", @@ -49,6 +50,7 @@ public void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(AUTH_WHITELIST).permitAll() .antMatchers("/users/**").hasRole("ADMIN") + .antMatchers(HttpMethod.GET).permitAll() .antMatchers(HttpMethod.POST).hasAnyRole("EDITOR", "ADMIN") .antMatchers(HttpMethod.PUT).hasAnyRole("EDITOR", "ADMIN") .antMatchers(HttpMethod.PATCH).hasAnyRole("EDITOR", "ADMIN") diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8494936..27e60b4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -19,7 +19,6 @@ spring.jpa.generate-ddl=true security.enabled=true security.oauth2.resource.userInfoUri=https://www.googleapis.com/userinfo/v2/me -security.oauth2.resource.filter-order=3 spring.mail.host=@smtp-host@ spring.mail.port=587 From e0ee6e9301ed525d9aeaa0922f14377dc50b81a9 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Thu, 26 Sep 2019 15:59:25 +0100 Subject: [PATCH 04/19] path to staging machine --- pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5ceceb7..a2d899d 100644 --- a/pom.xml +++ b/pom.xml @@ -127,6 +127,9 @@ swagger-ui + + true + @@ -186,7 +189,7 @@ https://petstore.swagger.io/v2/swagger.json - http://ves-hx-e9.ebi.ac.uk:8080/amp-t2d-property-registry-0.1.0/property.yaml + http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/property.yaml From 57efe956966960c48fb574f5e681cc34f2a05c82 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Thu, 26 Sep 2019 17:23:08 +0100 Subject: [PATCH 05/19] removing swagger/springfox dependant tests --- .../registry/config/SwaggerConfiguration.java | 125 ------------------ .../config/security/EnableSecurityConfig.java | 1 - src/main/webapp/property.yaml | 6 +- ...opertyRegistryServiceApplicationTests.java | 8 +- 4 files changed, 5 insertions(+), 135 deletions(-) delete mode 100644 src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java deleted file mode 100644 index 2437624..0000000 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/SwaggerConfiguration.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * Copyright 2018 EMBL - European Bioinformatics Institute - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package uk.ac.ebi.ampt2d.registry.config; -/* -import com.fasterxml.classmate.TypeResolver; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.http.ResponseEntity; -import org.springframework.web.context.request.async.DeferredResult; -import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.schema.AlternateTypeRule; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.ApiKey; -import springfox.documentation.service.AuthorizationScope; -import springfox.documentation.service.Contact; -import springfox.documentation.service.SecurityReference; -import springfox.documentation.service.Tag; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spi.service.contexts.SecurityContext; -import springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger.web.UiConfiguration; -import springfox.documentation.swagger.web.UiConfigurationBuilder; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -import java.lang.reflect.WildcardType; -import java.util.Arrays; - -import static springfox.documentation.schema.AlternateTypeRules.newRule; - -@Configuration -@EnableSwagger2 -@Import({SpringDataRestConfiguration.class, BeanValidatorPluginsConfiguration.class}) -public class SwaggerConfiguration { - - @Autowired - private TypeResolver typeResolver; - - private SecurityReference securityReference = SecurityReference.builder() - .reference("Authorization").scopes(new AuthorizationScope[0]).build(); - - private SecurityContext securityContext = SecurityContext.builder() - .securityReferences(Arrays.asList(securityReference)).build(); - - @Bean - public Docket propertyRegistryApi() { - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.any()) - .paths(getScanRestServicesPathPredicate()) - .build() - .apiInfo(getApiInfo()) - .pathMapping("/") - .tags( - new Tag("Property Entity", "Property definition"), - new Tag("Phenotype Entity", "Phenotype definition") - ) - .genericModelSubstitutes(ResponseEntity.class) - .securitySchemes(Arrays.asList(new ApiKey("Authorization", "Authorization", "header"))) - .securityContexts(Arrays.asList(securityContext)) - .alternateTypeRules(getSubstitutionRules()); - - } - - private Predicate getScanRestServicesPathPredicate() { - return Predicates.and( - Predicates.not(PathSelectors.regex("/actuator.*")), // Hide spring-actuator - Predicates.not(PathSelectors.regex("/error.*")), // Hide spring-data error - Predicates.not(PathSelectors.regex("/profile.*")),// Hide spring-data profile - Predicates.not(PathSelectors.regex("/users.*")) // Hide user-profile - ); - } - - private ApiInfo getApiInfo() { - return new ApiInfoBuilder() - .contact(new Contact("Europe Phenome Genome Archive - EMBL-EBI", "https://www.ebi.ac.uk/ega/", null)) - .license("Apache 2.0") - .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0") - .termsOfServiceUrl(null) - .title("AMP T2D Property registry API") - .description("Property registry API for the project AMP-T2D") - .version("1.0") - .build(); - } - - private AlternateTypeRule getSubstitutionRules() { - return newRule(typeResolver.resolve(DeferredResult.class, - typeResolver.resolve(ResponseEntity.class, WildcardType.class)), - typeResolver.resolve(WildcardType.class)); - } - - @Bean - UiConfiguration uiConfig() { - return UiConfigurationBuilder.builder() - .deepLinking(true) - .displayRequestDuration(true) - .filter(false) - .validatorUrl("") - .build(); - } - -} -*/ \ No newline at end of file diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index 5535ec2..09ca75a 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -50,7 +50,6 @@ public void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(AUTH_WHITELIST).permitAll() .antMatchers("/users/**").hasRole("ADMIN") - .antMatchers(HttpMethod.GET).permitAll() .antMatchers(HttpMethod.POST).hasAnyRole("EDITOR", "ADMIN") .antMatchers(HttpMethod.PUT).hasAnyRole("EDITOR", "ADMIN") .antMatchers(HttpMethod.PATCH).hasAnyRole("EDITOR", "ADMIN") diff --git a/src/main/webapp/property.yaml b/src/main/webapp/property.yaml index 980bf9f..91b08d3 100644 --- a/src/main/webapp/property.yaml +++ b/src/main/webapp/property.yaml @@ -12,7 +12,7 @@ info: name: "Apache 2.0" url: "https://www.apache.org/license/" servers: - - url: http://localhost:8080/amp-t2d-property-registry-0.1.0/ + - url: http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/ description: Production server paths: /phenotypes: @@ -109,7 +109,7 @@ components: type: oauth2 flows: authorizationCode: - tokenUrl: http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/token - authorizationUrl: http://localhost:8080/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/auth + tokenUrl: http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/token + authorizationUrl: http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/auth scopes: opened: openid diff --git a/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java b/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java index b17efa4..8ab5fd4 100644 --- a/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java +++ b/src/test/java/uk/ac/ebi/ampt2d/registry/PropertyRegistryServiceApplicationTests.java @@ -268,7 +268,7 @@ public void testPaging() throws Exception { .andExpect(jsonPath("$._embedded.properties.length()").value(2)); } -/* + @Test public void testAuthorization() throws Exception { // Any url other than root and swagger is Secured @@ -277,10 +277,6 @@ public void testAuthorization() throws Exception { // AUTH_WHITELIST URLs not secured mockMvc.perform(get("/")).andExpect(status().isOk()); - mockMvc.perform(get("/swagger-ui.html")).andExpect(status().isOk()); - mockMvc.perform(get("/v2/api-docs")).andExpect(status().isOk()); - mockMvc.perform(get("/swagger-resources/")).andExpect(status().isOk()); - mockMvc.perform(get("/webjars/springfox-swagger-ui/fonts/open-sans-v15-latin-regular.woff2")).andExpect(status().isOk()); Property property = new Property("CALL_RATE", Property.Type.DOUBLE, Property.Meaning.CALL_RATE, "calling rate"); Phenotype phenotype1 = new Phenotype("BMI", Phenotype.Group.ANTHROPOMETRIC, "Body Mass Index", @@ -333,5 +329,5 @@ public void testAuthorization() throws Exception { mockMvc.perform(post("/properties").with(oAuthHelper.bearerToken("testUser@gmail.com")) .content(propertyContent)).andExpect(status().isCreated()); } -*/ + } From c080964931559666a28ade5499a98f22f55c0402 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Thu, 26 Sep 2019 22:22:37 +0100 Subject: [PATCH 06/19] verifying with GET all --- .../ampt2d/registry/config/security/EnableSecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index 09ca75a..f83ca11 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -49,6 +49,7 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { public void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(AUTH_WHITELIST).permitAll() + .antMatchers(HttpMethod.GET).permitAll() .antMatchers("/users/**").hasRole("ADMIN") .antMatchers(HttpMethod.POST).hasAnyRole("EDITOR", "ADMIN") .antMatchers(HttpMethod.PUT).hasAnyRole("EDITOR", "ADMIN") From 511d941a8229e7eafa7b45f3b5d93d4178dd900b Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Fri, 27 Sep 2019 13:05:28 +0100 Subject: [PATCH 07/19] removing spring fox links --- .../registry/config/security/EnableSecurityConfig.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index f83ca11..ccf58cd 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -37,11 +37,6 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { "/swagger-ui/", "/swagger-ui/index.html", "/property.yaml", - "/v2/api-docs", - "/swagger-resources", - "/swagger-resources/**", - "/swagger-ui.html", - "/webjars/**", "/" }; @@ -49,7 +44,6 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { public void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(AUTH_WHITELIST).permitAll() - .antMatchers(HttpMethod.GET).permitAll() .antMatchers("/users/**").hasRole("ADMIN") .antMatchers(HttpMethod.POST).hasAnyRole("EDITOR", "ADMIN") .antMatchers(HttpMethod.PUT).hasAnyRole("EDITOR", "ADMIN") From 2019e20ab9aac3dc6ed57efa4427ad3b7e5183a0 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Fri, 27 Sep 2019 13:21:19 +0100 Subject: [PATCH 08/19] verifying with logs enabled --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 27e60b4..42b6d2c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -30,4 +30,5 @@ mail.from=@amp-t2d-email-id@ mail.to=@amp-t2d-email-id@ mail.subject=AMP-T2D Registry Update -registry.protocols=https \ No newline at end of file +registry.protocols=https +logging.level.org.springframework.security=DEBUG From 5ff402b4756f7b21bd0e4338daaa842dddb162ea Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Fri, 27 Sep 2019 13:37:13 +0100 Subject: [PATCH 09/19] adding permission to starting /swagger-ui to all --- .../ampt2d/registry/config/security/EnableSecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index ccf58cd..cd592d3 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -35,6 +35,7 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { private static final String[] AUTH_WHITELIST = { // -- swagger ui "/swagger-ui/", + "/swagger-ui/**", "/swagger-ui/index.html", "/property.yaml", "/" From f79e6d6f5d7c594d2590dede1d721ce86fa0266b Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Fri, 27 Sep 2019 14:24:46 +0100 Subject: [PATCH 10/19] removing debug entry --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 42b6d2c..8494936 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -19,6 +19,7 @@ spring.jpa.generate-ddl=true security.enabled=true security.oauth2.resource.userInfoUri=https://www.googleapis.com/userinfo/v2/me +security.oauth2.resource.filter-order=3 spring.mail.host=@smtp-host@ spring.mail.port=587 @@ -30,5 +31,4 @@ mail.from=@amp-t2d-email-id@ mail.to=@amp-t2d-email-id@ mail.subject=AMP-T2D Registry Update -registry.protocols=https -logging.level.org.springframework.security=DEBUG +registry.protocols=https \ No newline at end of file From 8d2574c998749ab92d35b36c4c63ef648a3437bd Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Mon, 30 Sep 2019 14:14:40 +0100 Subject: [PATCH 11/19] adding bearer security --- src/main/webapp/property.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/webapp/property.yaml b/src/main/webapp/property.yaml index 91b08d3..2d70464 100644 --- a/src/main/webapp/property.yaml +++ b/src/main/webapp/property.yaml @@ -105,11 +105,6 @@ components: xml: name: Phenotype securitySchemes: - keycloak_auth: - type: oauth2 - flows: - authorizationCode: - tokenUrl: http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/token - authorizationUrl: http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/ega/ampt2d/auth/realms/securemetadata/protocol/openid-connect/auth - scopes: - opened: openid + bearerAuth: + type: http + scheme: bearer From f18a664b7ed89bf439482d843d9ce0e2ec2aff4c Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Mon, 30 Sep 2019 14:42:36 +0100 Subject: [PATCH 12/19] updaing bearer security --- src/main/webapp/property.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/webapp/property.yaml b/src/main/webapp/property.yaml index 2d70464..100895a 100644 --- a/src/main/webapp/property.yaml +++ b/src/main/webapp/property.yaml @@ -105,6 +105,7 @@ components: xml: name: Phenotype securitySchemes: - bearerAuth: - type: http - scheme: bearer + ApiKeyAuth: + type: apiKey + in: header + name: Authorization From 75cf54eb2ba151b03152e777bbb3a95f7304f355 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Mon, 30 Sep 2019 15:19:52 +0100 Subject: [PATCH 13/19] security for each call --- src/main/webapp/property.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/webapp/property.yaml b/src/main/webapp/property.yaml index 100895a..254f3bf 100644 --- a/src/main/webapp/property.yaml +++ b/src/main/webapp/property.yaml @@ -17,6 +17,8 @@ servers: paths: /phenotypes: get: + security: + - ApiKeyAuth: [] tags: - Phenotype Entity summary: "find all phenotypes." @@ -52,6 +54,8 @@ paths: 404: description: Not found post: + security: + - ApiKeyAuth: [] tags: - Phenotype Entity summary: "save phenotype." @@ -104,6 +108,7 @@ components: description: allowed values of phenotype xml: name: Phenotype + securitySchemes: ApiKeyAuth: type: apiKey From 86d42aa959363db437e5a69f0555e1c4bdd0fd10 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Tue, 1 Oct 2019 15:00:31 +0100 Subject: [PATCH 14/19] removing webjars duplication --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index a2d899d..dc356b5 100644 --- a/pom.xml +++ b/pom.xml @@ -85,11 +85,6 @@ spring-boot-starter-tomcat provided
- - org.webjars - swagger-ui - 3.23.0 -
From b5212ad9741d543de5473eb191770b3b009ef57e Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Sun, 6 Oct 2019 01:00:06 +0100 Subject: [PATCH 15/19] making staging profile --- pom.xml | 82 +++++++++++++++++------------------ src/main/webapp/property.yaml | 2 +- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index dc356b5..2cfa970 100644 --- a/pom.xml +++ b/pom.xml @@ -116,57 +116,56 @@ + + + maven-dependency-plugin + + + swagger ui + prepare-package + + unpack + + + + + org.webjars + swagger-ui + 3.23.0 + + + ${project.build.directory}/swagger-ui + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + ${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/3.23.0 + + **/*.* + + swagger-ui + + + + - swagger-ui + staging true - - - maven-dependency-plugin - - - swagger ui - prepare-package - - unpack - - - - - org.webjars - swagger-ui - 3.23.0 - - - ${project.build.directory}/swagger-ui - - - - - - - org.apache.maven.plugins - maven-war-plugin - - - - ${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/3.23.0 - - **/*.* - - swagger-ui - - - - - com.google.code.maven-replacer-plugin replacer @@ -189,7 +188,6 @@ - diff --git a/src/main/webapp/property.yaml b/src/main/webapp/property.yaml index 254f3bf..d4da4c4 100644 --- a/src/main/webapp/property.yaml +++ b/src/main/webapp/property.yaml @@ -13,7 +13,7 @@ info: url: "https://www.apache.org/license/" servers: - url: http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/ - description: Production server + description: Staging server paths: /phenotypes: get: From 82a080994bdba4ff00aed9c440379cd44932061d Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Sun, 6 Oct 2019 01:25:29 +0100 Subject: [PATCH 16/19] removing default as staging profile --- Jenkinsfile | 2 +- pom.xml | 5 +---- .../registry/config/security/EnableSecurityConfig.java | 2 +- src/main/webapp/{property.yaml => propertys.yaml} | 0 4 files changed, 3 insertions(+), 6 deletions(-) rename src/main/webapp/{property.yaml => propertys.yaml} (100%) diff --git a/Jenkinsfile b/Jenkinsfile index 5494a31..35b280b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { stages { stage('Default Build pointing to Staging DB') { steps { - sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId}" + sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId} -Pstaging" } } stage('Build For FallBack And Production') { diff --git a/pom.xml b/pom.xml index 2cfa970..8b4cd77 100644 --- a/pom.xml +++ b/pom.xml @@ -161,9 +161,6 @@ staging - - true - @@ -183,7 +180,7 @@ https://petstore.swagger.io/v2/swagger.json - http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/property.yaml + http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/propertys.yaml diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index cd592d3..85549a0 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -37,7 +37,7 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { "/swagger-ui/", "/swagger-ui/**", "/swagger-ui/index.html", - "/property.yaml", + "/propertys.yaml", "/" }; diff --git a/src/main/webapp/property.yaml b/src/main/webapp/propertys.yaml similarity index 100% rename from src/main/webapp/property.yaml rename to src/main/webapp/propertys.yaml From 8579e40200fb3b25883cb1e9742f83d5b643cfcc Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Sun, 6 Oct 2019 11:25:24 +0100 Subject: [PATCH 17/19] evaluating multiple yaml profile --- Jenkinsfile | 2 +- pom.xml | 32 +++++++++++++++++-- .../config/security/EnableSecurityConfig.java | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 35b280b..ee6af08 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { stages { stage('Default Build pointing to Staging DB') { steps { - sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId} -Pstaging" + sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId} -Pproduction" } } stage('Build For FallBack And Production') { diff --git a/pom.xml b/pom.xml index 8b4cd77..8baa811 100644 --- a/pom.xml +++ b/pom.xml @@ -160,7 +160,7 @@ - staging + staging @@ -188,6 +188,34 @@ + + production + + + + com.google.code.maven-replacer-plugin + replacer + 1.5.3 + + + prepare-package + + replace + + + + + ${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/3.23.0/index.html + + + https://petstore.swagger.io/v2/swagger.json + http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/propertyp.yaml + + + + + + + - diff --git a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java index 85549a0..88638a1 100644 --- a/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java +++ b/src/main/java/uk/ac/ebi/ampt2d/registry/config/security/EnableSecurityConfig.java @@ -38,6 +38,7 @@ public class EnableSecurityConfig extends ResourceServerConfigurerAdapter { "/swagger-ui/**", "/swagger-ui/index.html", "/propertys.yaml", + "/propertyp.yaml", "/" }; From 8e359ed6a67fe2f8f3813e70fef56acf0c935166 Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Sun, 6 Oct 2019 11:27:30 +0100 Subject: [PATCH 18/19] add production yaml file --- src/main/webapp/propertyp.yaml | 116 +++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/main/webapp/propertyp.yaml diff --git a/src/main/webapp/propertyp.yaml b/src/main/webapp/propertyp.yaml new file mode 100644 index 0000000..0b115d1 --- /dev/null +++ b/src/main/webapp/propertyp.yaml @@ -0,0 +1,116 @@ +openapi: "3.0.2" +info: + title: "AMP T2D Property registry API" + description: "Property registry API for the project AMP-T2D" + version: "1.0SNAPSHOT" + termsOfService: "www.ebi.ac.uk/terms" + contact: + name: "Property registry API Admin" + url: "www.ebi.ac.uk" + email: "prop@gmail.com" + license: + name: "Apache 2.0" + url: "https://www.apache.org/license/" +servers: + - url: http://ves-hx-e9.ebi.ac.uk:8080/dev/registry/ + description: Staging server(production exp) +paths: + /phenotypes: + get: + security: + - ApiKeyAuth: [] + tags: + - Phenotype Entity + summary: "find all phenotypes." + description: "Get all phenotypes of Type2Diabetes." + operationId: GetPhenotypeEntity + parameters: + - name: page + in: query + description: "Number of pages." + schema: + type: string + - name: size + in: query + description: "size of page." + schema: + type: string + - name: sort + in: query + description: "Ascending or descending." + schema: + type: string + responses: + 200: + description: OK, Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/Phenotype' + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not found + post: + security: + - ApiKeyAuth: [] + tags: + - Phenotype Entity + summary: "save phenotype." + description: "Store a phenotype of Type2Diabetes." + operationId: PostPhenotypeEntity + requestBody: + description: Store a phenotype of Type2Diabetes. + content: + 'application/json': + schema: + $ref: '#/components/schemas/Phenotype' + required: true + responses: + 200: + description: OK, Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/Phenotype' + 201: + description: Created + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not found + +components: + schemas: + Phenotype: + type: object + properties: + id: + type: string + description: generated phid of phenotype + phenotypeGroup: + type: string + enum: [ANTHROPOMETRIC,CARDIOVASCULAR,GLYCEMIC] + description: phenotype group + description: + type: string + description: description of phenotype + type: + type: string + enum: [DICHOTOMOUS, MULTICHOTOMOUS] + description: description of phenotype + allowedValues: + type: string + description: allowed values of phenotype + xml: + name: Phenotype + + securitySchemes: + ApiKeyAuth: + type: apiKey + in: header + name: Authorization From dc0d0bdc1daaebeaad90696f4d703d7687e997ba Mon Sep 17 00:00:00 2001 From: Sreenidhi Iyangar Date: Sun, 6 Oct 2019 11:42:25 +0100 Subject: [PATCH 19/19] update to correct profile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ee6af08..f76bde7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { stages { stage('Default Build pointing to Staging DB') { steps { - sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId} -Pproduction" + sh "mvn clean package -DskipTests -DbuildDirectory=staging/target -Dampt2d-property-registry-db.url=${stagingPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId} -Pstaging" } } stage('Build For FallBack And Production') { @@ -35,9 +35,9 @@ pipeline { } steps { echo 'Build pointing to FallBack DB' - sh "mvn clean package -DskipTests -DbuildDirectory=fallback/target -Dampt2d-property-registry-db.url=${fallBackPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId}" + sh "mvn clean package -DskipTests -DbuildDirectory=fallback/target -Dampt2d-property-registry-db.url=${fallBackPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId} -Pproduction" echo 'Build pointing to Production DB' - sh "mvn clean package -DskipTests -DbuildDirectory=production/target -Dampt2d-property-registry-db.url=${productionPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId}" + sh "mvn clean package -DskipTests -DbuildDirectory=production/target -Dampt2d-property-registry-db.url=${productionPostgresDbUrl} -Dampt2d-property-registry-db.username=${postgresDBUserName} -Dampt2d-property-registry-db.password=${postgresDBPassword} -Dsmtp-host=${smtpHost} -Damp-t2d-email-id=${ampt2dEmailId} -Pproduction" } } stage('Deploy To Staging') {