diff --git a/spring-platform-config-server/pom.xml b/spring-platform-config-server/pom.xml
index e4031d5b..2c4dc5ec 100644
--- a/spring-platform-config-server/pom.xml
+++ b/spring-platform-config-server/pom.xml
@@ -45,6 +45,15 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.security
+ spring-security-crypto
+
+
+ org.springframework.security
+ spring-security-rsa
+ 1.0.0.BUILD-SNAPSHOT
+
org.eclipse.jgit
org.eclipse.jgit
diff --git a/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/Application.java b/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/Application.java
index 953fa11c..8f0ba7f5 100644
--- a/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/Application.java
+++ b/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/Application.java
@@ -1,6 +1,8 @@
package org.springframework.platform.config.server;
+import javax.annotation.PostConstruct;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -10,34 +12,40 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.platform.config.Environment;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
@Configuration
@ComponentScan
@EnableAutoConfiguration
-@RestController
public class Application {
- @Autowired
- private EnvironmentRepository repository;
-
- @RequestMapping("/{name}/{env}")
- public Environment master(@PathVariable String name, @PathVariable String env) {
- return properties(name, env, "master");
- }
-
- @RequestMapping("/{name}/{env}/{label}")
- public Environment properties(@PathVariable String name, @PathVariable String env, @PathVariable String label) {
- return repository.findOne(name, env, label);
- }
-
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
+ @Configuration
+ @ConfigurationProperties("encrypt")
+ protected static class KeyConfiguration {
+ @Autowired
+ private EncryptionController controller;
+
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ @PostConstruct
+ public void init() {
+ if (key!=null) {
+ controller.uploadKey(key);
+ }
+ }
+ }
+
@Configuration
@Profile("native")
protected static class NativeRepositoryConfiguration {
diff --git a/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/EncryptionController.java b/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/EncryptionController.java
new file mode 100644
index 00000000..10e0ecad
--- /dev/null
+++ b/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/EncryptionController.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2013-2014 the original author or authors.
+ *
+ * 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 org.springframework.platform.config.server;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.platform.config.Environment;
+import org.springframework.platform.config.PropertySource;
+import org.springframework.security.crypto.encrypt.Encryptors;
+import org.springframework.security.crypto.encrypt.TextEncryptor;
+import org.springframework.security.rsa.crypto.RsaKeyHolder;
+import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author Dave Syer
+ *
+ */
+@RestController
+public class EncryptionController {
+
+ private static Log logger = LogFactory.getLog(EncryptionController.class);
+
+ // TODO: expose as config property
+ private static final String SALT = "deadbeef";
+
+ private TextEncryptor encryptor;
+
+ public void setEncryptor(TextEncryptor encryptor) {
+ this.encryptor = encryptor;
+ }
+
+ @RequestMapping(value = "/key", method = RequestMethod.GET)
+ public String getPublicKey() {
+ if (!(encryptor instanceof RsaKeyHolder)) {
+ throw new KeyNotAvailableException();
+ }
+ return ((RsaKeyHolder) encryptor).getPublicKey();
+ }
+
+ @RequestMapping(value = "/key", method = RequestMethod.PUT)
+ public ResponseEntity