Skip to content

Commit

Permalink
fixes #48 add client key/trust stores and supportClient flag
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Jun 13, 2017
1 parent a322cda commit e981cf3
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
String schemaPackage = config.get("schemaPackage").toString();
String schemaClass = config.get("schemaClass").toString();
boolean overwriteSchemaClass = config.toBoolean("overwriteSchemaClass");
boolean supportClient = config.toBoolean("supportClient");

transfer(targetPath, "", "pom.xml", templates.graphql.pom.template(config));
transfer(targetPath, "", "Dockerfile", templates.graphql.dockerfile.template(config));
Expand All @@ -48,7 +49,13 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "server.yml", templates.graphql.serverYml.template(config.get("groupId") + "." + config.get("artifactId") + "-" + config.get("version")));
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "secret.yml", templates.graphql.secretYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "security.yml", templates.graphql.securityYml.template());

if(supportClient) {
// copy client.yml to main/resources/config
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "client.yml", templates.graphql.clientYml.template());
} else {
// copy client.yml to test/resources/config for test cases
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "client.yml", templates.graphql.clientYml.template());
}

transfer(targetPath, ("src.main.resources.config.oauth").replace(".", separator), "primary.crt", templates.graphql.primaryCrt.template());
transfer(targetPath, ("src.main.resources.config.oauth").replace(".", separator), "secondary.crt", templates.graphql.secondaryCrt.template());
Expand Down Expand Up @@ -91,7 +98,25 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
try (InputStream is = GraphqlGenerator.class.getResourceAsStream("/binaries/server.truststore")) {
Files.copy(is, Paths.get(targetPath, ("src.main.resources.config.tls").replace(".", separator), "server.truststore"), StandardCopyOption.REPLACE_EXISTING);
}

if(supportClient) {
try (InputStream is = GraphqlGenerator.class.getResourceAsStream("/binaries/client.keystore")) {
Files.copy(is, Paths.get(targetPath, ("src.main.resources.config.tls").replace(".", separator), "client.keystore"), StandardCopyOption.REPLACE_EXISTING);
}
try (InputStream is = GraphqlGenerator.class.getResourceAsStream("/binaries/client.truststore")) {
Files.copy(is, Paths.get(targetPath, ("src.main.resources.config.tls").replace(".", separator), "client.truststore"), StandardCopyOption.REPLACE_EXISTING);
}
} else {
// copy client keystore and truststore into test resources for test cases.
if(Files.notExists(Paths.get(targetPath, ("src.test.resources.config.tls").replace(".", separator)))) {
Files.createDirectories(Paths.get(targetPath, ("src.test.resources.config.tls").replace(".", separator)));
}
try (InputStream is = GraphqlGenerator.class.getResourceAsStream("/binaries/client.keystore")) {
Files.copy(is, Paths.get(targetPath, ("src.test.resources.config.tls").replace(".", separator), "client.keystore"), StandardCopyOption.REPLACE_EXISTING);
}
try (InputStream is = GraphqlGenerator.class.getResourceAsStream("/binaries/client.truststore")) {
Files.copy(is, Paths.get(targetPath, ("src.test.resources.config.tls").replace(".", separator), "client.truststore"), StandardCopyOption.REPLACE_EXISTING);
}
}
}

}
Binary file not shown.
Binary file not shown.
Binary file modified light-graphql-4j/src/main/resources/binaries/server.keystore
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
sync:
maxConnectionTotal: 100
maxConnectionPerRoute: 10
routes:
api.google.com: 20
api.facebook.com: 10
timeout: 10000
keepAlive: 15000
async:
maxConnectionTotal: 100
maxConnectionPerRoute: 10
routes:
api.google.com: 20
api.facebook.com: 10
reactor:
ioThreadCount: 1
connectTimeout: 10000
soTimeout: 10000
timeout: 10000
keepAlive: 15000
tls:
# if the server is using self-signed certificate, this need to be false. If true, you have to use CA signed certificate
# or load truststore that contains the self-signed cretificate.
verifyHostname: true
# trust store contains certifictes that server needs. Enable if tls is used.
loadTrustStore: true
# trust store location can be specified here or system properties javax.net.ssl.trustStore and password javax.net.ssl.trustStorePassword
trustStore: tls/client.truststore
# key store contains client key and it should be loaded if two-way ssl is uesed.
loadKeyStore: false
# key store location
keyStore: tls/client.keystore
oauth:
tokenRenewBeforeExpired: 600000
expiredRefreshRetryDelay: 5000
earlyRefreshRetryDelay: 30000
# token server url. The default port number for token service is 6882.
server_url: http://localhost:6882
authorization_code:
# token endpoint for authorization code grant
uri: "/oauth2/token"
# client_id for authorization code grant flow. client_secret is in secret.yml
client_id: 3798d583-275c-47d7-bf46-a3c436846336
redirect_uri: https://localhost:8080/authorization_code
scope:
- customer.r
- customer.w
client_credentials:
# token endpoint for client credentials grant
uri: "/oauth2/token"
# client_id for client credentials grant flow. client_secret is in secret.yml
client_id: 6e9d1db3-2feb-4c1f-a5ad-9e93ae8ca59d
scope:
- account.r
- account.w
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# This file contains all the secrets for the server in order to manage and
# secure all of them in the same place. In Kubernetes, this file will be
# mapped to Secrets and all other config files will be mapped to mapConfig
# This file contains all the secrets for the server and client in order to manage and
# secure all of them in the same place. In Kubernetes, this file will be mapped to
# Secrets and all other config files will be mapped to mapConfig

---

# Sever section

# Key store password, the path of keystore is defined in server.yml
serverKeystorePass: password

# Key password, the key is in keystore
serverKeyPass: password

# Trust store password, the path of truststore is defined in server.yml
serverTruststorePass: password


# Client section

# Key store password, the path of keystore is defined in server.yml
keystorePass: secret
clientKeystorePass: password

# Key password, the key is in keystore
keyPass: secret
clientKeyPass: password

# Trust store password, the path of truststore is defined in server.yml
truststorePass: password
clientTruststorePass: password

# Authorization code client secret for OAuth2 server
authorizationCodeClientSecret: f6h1FTI8Q3-7UScPZDzfXA

# Client credentials client secret for OAuth2 server
clientCredentialsClientSecret: f6h1FTI8Q3-7UScPZDzfXA

# Client secret for OAuth2 server
clientSecret: f6h1FTI8Q3-7UScPZDzfXA
3 changes: 2 additions & 1 deletion light-graphql-4j/src/test/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"name": "starwars",
"version": "1.0.1",
"schemaClass": "StarWarsSchema",
"overwriteSchemaClass": true
"overwriteSchemaClass": true,
"supportClient": false
}

0 comments on commit e981cf3

Please sign in to comment.