package com.orange;

import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import static org.springframework.cloud.servicebroker.model.BrokerApiVersion.API_VERSION_ANY;

@EnableGlobalMethodSecurity
@SpringBootApplication(scanBasePackages = { "com.orange" })
public class Application {

	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(Application.class);
		app.setDefaultProperties(getSecurityProperties());
		app.run(args);
//		SpringApplication.run(Application.class, args);
	}
	
	@Bean
	public BrokerApiVersion brokerApiVersion() {
		return new BrokerApiVersion(API_VERSION_ANY);
	}
	
	public static Map<String, Object> getSecurityProperties(){
		Map<String, Object> properties = new HashMap<String, Object>();
		Map<String, String> env = System.getenv();
		String username = env.get("SECURITY_USER");
		String password = env.get("SECURITY_PASSWORD");
		properties.put("security.user.name", username);
		properties.put("security.user.password", password);
		return properties;
	}
}
@@ -855,17 +855,16 @@
 gs);%0A%09%7D%0A
-%09
 %0A%09@Bean%0A
@@ -960,17 +960,195 @@
 NY);%0A%09%7D%0A
-%09
+%0A%09/**%0A%09 * get SecurityProperties for system environment variables%0A%09 * %0A%09 * @return SecurityProperties which contains security.user.name and%0A%09 *         security.user.password%0A%09 */
 %0A%09public
@@ -1198,16 +1198,17 @@
 erties()
+ 
 %7B%0A%09%09Map%3C
@@ -1414,130 +1414,852 @@
 ;%0A%09%09
-properties.put(%22security.user.name%22, username);%0A%09%09properties.put(%22security.user.password%22, password);%0A%09%09return properties;
+Map%3CString, Object%3E mandatoryProperties = new HashMap%3CString, Object%3E();%0A%09%09mandatoryProperties.put(%22SECURITY_PASSWORD%22, password);%0A%09%09checkMandatoryPropertiesDefined(mandatoryProperties);%0A%09%09properties.put(%22security.user.name%22, username);%0A%09%09properties.put(%22security.user.password%22, password);%0A%09%09return properties;%0A%09%7D%0A%0A%09/**%0A%09 * throw IllegalArgumentException when the mandatory property%0A%09 * (SECURITY_PASSWORD) is not set%0A%09 * %0A%09 * @throws IllegalArgumentException%0A%09 */%0A%09public static void checkMandatoryPropertiesDefined(Map%3CString, Object%3E mandatoryProperties)%0A%09%09%09throws IllegalArgumentException %7B%0A%09%09for (Map.Entry%3CString, Object%3E mandatoryProperty : mandatoryProperties.entrySet()) %7B%0A%09%09%09if (mandatoryProperty.getValue() == null) %7B%0A%09%09%09%09throw new IllegalArgumentException(%22Mandatory property: %22 + mandatoryProperty.getKey() + %22 missing%22);%0A%09%09%09%7D%0A%09%09%7D
 %0A%09%7D%0A

add func to check whether mandatory properties defined, add check for SECURITY_PASSWORD