Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Fine tune server #38

Merged
merged 45 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
049527c
Server: Fix config property name
lealceldeiro Apr 2, 2020
28fd154
Server: Trim long comment
lealceldeiro Apr 2, 2020
4e753d7
Server: Improve config files format
lealceldeiro Apr 2, 2020
4d5352c
Server: Remove incorrect dependency added in JWTAuthenticationFailure…
lealceldeiro Apr 2, 2020
edc5fd7
Server: Upgrade to SpringBoot 2.2.6.RELEASE and flyway to 6.3.2
lealceldeiro Apr 3, 2020
6e5d253
Server: Fix dependency spring-boot-configuration-processor
lealceldeiro Apr 3, 2020
cfd3faf
Server: Remove deprecated dependency and fix code format.
lealceldeiro Apr 3, 2020
690f07e
Server: Add `spring.mvc.hiddenmethod.filter.enabled=false` to applica…
lealceldeiro Apr 4, 2020
79e9dcb
Server: Remove un-needed annotation.
lealceldeiro Apr 4, 2020
424f20a
Server: Spellcheck on apidocs.
lealceldeiro Apr 4, 2020
b24c70b
Server: Do not run test with spring runner and without spring context…
lealceldeiro Apr 4, 2020
e736d25
Server: Fix typos and format.
lealceldeiro Apr 5, 2020
9cd93e3
Server: Fix request language detection and handling.
lealceldeiro Apr 5, 2020
c6d3a7e
Server: Bumb class version.
lealceldeiro Apr 5, 2020
c087091
Server: Move JWToken service to a more descriptive folder.
lealceldeiro Apr 5, 2020
5bb87b3
Server: Move JWToken service to a more descriptive folder and create …
lealceldeiro Apr 5, 2020
ed0906f
Server: Move security config class to dedicated packages and update t…
lealceldeiro Apr 5, 2020
e4851c3
Server: Set default locale.
lealceldeiro Apr 5, 2020
a38fec1
Server: Fallback to CookieLocaleResolver if custom logic doesn't find…
lealceldeiro Apr 5, 2020
47b8547
Server: Documents language changing options.
lealceldeiro Apr 6, 2020
3d1b574
Server: Disable JSP pages on server.
lealceldeiro Apr 6, 2020
01192b0
Server: Return a reponse body on unauthorized requests
lealceldeiro Apr 10, 2020
796cad5
Server: Update javadocs.
lealceldeiro Apr 11, 2020
5993928
Server: Disable basic authentication.
lealceldeiro Apr 11, 2020
a8f5537
Server: Tweak some javadocs, variable names and optimize imports.
lealceldeiro Apr 11, 2020
78a5e0e
Server: Provide `PasswordEncoder` bean instead of `BcryptPassowrdEnco…
lealceldeiro Apr 11, 2020
2a04c1a
Server: Decrease column length for storing password.
lealceldeiro Apr 11, 2020
1165fcc
Server: Improve SQL readability in flyway migration.
lealceldeiro Apr 11, 2020
bf3437e
Server: Improve code format.
lealceldeiro Apr 11, 2020
2f3c5f3
Server: Create constructuro in GmsHttpStatusAndBodyEntryPoint using l…
lealceldeiro Apr 11, 2020
c786b95
Server: Create GmsAccessDeniedHandler and apply it in SecurityConfig.
lealceldeiro Apr 11, 2020
72cc1a2
Server: Add Security annotation to ConfigurationController (example t…
lealceldeiro Apr 12, 2020
9571dae
Server: Improve code style in gradle file.
lealceldeiro Apr 17, 2020
409542a
Server: Improve code style in gradle file.
lealceldeiro Apr 17, 2020
3cce48f
Server: Remove some deprecated usages in gradle file.
lealceldeiro Apr 18, 2020
a23a225
Server: Remove some deprecated usages in gradle file.
lealceldeiro Apr 18, 2020
75bab56
Server: Remove `serrver.port` from application.properties and update …
lealceldeiro Apr 18, 2020
13e08ef
Server: Update lombok version.
lealceldeiro Apr 18, 2020
e45e843
Server: Update flyway version.
lealceldeiro Apr 18, 2020
684f96e
Server: Update jwt version.
lealceldeiro Apr 18, 2020
600d199
Server: Update org.reflections version.
lealceldeiro Apr 18, 2020
d913aaf
Server: Update com.github.kt3k.coveralls and net.saliman.cobertura ve…
lealceldeiro Apr 18, 2020
bcfc3bf
Server: Update application versions.
lealceldeiro Apr 18, 2020
bac647b
Server: Update spring.dependency-management version.
lealceldeiro Apr 18, 2020
5d4b9d1
Server: Update org.asciidoctor.convert version.
lealceldeiro Apr 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 66 additions & 53 deletions server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
buildscript {
ext {
appVersion = "0.0.1"
appVersion = "0.0.2"
// versions (ordered alphabetically)
checkStyleVersion = "8.28"
flywayVersion = "5.0.7"
flywayVersion = "6.3.3"
javaassistVersion = "3.26.0-GA"
jaxbVersion = 2.1
jwtVersion = "0.9.0"
lombokVersion = "1.18.10"
refVersion = "0.9.11"
springBootVersion = "2.0.2.RELEASE" // keep synced with plugin org.springframework.boot declared below
jwtVersion = "0.9.1"
lombokVersion = "1.18.12"
refVersion = "0.9.12"
springBootVersion = "2.2.6.RELEASE" // keep synced with plugin org.springframework.boot declared below
targetSource = 1.8
// other vars
apiDocsFolder = "apidocs"
Expand All @@ -20,12 +20,12 @@ buildscript {
}

plugins {
id "com.github.kt3k.coveralls" version "2.8.4" // coverage reports for coveralls.io
id "com.github.kt3k.coveralls" version "2.10.1" // coverage reports for coveralls.io
id "com.moowork.node" version "1.3.1"
id "io.spring.dependency-management" version "1.0.8.RELEASE"
id "net.saliman.cobertura" version "2.6.1" // coverage generator
id "org.asciidoctor.convert" version "2.3.0"
id "org.springframework.boot" version "2.0.2.RELEASE" // keep synced with var springBootVersion
id "io.spring.dependency-management" version "1.0.9.RELEASE"
id "net.saliman.cobertura" version "3.0.0" // coverage generator
id "org.asciidoctor.convert" version "2.4.0"
id "org.springframework.boot" version "2.2.6.RELEASE" // keep synced with var springBootVersion
id 'checkstyle'
}

Expand All @@ -50,36 +50,40 @@ node {

dependencies {
annotationProcessor ("org.projectlombok:lombok:${lombokVersion}")

compile ("io.jsonwebtoken:jjwt:${jwtVersion}")
compile ("org.flywaydb:flyway-core:${flywayVersion}")
compile ("org.reflections:reflections:${refVersion}")
compile ("org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}")
compile ("org.springframework.boot:spring-boot-starter-data-jpa")
compile ("org.springframework.boot:spring-boot-starter-data-rest")
compile ("org.springframework.boot:spring-boot-starter-hateoas")
compile ("org.springframework.boot:spring-boot-starter-mail")
compile ("org.springframework.boot:spring-boot-starter-security")
compile ("org.springframework.boot:spring-boot-starter-web")
compile ("javax.xml.bind:jaxb-api:${jaxbVersion}")
compile ("org.javassist:javassist:${javaassistVersion}")

annotationProcessor ("org.springframework.boot:spring-boot-configuration-processor")

implementation ("io.jsonwebtoken:jjwt:${jwtVersion}")
implementation ("org.flywaydb:flyway-core:${flywayVersion}")
implementation ("org.reflections:reflections:${refVersion}")
implementation ("org.springframework.boot:spring-boot-starter-data-jpa")
implementation ("org.springframework.boot:spring-boot-starter-data-rest")
implementation ("org.springframework.boot:spring-boot-starter-hateoas")
implementation ("org.springframework.boot:spring-boot-starter-mail")
implementation ("org.springframework.boot:spring-boot-starter-security")
implementation ("org.springframework.boot:spring-boot-starter-web")
implementation ("javax.xml.bind:jaxb-api:${jaxbVersion}")
implementation ("org.javassist:javassist:${javaassistVersion}")

compileOnly ("org.projectlombok:lombok:${lombokVersion}")

runtime ("org.postgresql:postgresql")
runtime ("org.springframework.boot:spring-boot-devtools")
runtimeOnly ("org.postgresql:postgresql")
runtimeOnly ("org.springframework.boot:spring-boot-devtools")

testImplementation ("com.jayway.jsonpath:json-path")
testImplementation ("org.springframework.boot:spring-boot-starter-test")
testImplementation ("org.springframework.restdocs:spring-restdocs-mockmvc")
testImplementation ("org.springframework.security:spring-security-test")

testCompile ("com.jayway.jsonpath:json-path")
testCompile ("org.springframework.boot:spring-boot-starter-test")
testCompile ("org.springframework.restdocs:spring-restdocs-mockmvc")
testCompile ("org.springframework.security:spring-security-test")
testCompileOnly ("org.projectlombok:lombok:${lombokVersion}")
testAnnotationProcessor ("org.projectlombok:lombok:${lombokVersion}")
}

//region custom tasks

//region client task
task clientBuild(type: NpmTask, dependsOn: ["npmInstall", "copyClientDocBuild", "configPackageJsonDeployUrl", "configPackageJsonBaseUrl"]) {
task clientBuild(type: NpmTask, dependsOn: ["npmInstall", "copyClientDocBuild", "configPackageJsonDeployUrl",
"configPackageJsonBaseUrl"]
) {
group = "client"
description = "Compiles client side folder for production"
args = ["run", "build"]
Expand Down Expand Up @@ -112,7 +116,8 @@ task clientDocBuild(type: NpmTask, dependsOn: ["npmInstall"]) {

task copyClientDocBuild(type: Copy, dependsOn: ["clientDocBuild"]) {
group = "client"
description = "Checks all client app documentation resources are ready for deployment and copy them into the `static` folder"
description = """Checks all client app documentation resources are ready for deployment and copy them into the
`static` folder"""
from "../client/documentation"
into "build/resources/main/static/appdocs"
}
Expand All @@ -130,12 +135,14 @@ task setDevConfig() {
group = "other"
description = "Sets the environment for development mode"
doFirst {
def p = getSpringAppPropertyInBuild("spring.profiles.active")
if (p && p != "development") {
final def property = getSpringAppPropertyInBuild("spring.profiles.active")
if (property && property != "development") {
ant.propertyfile(file: buildPropertiesFilePath) {
entry(key: "spring.profiles.active", value: "development")
}
envSet = true

return
}
}
doLast {
Expand All @@ -149,12 +156,14 @@ task setTestingConfig() {
group = "other"
description = "Sets the environment for testing mode"
doFirst {
def p = getSpringAppPropertyInBuild("spring.profiles.active")
if (p && p != "test") {
final def property = getSpringAppPropertyInBuild("spring.profiles.active")
if (property && property != "test") {
ant.propertyfile(file: buildPropertiesFilePath) {
entry(key: "spring.profiles.active", value: "test")
}
envSet = true

return
}
}
doLast {
Expand All @@ -168,12 +177,14 @@ task setProductionConfig() {
group = "other"
description = "Sets the environment for production mode"
doFirst {
def p = getSpringAppPropertyInBuild("spring.profiles.active")
if (p && p != "production") {
final def property = getSpringAppPropertyInBuild("spring.profiles.active")
if (property && property != "production") {
ant.propertyfile(file: buildPropertiesFilePath) {
entry(key: "spring.profiles.active", value: "production")
}
envSet = true

return
}
}
doLast {
Expand All @@ -184,18 +195,18 @@ task setProductionConfig() {
}

@SuppressWarnings("GrMethodMayBeStatic")
private String getSpringAppPropertyInBuild(String key, String filePath = null){
def props = new Properties()
def propFile = new File(filePath ?: buildPropertiesFilePath)
def p = null
private String getSpringAppPropertyInBuild(final String propertyKey, final String filePath = null) {
final def props = new Properties()
final def propFile = new File(filePath ?: buildPropertiesFilePath)
def property = null

if (propFile.exists() && propFile.canRead()){
props.load(new FileInputStream(propFile))
if (props!=null && props.containsKey(key)) {
p = props[key]
if (props != null && props.containsKey(propertyKey)) {
property = props[propertyKey]
}
}
return p
return property
}

//endregion
Expand Down Expand Up @@ -272,7 +283,7 @@ testClasses.dependsOn(setTestingConfig)

bootWar {
dependsOn setProductionConfig, processApiDocs, copyClientBuild
baseName = getAppName()
archivesBaseName = getAppName()
}

// In order to generate our own metadata by Using the Annotation Processor
Expand All @@ -295,13 +306,15 @@ private String getAppName() {
}

private String getClientDeployUrl() {
String defaultUrl = "/${getAppName()}-${version}/"
String configUrl = project.getProperties().get("clientDeployUrl")
final String defaultUrl = "/${getAppName()}-${version}/"
final String configUrl = project.getProperties().get("clientDeployUrl")

return (configUrl || configUrl == "<default>") ? (configUrl == "<default>" ? "" : configUrl) : defaultUrl
}

private String getClientBaseUrl() {
String defaultUrl = "/${getAppName()}-${version}/"
String configUrl = project.getProperties().get("clientBaseUrl")
return configUrl ? configUrl : defaultUrl
}
final String defaultUrl = "/${getAppName()}-${version}/"
final String configUrl = project.getProperties().get("clientBaseUrl")

return configUrl ?: defaultUrl
}
4 changes: 3 additions & 1 deletion server/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ include::overview/index.adoc[]

include::security/index.adoc[]

include::resources/index.adoc[]
include::language/index.adoc[]

include::resources/index.adoc[]
11 changes: 11 additions & 0 deletions server/src/main/asciidoc/language/example/language-header-en.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include::../../util/H-REQUEST.adoc[]

include::../../util/H-EXAMPLE.adoc[]

include::{snippets}/locale-config-test/delete-roles-e-n/curl-request.adoc[]

include::../../util/H-RESPONSE.adoc[]

include::../../util/H-EXAMPLE-BARE.adoc[]

include::{snippets}/locale-config-test/delete-roles-e-n/http-response.adoc[]
11 changes: 11 additions & 0 deletions server/src/main/asciidoc/language/example/language-param-es.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include::../../util/H-REQUEST.adoc[]

include::../../util/H-EXAMPLE.adoc[]

include::{snippets}/locale-config-test/delete-roles-e-s/curl-request.adoc[]

include::../../util/H-RESPONSE.adoc[]

include::../../util/H-EXAMPLE-BARE.adoc[]

include::{snippets}/locale-config-test/delete-roles-e-s/http-response.adoc[]
21 changes: 21 additions & 0 deletions server/src/main/asciidoc/language/index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[[language]]
== Language

By default all requests will be handled in English Language. Additionally there is support for the following languages:

- Spanish

The language in which the request will be handle can be specified in the following ways:

[[sending-accept-language]]
=== Sending an `Accept-Language` header

include::example/language-header-en.adoc[]

[[sending-request-parameter]]
=== Sending a special parameter in the request (by default `lang`, but it may change due to server configuration)

include::example/language-param-es.adoc[]

[[sending-cookie]]
=== Sending a cookie
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[system-configuration-get-is-multientity]]
==== Getting whether the system is multi-entity or not

A `GET` request return `true` or `false` indicating whether the system is configured for managing multiple entities (`true`) or not (`false`).
A `GET` request returns `true` or `false` indicating whether the system is configured for managing multiple entities (`true`) or not (`false`).

include::../../util/H-REQUEST.adoc[]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[system-configuration-get-user-registration-allowed]]
==== Getting whether the system is configured for signing up new users or not

A `GET` request return `true` or `false` indicating whether new users can sign up (`true`) or not (`false`).
A `GET` request returns `true` or `false` indicating whether new users can sign up (`true`) or not (`false`).

include::../../util/H-REQUEST.adoc[]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[resource-roles-add-permission]]
==== Adding permissions

A `POST` request add new permissions to a role if this has not this permission already assigned.
A `POST` request adds new permissions to a role if this has not this permission already assigned.
This request does not delete eny of the existing permissions assigned to the role.

include::../../util/H-REQUEST.adoc[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[resource-roles-update-permission]]
==== Updating permissions

A `PUT` request set the permissions for a role.
A `PUT` request sets the permissions for a role.
This service sets the permissions with the `id` as the ones provided in the payload as the ones assigned to the specified role (through the `id` in the URL).
This removes all previous permissions assigned to the role and adds the new ones.

Expand Down
7 changes: 4 additions & 3 deletions server/src/main/java/com/gms/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
* Entry point to the application.
Expand Down Expand Up @@ -77,12 +78,12 @@ public CommandLineRunner commandLineRunner(final AppService appService) {
//bCrypt

/**
* Creates a {@link BCryptPasswordEncoder} to be provided to the Spring framework.
* Creates a {@link PasswordEncoder} to be provided to the Spring framework.
*
* @return A {@link BCryptPasswordEncoder}.
* @return A {@link PasswordEncoder}.
*/
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
public PasswordEncoder gmsPasswordEncoder() {
return new BCryptPasswordEncoder();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gms.config;

import com.gms.component.security.authentication.AuthenticationFacade;
import com.gms.config.security.authentication.AuthenticationFacade;
import com.gms.util.constant.DefaultConst;
import com.gms.util.exception.ExceptionUtil;
import com.gms.util.exception.GmsGeneralException;
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/com/gms/config/RepositoryConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.reflections.scanners.SubTypesScanner;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;

import java.util.Set;

Expand All @@ -15,7 +15,7 @@
* @version 0.1
*/
@Configuration
public class RepositoryConfig extends RepositoryRestConfigurerAdapter {
public class RepositoryConfig implements RepositoryRestConfigurer {

/**
* This method is intended to be used by the Spring framework and should not be overridden. Doing so may produce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class GmsCLocaleResolver extends CookieLocaleResolver {
public Locale resolveLocale(final HttpServletRequest request) {
String acceptLanguage = request.getHeader(DefaultConst.DEFAULT_LANGUAGE_HEADER);
if (acceptLanguage == null || acceptLanguage.trim().isEmpty()) {
return super.determineDefaultLocale(request);
return super.resolveLocale(request);
}

return request.getLocale();
Expand Down
Loading