-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dave Syer
committed
Aug 1, 2014
1 parent
2b2cbf2
commit b0c3642
Showing
6 changed files
with
182 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 1 addition & 112 deletions
113
...m-config-server/src/main/java/org/springframework/platform/config/server/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,11 @@ | ||
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; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
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.core.io.Resource; | ||
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory; | ||
import org.springframework.security.rsa.crypto.RsaSecretEncryptor; | ||
|
||
@Configuration | ||
@ComponentScan | ||
@EnableAutoConfiguration | ||
@EnableConfigServer | ||
public class Application { | ||
|
||
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; | ||
|
||
private KeyStore keyStore = new KeyStore(); | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public KeyStore getKeyStore() { | ||
return keyStore; | ||
} | ||
|
||
public void setKeyStore(KeyStore keyStore) { | ||
this.keyStore = keyStore; | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
if (keyStore.getLocation() != null) { | ||
controller.setEncryptor(new RsaSecretEncryptor(new KeyStoreKeyFactory( | ||
keyStore.getLocation(), keyStore.getPassword().toCharArray()) | ||
.getKeyPair(keyStore.getAlias()))); | ||
} | ||
if (key != null) { | ||
controller.uploadKey(key); | ||
} | ||
} | ||
|
||
public static class KeyStore { | ||
|
||
private Resource location; | ||
private String password; | ||
private String alias; | ||
|
||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
public void setAlias(String alias) { | ||
this.alias = alias; | ||
} | ||
|
||
public Resource getLocation() { | ||
return location; | ||
} | ||
|
||
public void setLocation(Resource location) { | ||
this.location = location; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
} | ||
} | ||
|
||
@Configuration | ||
@Profile("native") | ||
protected static class NativeRepositoryConfiguration { | ||
@Autowired | ||
private ConfigurableEnvironment environment; | ||
|
||
@Bean | ||
public NativeEnvironmentRepository repository() { | ||
return new NativeEnvironmentRepository(environment); | ||
} | ||
} | ||
|
||
@Configuration | ||
@Profile("!native") | ||
protected static class GitRepositoryConfiguration { | ||
@Autowired | ||
private ConfigurableEnvironment environment; | ||
|
||
@Bean | ||
@ConfigurationProperties("spring.platform.config.server") | ||
public JGitEnvironmentRepository repository() { | ||
return new JGitEnvironmentRepository(environment); | ||
} | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
...r/src/main/java/org/springframework/platform/config/server/ConfigServerConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* 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 javax.annotation.PostConstruct; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
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.core.io.Resource; | ||
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory; | ||
import org.springframework.security.rsa.crypto.RsaSecretEncryptor; | ||
|
||
/** | ||
* @author Dave Syer | ||
* | ||
*/ | ||
@Configuration | ||
@ComponentScan | ||
public class ConfigServerConfiguration { | ||
|
||
@Configuration | ||
@ConfigurationProperties("encrypt") | ||
protected static class KeyConfiguration { | ||
@Autowired | ||
private EncryptionController controller; | ||
|
||
private String key; | ||
|
||
private KeyStore keyStore = new KeyStore(); | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public KeyStore getKeyStore() { | ||
return keyStore; | ||
} | ||
|
||
public void setKeyStore(KeyStore keyStore) { | ||
this.keyStore = keyStore; | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
if (keyStore.getLocation() != null) { | ||
controller.setEncryptor(new RsaSecretEncryptor(new KeyStoreKeyFactory( | ||
keyStore.getLocation(), keyStore.getPassword().toCharArray()) | ||
.getKeyPair(keyStore.getAlias()))); | ||
} | ||
if (key != null) { | ||
controller.uploadKey(key); | ||
} | ||
} | ||
|
||
public static class KeyStore { | ||
|
||
private Resource location; | ||
private String password; | ||
private String alias; | ||
|
||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
public void setAlias(String alias) { | ||
this.alias = alias; | ||
} | ||
|
||
public Resource getLocation() { | ||
return location; | ||
} | ||
|
||
public void setLocation(Resource location) { | ||
this.location = location; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
} | ||
} | ||
|
||
@Configuration | ||
@Profile("native") | ||
protected static class NativeRepositoryConfiguration { | ||
@Autowired | ||
private ConfigurableEnvironment environment; | ||
|
||
@Bean | ||
public NativeEnvironmentRepository repository() { | ||
return new NativeEnvironmentRepository(environment); | ||
} | ||
} | ||
|
||
@Configuration | ||
@Profile("!native") | ||
protected static class GitRepositoryConfiguration { | ||
@Autowired | ||
private ConfigurableEnvironment environment; | ||
|
||
@Bean | ||
@ConfigurationProperties("spring.platform.config.server") | ||
public JGitEnvironmentRepository repository() { | ||
return new JGitEnvironmentRepository(environment); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...g-server/src/main/java/org/springframework/platform/config/server/EnableConfigServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.context.annotation.Import; | ||
|
||
/** | ||
* @author Dave Syer | ||
* | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Import(ConfigServerConfiguration.class) | ||
public @interface EnableConfigServer { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters