diff options
| author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 12:14:20 +0200 | 
|---|---|---|
| committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 12:14:20 +0200 | 
| commit | 1fb729e35f4c423cf2a1996cdcc6a213122f4e0e (patch) | |
| tree | 4d0ad94176fe3d756a3297508a5e2ebf11cbc58c | |
| parent | 95ce504efcf6eb886e353310570505d598e10561 (diff) | |
| download | moa-id-spss-1fb729e35f4c423cf2a1996cdcc6a213122f4e0e.tar.gz moa-id-spss-1fb729e35f4c423cf2a1996cdcc6a213122f4e0e.tar.bz2 moa-id-spss-1fb729e35f4c423cf2a1996cdcc6a213122f4e0e.zip | |
fix merge problems
12 files changed, 1446 insertions, 1378 deletions
| diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigLoader.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigLoader.java index f5009f99f..80ecff2d2 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigLoader.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigLoader.java @@ -47,11 +47,15 @@ public class AuthConfigLoader implements Runnable {  					Date dbdate = moaidconfig.getTimestampItem();  					Date pvprefresh = moaidconfig.getPvp2RefreshItem(); -					Date date = AuthConfigurationProviderFactory.getInstance().getTimeStamp(); -				 +					//TODO: check!!!! +					 +					//Date date = AuthConfigurationProviderFactory.getInstance().getTimeStamp(); +					Date date = new Date(); +					 +					  					if (dbdate != null && dbdate.after(date)) {  						AuthConfiguration instance = AuthConfigurationProviderFactory.getInstance(); -						instance.reloadDataBaseConfig(); +//						instance.reloadDataBaseConfig();  					}  					Date pvpdate = MOAMetadataProvider.getTimeStamp(); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java index cba80d536..7228e6129 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfiguration.java @@ -1,6 +1,5 @@  package at.gv.egovernment.moa.id.config.auth; -import java.util.Hashtable;  import java.util.List;  import java.util.Properties; diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java index 81a3dad8f..dfb2a4dfd 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java @@ -71,9 +71,7 @@ import at.gv.egovernment.moa.id.auth.modules.internal.tasks.GetMISSessionIDTask;  import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants;  import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead;  import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; -import at.gv.egovernment.moa.id.commons.db.NewConfigurationDBWrite;  import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; -import at.gv.egovernment.moa.id.commons.db.NewConfigurationDBRead;  import at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils;  import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral;  import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; @@ -123,6 +121,7 @@ import at.gv.egovernment.moa.util.MiscUtil;  import at.gv.util.config.EgovUtilPropertiesConfiguration;  import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty;  /**   * A class providing access to the Auth Part of the MOA-ID configuration data. diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java index cdd112a43..e1c1ac49e 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/ConfigurationToJSONConverter.java @@ -1,155 +1,155 @@ -package at.gv.egovernment.moa.id.config.auth; - -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; -import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead; -import at.gv.egovernment.moa.id.config.ConfigurationException; -import at.gv.egovernment.moa.id.config.ConfigurationProvider; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ConfigurationToJSONConverter { - -	@Autowired -	NewAuthConfigurationProvider configProvider; - -	@Autowired -	MOAIDConfiguration configDataBase; - -	public static void main(String[] args) { - -		try { -			ConfigurationToJSONConverter converter = new ConfigurationToJSONConverter(args[0]); -			converter.writeConfigToJSONDB(); -			System.out.println("====================================="); -			System.out.println("====================================="); -			converter.readConfigFromDB(); -			System.out.println("====================================="); -			System.out.println("====================================="); - -			// otherwise the database connection is not initialized -			JaxBAuthConfigurationProvider.getInstance(); -			List<String> methodNames = Arrays.asList("getAllOnlineApplications", "getAllUsers", "getMOAIDConfiguration"); -			converter.extractDataViaConfigurationDBRead(methodNames); -			converter.readExtractedConfigurationDBReadData(methodNames); - -		} catch (ConfigurationException e) { -			e.printStackTrace(); -			System.out.println("Problems reading the configuration file in: " + System.getProperty(ConfigurationProvider.CONFIG_PROPERTY_NAME)); -			System.exit(1); -		} - -	} - -	public ConfigurationToJSONConverter(String pathToDBConfigPropertiesFile) throws ConfigurationException { - -		System.getProperties().setProperty("location", "file:" + pathToDBConfigPropertiesFile); -		ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml"); -		AutowireCapableBeanFactory acbFactory = context.getAutowireCapableBeanFactory(); -		acbFactory.autowireBean(this); - -	} - -	public void extractDataViaConfigurationDBRead(List<String> methodNames) { -		System.out.println("Start extracting"); -		// read objects from db and write to key-value -		for (String name : methodNames) { -			try { -				Method method = ConfigurationDBRead.class.getMethod(name); -				Object tmp = method.invoke(null, new Object[] {}); -				JsonProperty annotation = method.getAnnotation(JsonProperty.class); -				if (annotation != null) { -					configDataBase.set(annotation.value(), tmp); -				} else { -					System.out.println("Annotate Method with name: " + name); -				} -			} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException -					| InvocationTargetException e) { -				System.out.println("Problems while extracting ConfigurationDBRead data."); -			} -		} -	} - -	public void readExtractedConfigurationDBReadData(List<String> methodNames) { -		for (String name : methodNames) { -			Object tmp = configDataBase.get(name); -			System.out.println(">>> OBJECT: " + tmp); -		} -	} - -	public void writeConfigToJSONDB() { - -		try { -			// find all getter methods -			for (PropertyDescriptor pd : Introspector.getBeanInfo(NewAuthConfigurationProvider.class).getPropertyDescriptors()) { -				// check if correct methods, and not annotated with @JsonIgnore -				if ((pd.getReadMethod() != null) -						&& (!"class".equals(pd.getName())) -						&& (pd.getReadMethod().getAnnotation(JsonIgnore.class) == null)) { - -					JsonProperty name = pd.getReadMethod().getAnnotation(JsonProperty.class); -					// get result of get method -					Object tmp; -					try { -						tmp = pd.getReadMethod().invoke(configProvider); -						// convert result to JSON -						if (name != null) { -							configDataBase.set(name.value(), tmp); -						} else { -							System.out.println("CHECK if '" + pd.getDisplayName() + "' is NOT ANNOTATED"); -						} -					} catch (IllegalAccessException | InvocationTargetException e) { -						System.out.println("Problems while writing the configuration to the database."); -					} -				} -			} - -			// no static method handling needed - -		} catch (IllegalArgumentException e) { -			System.out.println("Problems while using reflection to get all getter methods."); -		} catch (IntrospectionException e) { -			System.out.println("Problems while using reflection to get all getter methods."); -		} - -	} - -	public void readConfigFromDB() { -		try { -			// find all getter methods -			for (PropertyDescriptor pd : Introspector.getBeanInfo(NewAuthConfigurationProvider.class) -					.getPropertyDescriptors()) { -				// check if correct methods, and not annotated with @JsonIgnore -				if ((pd.getReadMethod() != null) -						&& (!"class".equals(pd.getName())) -						&& (pd.getReadMethod().getAnnotation(JsonIgnore.class) == null)) { -					JsonProperty name = pd.getReadMethod().getAnnotation(JsonProperty.class); -					// get result of get method -					if (name != null) { -						System.out.println(">>> OBJECT: " + configDataBase.get(name.value())); -					} else { -						System.out.println("CHECK if '" + pd.getDisplayName() + "' is NOT ANNOTATED"); -					} -				} -			} -		} catch (IllegalArgumentException e) { -			System.out.println("Problems while using reflection to get all getter methods."); -		} catch (IntrospectionException e) { -			System.out.println("Problems while using reflection to get all getter methods."); -		} -	} - -} +//package at.gv.egovernment.moa.id.config.auth; +// +//import java.beans.IntrospectionException; +//import java.beans.Introspector; +//import java.beans.PropertyDescriptor; +//import java.lang.reflect.InvocationTargetException; +//import java.lang.reflect.Method; +//import java.util.Arrays; +//import java.util.List; +// +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +//import org.springframework.context.ApplicationContext; +//import org.springframework.context.support.ClassPathXmlApplicationContext; +// +//import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; +//import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead; +//import at.gv.egovernment.moa.id.config.ConfigurationException; +//import at.gv.egovernment.moa.id.config.ConfigurationProvider; +// +//import com.fasterxml.jackson.annotation.JsonIgnore; +//import com.fasterxml.jackson.annotation.JsonProperty; +// +//public class ConfigurationToJSONConverter { +// +//	@Autowired +//	NewAuthConfigurationProvider configProvider; +// +//	@Autowired +//	MOAIDConfiguration configDataBase; +// +//	public static void main(String[] args) { +// +//		try { +//			ConfigurationToJSONConverter converter = new ConfigurationToJSONConverter(args[0]); +//			converter.writeConfigToJSONDB(); +//			System.out.println("====================================="); +//			System.out.println("====================================="); +//			converter.readConfigFromDB(); +//			System.out.println("====================================="); +//			System.out.println("====================================="); +// +//			// otherwise the database connection is not initialized +//			JaxBAuthConfigurationProvider.getInstance(); +//			List<String> methodNames = Arrays.asList("getAllOnlineApplications", "getAllUsers", "getMOAIDConfiguration"); +//			converter.extractDataViaConfigurationDBRead(methodNames); +//			converter.readExtractedConfigurationDBReadData(methodNames); +// +//		} catch (ConfigurationException e) { +//			e.printStackTrace(); +//			System.out.println("Problems reading the configuration file in: " + System.getProperty(ConfigurationProvider.CONFIG_PROPERTY_NAME)); +//			System.exit(1); +//		} +// +//	} +// +//	public ConfigurationToJSONConverter(String pathToDBConfigPropertiesFile) throws ConfigurationException { +// +//		System.getProperties().setProperty("location", "file:" + pathToDBConfigPropertiesFile); +//		ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml"); +//		AutowireCapableBeanFactory acbFactory = context.getAutowireCapableBeanFactory(); +//		acbFactory.autowireBean(this); +// +//	} +// +//	public void extractDataViaConfigurationDBRead(List<String> methodNames) { +//		System.out.println("Start extracting"); +//		// read objects from db and write to key-value +//		for (String name : methodNames) { +//			try { +//				Method method = ConfigurationDBRead.class.getMethod(name); +//				Object tmp = method.invoke(null, new Object[] {}); +//				JsonProperty annotation = method.getAnnotation(JsonProperty.class); +//				if (annotation != null) { +//					configDataBase.set(annotation.value(), tmp); +//				} else { +//					System.out.println("Annotate Method with name: " + name); +//				} +//			} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException +//					| InvocationTargetException e) { +//				System.out.println("Problems while extracting ConfigurationDBRead data."); +//			} +//		} +//	} +// +//	public void readExtractedConfigurationDBReadData(List<String> methodNames) { +//		for (String name : methodNames) { +//			Object tmp = configDataBase.get(name); +//			System.out.println(">>> OBJECT: " + tmp); +//		} +//	} +// +//	public void writeConfigToJSONDB() { +// +//		try { +//			// find all getter methods +//			for (PropertyDescriptor pd : Introspector.getBeanInfo(NewAuthConfigurationProvider.class).getPropertyDescriptors()) { +//				// check if correct methods, and not annotated with @JsonIgnore +//				if ((pd.getReadMethod() != null) +//						&& (!"class".equals(pd.getName())) +//						&& (pd.getReadMethod().getAnnotation(JsonIgnore.class) == null)) { +// +//					JsonProperty name = pd.getReadMethod().getAnnotation(JsonProperty.class); +//					// get result of get method +//					Object tmp; +//					try { +//						tmp = pd.getReadMethod().invoke(configProvider); +//						// convert result to JSON +//						if (name != null) { +//							configDataBase.set(name.value(), tmp); +//						} else { +//							System.out.println("CHECK if '" + pd.getDisplayName() + "' is NOT ANNOTATED"); +//						} +//					} catch (IllegalAccessException | InvocationTargetException e) { +//						System.out.println("Problems while writing the configuration to the database."); +//					} +//				} +//			} +// +//			// no static method handling needed +// +//		} catch (IllegalArgumentException e) { +//			System.out.println("Problems while using reflection to get all getter methods."); +//		} catch (IntrospectionException e) { +//			System.out.println("Problems while using reflection to get all getter methods."); +//		} +// +//	} +// +//	public void readConfigFromDB() { +//		try { +//			// find all getter methods +//			for (PropertyDescriptor pd : Introspector.getBeanInfo(NewAuthConfigurationProvider.class) +//					.getPropertyDescriptors()) { +//				// check if correct methods, and not annotated with @JsonIgnore +//				if ((pd.getReadMethod() != null) +//						&& (!"class".equals(pd.getName())) +//						&& (pd.getReadMethod().getAnnotation(JsonIgnore.class) == null)) { +//					JsonProperty name = pd.getReadMethod().getAnnotation(JsonProperty.class); +//					// get result of get method +//					if (name != null) { +//						System.out.println(">>> OBJECT: " + configDataBase.get(name.value())); +//					} else { +//						System.out.println("CHECK if '" + pd.getDisplayName() + "' is NOT ANNOTATED"); +//					} +//				} +//			} +//		} catch (IllegalArgumentException e) { +//			System.out.println("Problems while using reflection to get all getter methods."); +//		} catch (IntrospectionException e) { +//			System.out.println("Problems while using reflection to get all getter methods."); +//		} +//	} +// +//} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java index 38af90ade..94fbe46c4 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/PropertyBasedAuthConfigurationProvider.java @@ -6,6 +6,7 @@ import java.io.FileNotFoundException;  import java.io.IOException;  import java.math.BigInteger;  import java.util.ArrayList; +import java.util.Arrays;  import java.util.Collection;  import java.util.Collections;  import java.util.Date; @@ -14,6 +15,8 @@ import java.util.Properties;  import org.springframework.beans.factory.annotation.Autowired; +import com.fasterxml.jackson.annotation.JsonIgnore; +  import at.gv.egovernment.moa.id.auth.MOAIDAuthConstants;  import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants;  import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; @@ -51,6 +54,7 @@ import at.gv.egovernment.moa.id.config.auth.data.ProtocolAllowed;  import at.gv.egovernment.moa.id.config.stork.STORKConfig;  import at.gv.egovernment.moa.logging.Logger;  import at.gv.egovernment.moa.util.MiscUtil; +import at.gv.util.config.EgovUtilPropertiesConfiguration;  /**   * A class providing access to the Auth Part of the MOA-ID configuration data. @@ -63,7 +67,9 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide  	private MOAIDConfiguration configuration;  	private final Properties properties = new Properties(); - +	private EgovUtilPropertiesConfiguration eGovUtilsConfig = null; +	 +	  	public PropertyBasedAuthConfigurationProvider() {  	} @@ -79,6 +85,23 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide  		try (FileInputStream in = new FileInputStream(propertiesFile);) {  			properties.load(in); +			 +		    //read eGovUtils client configuration +		    Properties eGovUtilsConfigProp = new Properties(); +		    for (Object key : properties.keySet()) { +		    	String propPrefix = "service."; +			    if (key.toString().startsWith(propPrefix+"egovutil")) { +			    	String propertyName = key.toString().substring(propPrefix.length()); +			    	eGovUtilsConfigProp.put(propertyName, properties.get(key.toString())); +			    } +			} +			if (!eGovUtilsConfigProp.isEmpty()) { +				Logger.info("Start eGovUtils client implementation configuration ..."); +				eGovUtilsConfig =  +						new EgovUtilPropertiesConfiguration(eGovUtilsConfigProp, rootConfigFileDir); +			} +			 +			  		} catch (FileNotFoundException e) {  			throw new ConfigurationException("config.03", null, e);  		} catch (IOException e) { @@ -909,15 +932,6 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide  	}  	/** -	 * Returns the current time. -	 * @return the time stamp -	 */ -	public static Date getTimeStamp() { - -		return new Date(); -	} - -	/**  	 * Returns a list of all {@link OnlineApplication}.  	 *  	 * @return list of all OnlineApplications @@ -980,4 +994,57 @@ public class PropertyBasedAuthConfigurationProvider extends ConfigurationProvide  		return result;  	} +	  //Load document service url from moa properties +	  public String getDocumentServiceUrl() { +		  String prop = properties.getProperty("stork.documentservice.url", "false"); +		  return prop;   +	  } +	   + +	  public boolean isPVPSchemaValidationActive() { +		  String prop = properties.getProperty("protocols.pvp2.schemavalidation", "true"); +		  return Boolean.valueOf(prop);	   +	  } +	   +	  /** +	   * Checks if is fakeIdL is activated. +	   * +	   * @return true, if fake IdLs are available for stork +	   */ +	  public boolean isStorkFakeIdLActive() { +		  String prop = properties.getProperty("stork.fakeIdL.active", "false"); +		  return Boolean.valueOf(prop); +	  } + +	  /** +	   * Gets the countries which will receive a fake IdL +	   * +	   * @return the countries +	   */ +	  public List<String> getStorkFakeIdLCountries() { +		  String prop = properties.getProperty("stork.fakeIdL.countries", ""); +		  return Arrays.asList(prop.replaceAll(" ", "").split(",")); +	  } + +	  /** +	   * Gets the resigning key (group) for the stork fake IdL. +	   * +	   * @return the resigning key +	   */ +	  public String getStorkFakeIdLResigningKey() { +		  String prop = properties.getProperty("stork.fakeIdL.keygroup"); +		  if (MiscUtil.isNotEmpty(prop)) +			  return prop; +		  else +			  return null; +	  } + +	  /** +	   * @return the eGovUtilsConfig +	   */ +	  @JsonIgnore +	  public EgovUtilPropertiesConfiguration geteGovUtilsConfig() { +	  	return eGovUtilsConfig; +	  } +  } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java index e794951d7..468e4a536 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java @@ -1,226 +1,226 @@ -package at.gv.egovernment.moa.id.commons.config; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Enumeration; -import java.util.List; -import java.util.Properties; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import at.gv.egovernment.moa.id.commons.config.persistence.Configuration; -import at.gv.egovernment.moa.id.commons.config.persistence.JsonMapper; -import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration; - -import com.fasterxml.jackson.core.JsonProcessingException; - -public class ConfigurationUtil { -	 -	final boolean isOverwriteData; -	 -	public ConfigurationUtil(boolean isOverwriteData){ -		this.isOverwriteData = isOverwriteData; -	} - -	/** -	 * Read an input MOAID 2 XML file, transfer it to properties and write the -	 * properties to a MOAID 3 property file. -	 *  -	 * @param inStream -	 *            the input stream to read from. -	 * @param outFile -	 *            the output file to write to. -	 * @throws JAXBException -	 */ -	public void readFromXMLFileConvertToPropertyFile(FileInputStream inStream, File outFile) throws JAXBException { - -		try (FileOutputStream outStream = new FileOutputStream(outFile);) { - -			// get config from xml file -			JAXBContext jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config"); -			Unmarshaller m = jc.createUnmarshaller(); -			MOAIDConfiguration config = (MOAIDConfiguration) m.unmarshal(inStream); - -			// serialize config to JSON properties -			Properties result = moaIdConfigToJsonProperties(config); - -			// write to output stream -			result.store(outStream, null); - -		} catch (FileNotFoundException e) { -			System.out.println("Could not find the output file."); -			System.exit(1); -		} catch (IOException e) { -			System.out.println("Could not write to the output file."); -			System.exit(1); -		} -	} - -	/** -	 * Helper method to serialize a {@link MOAIDConfiguration} to Properties -	 * with JSON encoded values. -	 *  -	 * @param config -	 *            the MOAIDConfiguration to serialize -	 * @return {@link Properties} containing the database key and the serialized -	 *         values -	 * @throws JsonProcessingException -	 *             is thrown if problem occurred while serializing one of the -	 *             database values -	 */ -	private Properties moaIdConfigToJsonProperties(MOAIDConfiguration config) throws JsonProcessingException { - -		Properties result = new Properties(); -		boolean prettyPrint = true; -		JsonMapper mapper = new JsonMapper(prettyPrint); - -		// serialize config to JSON -		String oaJson = mapper.serialize(config.getOnlineApplication()); -		String authCompGeneralJson = mapper.serialize(config.getAuthComponentGeneral()); -		String chainingModeJson = mapper.serialize(config.getChainingModes()); -		String defaultBKUJson = mapper.serialize(config.getDefaultBKUs()); -		String genericConfigJson = mapper.serialize(config.getGenericConfiguration()); -		String pvp2RefreshJson = mapper.serialize(config.getPvp2RefreshItem()); -		String slRequestTemplatesJson = mapper.serialize(config.getSLRequestTemplates()); -		String timestampJson = mapper.serialize(config.getTimestampItem()); -		String trustedCaCertJson = mapper.serialize(config.getTrustedCACertificates()); - -		// add to properties -		result.put(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, oaJson); -		result.put(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, authCompGeneralJson); -		result.put(MOAIDConfigurationConstants.CHAINING_MODES_KEY, chainingModeJson); -		result.put(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, defaultBKUJson); -		result.put(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, genericConfigJson); -		result.put(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, pvp2RefreshJson); -		result.put(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, slRequestTemplatesJson); -		result.put(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, timestampJson); -		result.put(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, trustedCaCertJson); - -		return result; -	} - -	/** -	 * Exports a key-value database to a property file, where keys are the same -	 * as in the database, and the values are serialized JSON objects. -	 *  -	 * @param inputDBConfigFilePath -	 *            the path to the database properties, for the db the data is -	 *            read from. -	 * @param outFile -	 *            the destination file for the exported data. -	 */ -	public void readFromDBWriteToFile(String inputDBConfigFilePath, File outFile) { - -		try (FileOutputStream outStream = new FileOutputStream(outFile);) { - -			Properties result = new Properties(); - -			System.getProperties().setProperty("location", "file:" + inputDBConfigFilePath); -			ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml"); -			Configuration dbConfiguration = (Configuration) context.getBean("config"); -			boolean prettyPrint = true; -			at.gv.egovernment.moa.id.commons.config.persistence.JsonMapper mapper = new JsonMapper(prettyPrint); - -			for (String key : MOAIDConfigurationConstants.getAllMOAIDConfigurationKeys()) { - -				// extract database value -				Object value = dbConfiguration.get(key); - -				// serialize value to JSON -				String json = mapper.serialize(value); - -				// add to properties -				result.setProperty(key, json); -			} - -			// write to output stream -			result.store(outStream, null); - -			System.out.println("Property configuration written to:"); -			System.out.println(outFile.getAbsolutePath()); - -		} catch (FileNotFoundException e) { -			System.out.println("Could not find the output file."); -			System.exit(1); -		} catch (IOException e) { -			System.out.println("Could not write to the output file."); -			System.exit(1); -		} -	} - -	/** -	 * Read an input property file, deserialize it's values and write them to -	 * the given database. -	 *  -	 * @param inStream -	 *            the FileInputStream to read from. -	 * @param outputDBConfigFilePath -	 *            the path to the database properties, for the db which is -	 *            written. -	 * @throws IOException -	 *             is thrown in case the properties could not be loaded from the -	 *             stream -	 */ -	public void readFromFileWriteToDB(FileInputStream inStream, String outputDBConfigFilePath) throws IOException { - -		Properties inProperties = new Properties(); -		inProperties.load(inStream); - -		System.getProperties().setProperty("location", "file:" + outputDBConfigFilePath); -		ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml"); -		Configuration dbConfiguration = (Configuration) context.getBean("config"); -		boolean prettyPrint = true; -		JsonMapper mapper = new JsonMapper(prettyPrint); - -		List<String> keys = dbConfiguration.getAllKeys(); - -		if (keys == null) { -			System.out.println("Database can not be read."); -			System.exit(1); -		} - -		if (!keys.isEmpty() && !isOverwriteData) { -			System.out.println("The database already contains configuration data."); -			System.out.println("Use force switch if you want to override data)"); -			System.exit(1); -		} - -		if (isOverwriteData) { -			// remove existing entries -			for (String key : keys) { -				dbConfiguration.set(key, null); -			} -		} - -		Enumeration<?> propertyNames = inProperties.propertyNames(); - -		while (propertyNames.hasMoreElements()) { -			String key = (String) propertyNames.nextElement(); -			// extract database value -			String json = inProperties.getProperty(key); - -			// deserialize value to object -			Object value = mapper.deserialize(json, null); - -			// add to database -			boolean result = dbConfiguration.set(key, value); -			if (!result) { -				System.out.println("Could NOT persist the configuration file's information in the database."); -			} -		} -		System.out.println("Data has been successfully written to the database."); -	} - -	private static void readFromDBWriteToDB(String inputDBConfigFilePath, String outputDBConfigFilePath) { -		//TODO: implement -	} -	 -} +//package at.gv.egovernment.moa.id.commons.config; +// +//import java.io.File; +//import java.io.FileInputStream; +//import java.io.FileNotFoundException; +//import java.io.FileOutputStream; +//import java.io.IOException; +//import java.util.Enumeration; +//import java.util.List; +//import java.util.Properties; +// +//import javax.xml.bind.JAXBContext; +//import javax.xml.bind.JAXBException; +//import javax.xml.bind.Unmarshaller; +// +//import org.springframework.context.ApplicationContext; +//import org.springframework.context.support.ClassPathXmlApplicationContext; +// +//import at.gv.egovernment.moa.id.commons.config.persistence.Configuration; +//import at.gv.egovernment.moa.id.commons.config.persistence.JsonMapper; +//import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration; +// +//import com.fasterxml.jackson.core.JsonProcessingException; +// +//public class ConfigurationUtil { +//	 +//	final boolean isOverwriteData; +//	 +//	public ConfigurationUtil(boolean isOverwriteData){ +//		this.isOverwriteData = isOverwriteData; +//	} +// +//	/** +//	 * Read an input MOAID 2 XML file, transfer it to properties and write the +//	 * properties to a MOAID 3 property file. +//	 *  +//	 * @param inStream +//	 *            the input stream to read from. +//	 * @param outFile +//	 *            the output file to write to. +//	 * @throws JAXBException +//	 */ +//	public void readFromXMLFileConvertToPropertyFile(FileInputStream inStream, File outFile) throws JAXBException { +// +//		try (FileOutputStream outStream = new FileOutputStream(outFile);) { +// +//			// get config from xml file +//			JAXBContext jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config"); +//			Unmarshaller m = jc.createUnmarshaller(); +//			MOAIDConfiguration config = (MOAIDConfiguration) m.unmarshal(inStream); +// +//			// serialize config to JSON properties +//			Properties result = moaIdConfigToJsonProperties(config); +// +//			// write to output stream +//			result.store(outStream, null); +// +//		} catch (FileNotFoundException e) { +//			System.out.println("Could not find the output file."); +//			System.exit(1); +//		} catch (IOException e) { +//			System.out.println("Could not write to the output file."); +//			System.exit(1); +//		} +//	} +// +//	/** +//	 * Helper method to serialize a {@link MOAIDConfiguration} to Properties +//	 * with JSON encoded values. +//	 *  +//	 * @param config +//	 *            the MOAIDConfiguration to serialize +//	 * @return {@link Properties} containing the database key and the serialized +//	 *         values +//	 * @throws JsonProcessingException +//	 *             is thrown if problem occurred while serializing one of the +//	 *             database values +//	 */ +//	private Properties moaIdConfigToJsonProperties(MOAIDConfiguration config) throws JsonProcessingException { +// +//		Properties result = new Properties(); +//		boolean prettyPrint = true; +//		JsonMapper mapper = new JsonMapper(prettyPrint); +// +//		// serialize config to JSON +//		String oaJson = mapper.serialize(config.getOnlineApplication()); +//		String authCompGeneralJson = mapper.serialize(config.getAuthComponentGeneral()); +//		String chainingModeJson = mapper.serialize(config.getChainingModes()); +//		String defaultBKUJson = mapper.serialize(config.getDefaultBKUs()); +//		String genericConfigJson = mapper.serialize(config.getGenericConfiguration()); +//		String pvp2RefreshJson = mapper.serialize(config.getPvp2RefreshItem()); +//		String slRequestTemplatesJson = mapper.serialize(config.getSLRequestTemplates()); +//		String timestampJson = mapper.serialize(config.getTimestampItem()); +//		String trustedCaCertJson = mapper.serialize(config.getTrustedCACertificates()); +// +//		// add to properties +//		result.put(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, oaJson); +//		result.put(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, authCompGeneralJson); +//		result.put(MOAIDConfigurationConstants.CHAINING_MODES_KEY, chainingModeJson); +//		result.put(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, defaultBKUJson); +//		result.put(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, genericConfigJson); +//		result.put(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, pvp2RefreshJson); +//		result.put(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, slRequestTemplatesJson); +//		result.put(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, timestampJson); +//		result.put(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, trustedCaCertJson); +// +//		return result; +//	} +// +//	/** +//	 * Exports a key-value database to a property file, where keys are the same +//	 * as in the database, and the values are serialized JSON objects. +//	 *  +//	 * @param inputDBConfigFilePath +//	 *            the path to the database properties, for the db the data is +//	 *            read from. +//	 * @param outFile +//	 *            the destination file for the exported data. +//	 */ +//	public void readFromDBWriteToFile(String inputDBConfigFilePath, File outFile) { +// +//		try (FileOutputStream outStream = new FileOutputStream(outFile);) { +// +//			Properties result = new Properties(); +// +//			System.getProperties().setProperty("location", "file:" + inputDBConfigFilePath); +//			ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml"); +//			Configuration dbConfiguration = (Configuration) context.getBean("config"); +//			boolean prettyPrint = true; +//			at.gv.egovernment.moa.id.commons.config.persistence.JsonMapper mapper = new JsonMapper(prettyPrint); +// +//			for (String key : MOAIDConfigurationConstants.getAllMOAIDConfigurationKeys()) { +// +//				// extract database value +//				Object value = dbConfiguration.get(key); +// +//				// serialize value to JSON +//				String json = mapper.serialize(value); +// +//				// add to properties +//				result.setProperty(key, json); +//			} +// +//			// write to output stream +//			result.store(outStream, null); +// +//			System.out.println("Property configuration written to:"); +//			System.out.println(outFile.getAbsolutePath()); +// +//		} catch (FileNotFoundException e) { +//			System.out.println("Could not find the output file."); +//			System.exit(1); +//		} catch (IOException e) { +//			System.out.println("Could not write to the output file."); +//			System.exit(1); +//		} +//	} +// +//	/** +//	 * Read an input property file, deserialize it's values and write them to +//	 * the given database. +//	 *  +//	 * @param inStream +//	 *            the FileInputStream to read from. +//	 * @param outputDBConfigFilePath +//	 *            the path to the database properties, for the db which is +//	 *            written. +//	 * @throws IOException +//	 *             is thrown in case the properties could not be loaded from the +//	 *             stream +//	 */ +//	public void readFromFileWriteToDB(FileInputStream inStream, String outputDBConfigFilePath) throws IOException { +// +//		Properties inProperties = new Properties(); +//		inProperties.load(inStream); +// +//		System.getProperties().setProperty("location", "file:" + outputDBConfigFilePath); +//		ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml"); +//		Configuration dbConfiguration = (Configuration) context.getBean("config"); +//		boolean prettyPrint = true; +//		JsonMapper mapper = new JsonMapper(prettyPrint); +// +//		List<String> keys = dbConfiguration.getAllKeys(); +// +//		if (keys == null) { +//			System.out.println("Database can not be read."); +//			System.exit(1); +//		} +// +//		if (!keys.isEmpty() && !isOverwriteData) { +//			System.out.println("The database already contains configuration data."); +//			System.out.println("Use force switch if you want to override data)"); +//			System.exit(1); +//		} +// +//		if (isOverwriteData) { +//			// remove existing entries +//			for (String key : keys) { +//				dbConfiguration.set(key, null); +//			} +//		} +// +//		Enumeration<?> propertyNames = inProperties.propertyNames(); +// +//		while (propertyNames.hasMoreElements()) { +//			String key = (String) propertyNames.nextElement(); +//			// extract database value +//			String json = inProperties.getProperty(key); +// +//			// deserialize value to object +//			Object value = mapper.deserialize(json, null); +// +//			// add to database +//			boolean result = dbConfiguration.set(key, value); +//			if (!result) { +//				System.out.println("Could NOT persist the configuration file's information in the database."); +//			} +//		} +//		System.out.println("Data has been successfully written to the database."); +//	} +// +//	private static void readFromDBWriteToDB(String inputDBConfigFilePath, String outputDBConfigFilePath) { +//		//TODO: implement +//	} +//	 +//} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java index 4e8c7dffd..32dd97148 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java @@ -1,103 +1,103 @@ -package at.gv.egovernment.moa.id.commons.config; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; - -import javax.xml.bind.JAXBException; - -import at.gv.egovernment.moa.id.commons.config.cli.MOAIDConfCLI; -import at.gv.egovernment.moa.id.commons.config.cli.MigrateConfigurationParams; - -/** - * CLI tool which is able to perform the following tasks: - * <ul> - * <li>transform a MoaID 2 XML configuration XML file to a MoaID 3 property file - * </li> - * <li>read a property file and transfer it's content to a database</li> - * <li>write the content of a database to a property file</li> - * </ul> - */ -public class MigrateConfiguration { - -	public static void main(String[] args) { - -		MOAIDConfCLI cli = new MOAIDConfCLI(); -		MigrateConfigurationParams parsedParameters = cli.parse(args); - -		// consider settings of force switch -		boolean isOverwriteData = parsedParameters.isOverwriteData(); -		ConfigurationUtil configUtil = new ConfigurationUtil(isOverwriteData); - -		if (!parsedParameters.isInputDB() && (parsedParameters.getInputTarget() != null)) { -			// read input from file -			workWithInputFromFile(parsedParameters.getInputTarget(), parsedParameters, configUtil); - -		} else if (parsedParameters.getInputDBConfig() != null) { -			// read input from database -			workWithImputFromDB(parsedParameters, configUtil); - -		} else { -			System.exit(1); -		} -	} - -	/** -	 * Handle the case where input from a file is read. -	 *  -	 * @param inputFileUrl -	 *            the url of the input file. -	 * @param parsedParameters -	 *            the command line parameters. -	 * @param configUtil -	 *            the class for working with the configuration. -	 */ -	private static void workWithInputFromFile(String inputFileUrl, MigrateConfigurationParams parsedParameters, -			ConfigurationUtil configUtil) { -		File inFile = new File(inputFileUrl); -		try (FileInputStream inStream = new FileInputStream(inFile);) { - -			if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) { -				// input from file and output to a file is desired -				File outFile = new File(parsedParameters.getOutputFile()); -				configUtil.readFromXMLFileConvertToPropertyFile(inStream, outFile); - -			} else if (parsedParameters.getOutputDBConfig() != null) { -				// input from file and output to a database is desired -				configUtil.readFromFileWriteToDB(inStream, parsedParameters.getOutputDBConfig()); -			} -		} catch (JAXBException e) { -			System.out.println("MOA-ID XML configuration can not be loaded from given file."); -			System.exit(1); -		} catch (FileNotFoundException e) { -			System.out.println("Could not find the input file."); -			System.exit(1); -		} catch (IOException e) { -			System.out.println("Could not read from the input file."); -			System.exit(1); -		} -	} - -	/** -	 * Handle the case where input is read from a database. -	 *  -	 * @param parsedParameters -	 *            the command line parameters. -	 * @param configUtil -	 *            the class for working with the configuration. -	 */ -	private static void workWithImputFromDB(MigrateConfigurationParams parsedParameters, ConfigurationUtil configUtil) { -		if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) { -			// input from database and output to a file is desired -			File outFile = new File(parsedParameters.getOutputFile()); -			String inputDBConfigFilePath = parsedParameters.getInputDBConfig(); -			configUtil.readFromDBWriteToFile(inputDBConfigFilePath, outFile); - -		} else if (parsedParameters.getOutputDBConfig() != null) { -			// input from database and output to a database is desired -			// configUtil.readFromDBWriteToDB(inDBConfigFilePath, -			// outDBConfigFilePath); -		} -	} -}
\ No newline at end of file +//package at.gv.egovernment.moa.id.commons.config; +// +//import java.io.File; +//import java.io.FileInputStream; +//import java.io.FileNotFoundException; +//import java.io.IOException; +// +//import javax.xml.bind.JAXBException; +// +//import at.gv.egovernment.moa.id.commons.config.cli.MOAIDConfCLI; +//import at.gv.egovernment.moa.id.commons.config.cli.MigrateConfigurationParams; +// +///** +// * CLI tool which is able to perform the following tasks: +// * <ul> +// * <li>transform a MoaID 2 XML configuration XML file to a MoaID 3 property file +// * </li> +// * <li>read a property file and transfer it's content to a database</li> +// * <li>write the content of a database to a property file</li> +// * </ul> +// */ +//public class MigrateConfiguration { +// +//	public static void main(String[] args) { +// +//		MOAIDConfCLI cli = new MOAIDConfCLI(); +//		MigrateConfigurationParams parsedParameters = cli.parse(args); +// +//		// consider settings of force switch +//		boolean isOverwriteData = parsedParameters.isOverwriteData(); +//		ConfigurationUtil configUtil = new ConfigurationUtil(isOverwriteData); +// +//		if (!parsedParameters.isInputDB() && (parsedParameters.getInputTarget() != null)) { +//			// read input from file +//			workWithInputFromFile(parsedParameters.getInputTarget(), parsedParameters, configUtil); +// +//		} else if (parsedParameters.getInputDBConfig() != null) { +//			// read input from database +//			workWithImputFromDB(parsedParameters, configUtil); +// +//		} else { +//			System.exit(1); +//		} +//	} +// +//	/** +//	 * Handle the case where input from a file is read. +//	 *  +//	 * @param inputFileUrl +//	 *            the url of the input file. +//	 * @param parsedParameters +//	 *            the command line parameters. +//	 * @param configUtil +//	 *            the class for working with the configuration. +//	 */ +//	private static void workWithInputFromFile(String inputFileUrl, MigrateConfigurationParams parsedParameters, +//			ConfigurationUtil configUtil) { +//		File inFile = new File(inputFileUrl); +//		try (FileInputStream inStream = new FileInputStream(inFile);) { +// +//			if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) { +//				// input from file and output to a file is desired +//				File outFile = new File(parsedParameters.getOutputFile()); +//				configUtil.readFromXMLFileConvertToPropertyFile(inStream, outFile); +// +//			} else if (parsedParameters.getOutputDBConfig() != null) { +//				// input from file and output to a database is desired +//				configUtil.readFromFileWriteToDB(inStream, parsedParameters.getOutputDBConfig()); +//			} +//		} catch (JAXBException e) { +//			System.out.println("MOA-ID XML configuration can not be loaded from given file."); +//			System.exit(1); +//		} catch (FileNotFoundException e) { +//			System.out.println("Could not find the input file."); +//			System.exit(1); +//		} catch (IOException e) { +//			System.out.println("Could not read from the input file."); +//			System.exit(1); +//		} +//	} +// +//	/** +//	 * Handle the case where input is read from a database. +//	 *  +//	 * @param parsedParameters +//	 *            the command line parameters. +//	 * @param configUtil +//	 *            the class for working with the configuration. +//	 */ +//	private static void workWithImputFromDB(MigrateConfigurationParams parsedParameters, ConfigurationUtil configUtil) { +//		if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) { +//			// input from database and output to a file is desired +//			File outFile = new File(parsedParameters.getOutputFile()); +//			String inputDBConfigFilePath = parsedParameters.getInputDBConfig(); +//			configUtil.readFromDBWriteToFile(inputDBConfigFilePath, outFile); +// +//		} else if (parsedParameters.getOutputDBConfig() != null) { +//			// input from database and output to a database is desired +//			// configUtil.readFromDBWriteToDB(inDBConfigFilePath, +//			// outDBConfigFilePath); +//		} +//	} +//}
\ No newline at end of file diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java index f6066d68f..432991f33 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java @@ -1,182 +1,182 @@ -package at.gv.egovernment.moa.id.commons.db; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; - -import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; -import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; -import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; -import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; -import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; -import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; -import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * This class is used to extract information from a legacy moa-id database. - */ -public class ConfigurationFromDBExtractor { - -	/** -	 * This class should not be instantiated. -	 */ -	private ConfigurationFromDBExtractor() { -	} - -	/** -	 * Helper method, to query for a single value. NOTE: returns {@code null} if -	 * there is no result, more than one result or if an exception is thrown -	 * while querying the database. -	 *  -	 * @param queryString -	 *            a jpa query string. -	 * @param clazz -	 *            the class type of the expected result. -	 * @return the result of the query or {@code null}. -	 */ -	private static <T> T getSingleValue(String queryString, Class<T> clazz) { -		T result = null; -		EntityManager session = ConfigurationDBUtils.getCurrentSession(); -		TypedQuery<T> query = session.createQuery(queryString, clazz); -		try { -			result = query.getSingleResult(); -		} catch (Exception e) { -			return null; -		} -		return result; -	} - -	/** -	 * Helper method, to query for a a list of values. NOTE: the returned list -	 * may be empty but is never {@code null}. -	 *  -	 * @param queryString -	 *            a jpa query string. -	 * @param clazz -	 *            the class type of the elements the expected result list. -	 * @return a list with the result of the query or an empty list. -	 */ -	private static <T> List<T> getListOfValues(String queryString, Class<T> clazz) { -		List<T> result = new ArrayList<T>(); -		EntityManager session = ConfigurationDBUtils.getCurrentSession(); -		TypedQuery<T> query = session.createQuery(queryString, clazz); -		try { -			result = query.getResultList(); -		} catch (Exception e) { -			return new ArrayList<T>(); -		} -		return result; -	} - -	/** -	 * Extracts an {@link AuthComponentGeneral} from the database. NOTE: returns -	 * {@code null} if there is no result, more than one result or if an -	 * exception is thrown while querying the database. -	 *  -	 * @return an AuthComponentgeneral or {@code null}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY) -	public static AuthComponentGeneral getAuthComponentGeneral() { -		return getSingleValue("from AuthComponentGeneral", AuthComponentGeneral.class); -	} - -	/** -	 * Extracts an {@link AuthComponentGeneral} from the database. NOTE: returns -	 * {@code null} if there is no result, more than one result or if an -	 * exception is thrown while querying the database. -	 *  -	 * @return an AuthComponentgeneral or {@code null}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.CHAINING_MODES_KEY) -	public static ChainingModes getChainingModes() { -		return (ChainingModes) getSingleValue("from ChainingModes", ChainingModes.class); -	} - -	/** -	 * Extracts a list of {@link OnlineApplication} from the database. NOTE: the -	 * returned list may be empty but is never {@code null}. -	 *  -	 * @return a list of {@link OnlineApplication}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY) -	public static List<OnlineApplication> getOnlineApplications() { -		return getListOfValues("from OnlineApplication", OnlineApplication.class); -	} - -	/** -	 * Extracts a list of {@link GenericConfiguration} from the database. NOTE: -	 * the returned list may be empty but is never {@code null}. -	 *  -	 * @return a list of {@link GenericConfiguration}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY) -	public static List<GenericConfiguration> getGenericConfigurations() { -		return getListOfValues("from GenericConfiguration", GenericConfiguration.class); -	} - -	/** -	 * Extracts the trusted CA-certificates from the database. NOTE: returns -	 * {@code null} if there is no result, more than one result or if an -	 * exception is thrown while querying the database. -	 *  -	 * @return the trusted CA-certificates or {@code null}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY) -	public static String getTrustedCACertificates() { -		return getSingleValue("select trustedCACertificates from MOAIDConfiguration", String.class); -	} - -	/** -	 * Extracts a {@link DefaultBKUs} from the database. NOTE: returns -	 * {@code null} if there is no result, more than one result or if an -	 * exception is thrown while querying the database. -	 *  -	 * @return a DefaultBKUs or {@code null}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY) -	public static DefaultBKUs getDefaultBKUs() { -		return getSingleValue("select defaultBKUs from MOAIDConfiguration", DefaultBKUs.class); -	} - -	/** -	 * Extracts a {@link SLRequestTemplates} from the database. NOTE: returns -	 * {@code null} if there is no result, more than one result or if an -	 * exception is thrown while querying the database. -	 *  -	 * @return a SLRequestTemplates or {@code null}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY) -	public static SLRequestTemplates getSLRequestTemplates() { -		return getSingleValue("select SLRequestTemplates from MOAIDConfiguration", SLRequestTemplates.class); -	} - -	/** -	 * Extracts the moa-id timestamp (last update) from the database. NOTE: -	 * returns {@code null} if there is no result, more than one result or if an -	 * exception is thrown while querying the database. -	 *  -	 * @return the moa-id timestamp (last update) or {@code null}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY) -	public static Date getTimeStampItem() { -		return getSingleValue("select timestampItem from MOAIDConfiguration", Date.class); -	} - -	/** -	 * Extracts the date of the last pvp2refresh from the database. NOTE: -	 * returns {@code null} if there is no result, more than one result or if an -	 * exception is thrown while querying the database. -	 *  -	 * @return the date of the last pvp2refresh or {@code null}. -	 */ -	@JsonProperty(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY) -	public static Date getPvp2RefreshItem() { -		return getSingleValue("select pvp2RefreshItem from MOAIDConfiguration", Date.class); -	} - -} +//package at.gv.egovernment.moa.id.commons.db; +// +//import java.util.ArrayList; +//import java.util.Date; +//import java.util.List; +// +//import javax.persistence.EntityManager; +//import javax.persistence.TypedQuery; +// +//import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; +//import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; +//import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; +//import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; +//import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; +//import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; +//import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; +// +//import com.fasterxml.jackson.annotation.JsonProperty; +// +///** +// * This class is used to extract information from a legacy moa-id database. +// */ +//public class ConfigurationFromDBExtractor { +// +//	/** +//	 * This class should not be instantiated. +//	 */ +//	private ConfigurationFromDBExtractor() { +//	} +// +//	/** +//	 * Helper method, to query for a single value. NOTE: returns {@code null} if +//	 * there is no result, more than one result or if an exception is thrown +//	 * while querying the database. +//	 *  +//	 * @param queryString +//	 *            a jpa query string. +//	 * @param clazz +//	 *            the class type of the expected result. +//	 * @return the result of the query or {@code null}. +//	 */ +//	private static <T> T getSingleValue(String queryString, Class<T> clazz) { +//		T result = null; +//		EntityManager session = ConfigurationDBUtils.getCurrentSession(); +//		TypedQuery<T> query = session.createQuery(queryString, clazz); +//		try { +//			result = query.getSingleResult(); +//		} catch (Exception e) { +//			return null; +//		} +//		return result; +//	} +// +//	/** +//	 * Helper method, to query for a a list of values. NOTE: the returned list +//	 * may be empty but is never {@code null}. +//	 *  +//	 * @param queryString +//	 *            a jpa query string. +//	 * @param clazz +//	 *            the class type of the elements the expected result list. +//	 * @return a list with the result of the query or an empty list. +//	 */ +//	private static <T> List<T> getListOfValues(String queryString, Class<T> clazz) { +//		List<T> result = new ArrayList<T>(); +//		EntityManager session = ConfigurationDBUtils.getCurrentSession(); +//		TypedQuery<T> query = session.createQuery(queryString, clazz); +//		try { +//			result = query.getResultList(); +//		} catch (Exception e) { +//			return new ArrayList<T>(); +//		} +//		return result; +//	} +// +//	/** +//	 * Extracts an {@link AuthComponentGeneral} from the database. NOTE: returns +//	 * {@code null} if there is no result, more than one result or if an +//	 * exception is thrown while querying the database. +//	 *  +//	 * @return an AuthComponentgeneral or {@code null}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY) +//	public static AuthComponentGeneral getAuthComponentGeneral() { +//		return getSingleValue("from AuthComponentGeneral", AuthComponentGeneral.class); +//	} +// +//	/** +//	 * Extracts an {@link AuthComponentGeneral} from the database. NOTE: returns +//	 * {@code null} if there is no result, more than one result or if an +//	 * exception is thrown while querying the database. +//	 *  +//	 * @return an AuthComponentgeneral or {@code null}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.CHAINING_MODES_KEY) +//	public static ChainingModes getChainingModes() { +//		return (ChainingModes) getSingleValue("from ChainingModes", ChainingModes.class); +//	} +// +//	/** +//	 * Extracts a list of {@link OnlineApplication} from the database. NOTE: the +//	 * returned list may be empty but is never {@code null}. +//	 *  +//	 * @return a list of {@link OnlineApplication}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY) +//	public static List<OnlineApplication> getOnlineApplications() { +//		return getListOfValues("from OnlineApplication", OnlineApplication.class); +//	} +// +//	/** +//	 * Extracts a list of {@link GenericConfiguration} from the database. NOTE: +//	 * the returned list may be empty but is never {@code null}. +//	 *  +//	 * @return a list of {@link GenericConfiguration}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY) +//	public static List<GenericConfiguration> getGenericConfigurations() { +//		return getListOfValues("from GenericConfiguration", GenericConfiguration.class); +//	} +// +//	/** +//	 * Extracts the trusted CA-certificates from the database. NOTE: returns +//	 * {@code null} if there is no result, more than one result or if an +//	 * exception is thrown while querying the database. +//	 *  +//	 * @return the trusted CA-certificates or {@code null}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY) +//	public static String getTrustedCACertificates() { +//		return getSingleValue("select trustedCACertificates from MOAIDConfiguration", String.class); +//	} +// +//	/** +//	 * Extracts a {@link DefaultBKUs} from the database. NOTE: returns +//	 * {@code null} if there is no result, more than one result or if an +//	 * exception is thrown while querying the database. +//	 *  +//	 * @return a DefaultBKUs or {@code null}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY) +//	public static DefaultBKUs getDefaultBKUs() { +//		return getSingleValue("select defaultBKUs from MOAIDConfiguration", DefaultBKUs.class); +//	} +// +//	/** +//	 * Extracts a {@link SLRequestTemplates} from the database. NOTE: returns +//	 * {@code null} if there is no result, more than one result or if an +//	 * exception is thrown while querying the database. +//	 *  +//	 * @return a SLRequestTemplates or {@code null}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY) +//	public static SLRequestTemplates getSLRequestTemplates() { +//		return getSingleValue("select SLRequestTemplates from MOAIDConfiguration", SLRequestTemplates.class); +//	} +// +//	/** +//	 * Extracts the moa-id timestamp (last update) from the database. NOTE: +//	 * returns {@code null} if there is no result, more than one result or if an +//	 * exception is thrown while querying the database. +//	 *  +//	 * @return the moa-id timestamp (last update) or {@code null}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY) +//	public static Date getTimeStampItem() { +//		return getSingleValue("select timestampItem from MOAIDConfiguration", Date.class); +//	} +// +//	/** +//	 * Extracts the date of the last pvp2refresh from the database. NOTE: +//	 * returns {@code null} if there is no result, more than one result or if an +//	 * exception is thrown while querying the database. +//	 *  +//	 * @return the date of the last pvp2refresh or {@code null}. +//	 */ +//	@JsonProperty(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY) +//	public static Date getPvp2RefreshItem() { +//		return getSingleValue("select pvp2RefreshItem from MOAIDConfiguration", Date.class); +//	} +// +//} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java index 64d8e9d80..66143efad 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java @@ -1,428 +1,428 @@ -package at.gv.egovernment.moa.id.commons.db; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; - -import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; -import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; -import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; -import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; -import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; -import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; -import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; -import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; -import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; -import at.gv.egovernment.moa.logging.Logger; - -/** - *  - * - */ -public class NewConfigurationDBRead { - -	private static MOAIDConfiguration conf; - -	@Autowired(required = true) -	public void setConfiguration(MOAIDConfiguration conf) { -		// https://jira.spring.io/browse/SPR-3845 -		NewConfigurationDBRead.conf = conf; -	} - -	@SuppressWarnings("unchecked") -	public static <T extends Iterable<?>> T nullGuard(T item) { -		if (item == null) { -			return (T) Collections.emptyList(); -		} else { -			return item; -		} -	} - -	/** -	 *  -	 * @return -	 */ -	public static List<UserDatabase> getAllUsers() { -		Logger.trace("Get All Users from database."); - -		// select userdatabase from UserDatabase userdatabase -		List<UserDatabase> result = conf.getList("getAllUsers", UserDatabase.class); -		if (result.size() == 0) { -			Logger.trace("No entries found."); -			return null; -		} - -		return result; -	} - -	/** -	 *  -	 * @return -	 */ -	public static List<OnlineApplication> getAllOnlineApplications() { -		Logger.trace("Get All OnlineApplications from database."); - -		// select onlineapplication from OnlineApplication onlineapplication -		return conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class); - -	} - -	/** -	 *  -	 * @return -	 */ -	public static List<OnlineApplication> getAllNewOnlineApplications() { -		Logger.trace("Get All New OnlineApplications from database."); - -		// select onlineapplication from OnlineApplication onlineapplication -		// where onlineapplication.isActive = '0' and onlineapplication.isAdminRequired = '1' -		List<OnlineApplication> result = new ArrayList<OnlineApplication>(); -		List<OnlineApplication> allOAs = getAllOnlineApplications(); - -		for (OnlineApplication oa : nullGuard(allOAs)) { -			if (!oa.isIsActive() && oa.isIsAdminRequired()) { -				result.add(oa); -			} -		} - -		if (result.size() == 0) { -			Logger.trace("No entries found."); -			return null; -		} - -		return result; -	} - -	/** -	 *  -	 * @return -	 */ -	public static at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration getMOAIDConfiguration() { -		Logger.trace("Load MOAID Configuration from database."); - -		AuthComponentGeneral authComponent = (AuthComponentGeneral) conf.get(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, -				AuthComponentGeneral.class); - -		ChainingModes chainingModes = (ChainingModes) conf.get(MOAIDConfigurationConstants.CHAINING_MODES_KEY, ChainingModes.class); -		List<GenericConfiguration> genericConfigurations = (List<GenericConfiguration>) conf.getList( -				MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, GenericConfiguration.class); -		String trustedCaCertificates = (String) conf.get(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, String.class); -		DefaultBKUs defaultBKUs = (DefaultBKUs) conf.get(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, DefaultBKUs.class); -		SLRequestTemplates slrRequestRemplates = (SLRequestTemplates) conf.get(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, -				SLRequestTemplates.class); -		Date timeStamp = (Date) conf.get(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, Date.class); -		Date pvp2Refresh = (Date) conf.get(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, Date.class); - -		// if (authComponent == null || chainingModes == null || trustedCaCertificates == null || defaultBKUs == null -		// || slrRequestRemplates == null || timeStamp == null || pvp2Refresh == null -		// -		// ) { -		// // TODO: is there a better approach in case of error? -		// Logger.trace("Not all necessary data available. Create fresh instance."); -		// return new MOAIDConfiguration(); -		// } - -		// select moaidconfiguration from MOAIDConfiguration moaidconfiguration -		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration result = new at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration(); -		result.setAuthComponentGeneral(authComponent); -		result.setChainingModes(chainingModes); -		result.setGenericConfiguration(genericConfigurations); -		result.setTrustedCACertificates(trustedCaCertificates); -		result.setDefaultBKUs(defaultBKUs); -		result.setSLRequestTemplates(slrRequestRemplates); -		result.setTimestampItem(timeStamp); -		result.setPvp2RefreshItem(pvp2Refresh); - -		return result; -	} - -	/** -	 *  -	 * @return -	 */ -	public static List<OnlineApplication> getAllActiveOnlineApplications() { -		Logger.trace("Get All New OnlineApplications from database."); - -		// select onlineapplication from OnlineApplication onlineapplication -		// where onlineapplication.isActive = '1' -		List<OnlineApplication> result = new ArrayList<OnlineApplication>(); -		List<OnlineApplication> allOAs = getAllOnlineApplications(); - -		for (OnlineApplication oa : nullGuard(allOAs)) { -			if (oa.isIsActive()) { -				result.add(oa); -			} -		} - -		if (result.size() == 0) { -			Logger.trace("No entries found."); -			return null; -		} - -		return result; -	} - -	/** -	 *  -	 * @param id -	 * @return -	 */ -	public static OnlineApplication getActiveOnlineApplication(String id) { -		Logger.trace("Getting Active OnlineApplication with ID " + id + " from database."); - -		// select onlineapplication from OnlineApplication onlineapplication -		// where onlineapplication.publicURLPrefix = -		// SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) and  onlineapplication.isActive = '1' -		OnlineApplication result = null; -		List<OnlineApplication> allActiveOAs = getAllActiveOnlineApplications(); - -		for (OnlineApplication oa : nullGuard(allActiveOAs)) { -			String publicUrlPrefix = oa.getPublicURLPrefix(); -			if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { -				if ((id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix))) { -					if (result != null) { -						Logger.warn("OAIdentifier match to more then one DB-entry!"); -						return null; -					} else { -						result = oa; -					} -				} -			} -		} - -		return result; -	} - -	/** -	 *  -	 * @param dbid -	 * @return -	 */ -	public static OnlineApplication getOnlineApplication(long dbid) { -		Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database."); - -		// select onlineapplication from OnlineApplication onlineapplication where onlineapplication.hjid = :id -		OnlineApplication result = null; -		List<OnlineApplication> allOAs = getAllOnlineApplications(); - -		for (OnlineApplication oa : nullGuard(allOAs)) { -			if (oa.getHjid() == dbid) { -				result = oa; -				break; -			} -		} - -		return result; -	} - -	/** -	 *  -	 * @param id -	 * @return -	 */ -	public static OnlineApplication getOnlineApplication(String id) { -		Logger.trace("Getting OnlineApplication with ID " + id + " from database."); - -		// select onlineapplication from OnlineApplication onlineapplication -		// where onlineapplication.publicURLPrefix = SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) -		OnlineApplication result = null; -		List<OnlineApplication> allOAs = getAllOnlineApplications(); - -		for (OnlineApplication oa : nullGuard(allOAs)) { -			String publicUrlPrefix = oa.getPublicURLPrefix(); -			if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { -				if (id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix)) { -					if (result != null) { -						Logger.warn("OAIdentifier match to more then one DB-entry!"); -						return null; -					} else { -						result = oa; -					} -				} -			} -		} - -		return result; -	} - -	/** -	 *  -	 * @param id -	 * @return -	 */ -	public static List<OnlineApplication> searchOnlineApplications(String id) { -		Logger.trace("Getting OnlineApplication with ID " + id + " from database."); - -		// select onlineapplication from OnlineApplication onlineapplication -		// where onlineapplication.friendlyName like :id -		List<OnlineApplication> result = new ArrayList<OnlineApplication>(); -		List<OnlineApplication> allOAs = getAllOnlineApplications(); - -		for (OnlineApplication oa : nullGuard(allOAs)) { -			if (id.equals(oa.getFriendlyName())) { -				result.add(oa); -			} -		} - -		if (result.size() == 0) { -			Logger.trace("No entries found."); -			return null; -		} -		 -		return result; -	} - -	/** -	 *  -	 * @return -	 */ -	public static List<UserDatabase> getAllOpenUsersRequests() { -		Logger.trace("Get all new Users from Database"); - -		// select userdatabase from UserDatabase userdatabase -		// where userdatabase.userRequestTokken is not null -		// and userdatabase.isAdminRequest = '1' and userdatabase.isMailAddressVerified = '0' -		List<UserDatabase> result = new ArrayList<UserDatabase>(); -		List<UserDatabase> allUsers = getAllUsers(); - -		for (UserDatabase user : nullGuard(allUsers)) { -			// TODO check result of query "... userdatabase.userRequestTokken is not null" if Tokken is null -> (null, "NULL", "", ... ?) -			if ((user.getUserRequestTokken() != null && !user.getUserRequestTokken().isEmpty() && !user.getUserRequestTokken().equals("NULL")) -					&& (user.isIsAdminRequest()) && (!user.isIsMailAddressVerified())) { -				result.add(user); -			} -		} - -		if (result.size() == 0) { -			Logger.trace("No entries found."); -			return null; -		} - -		return result; -	} - -	/** -	 *  -	 * @param tokken -	 * @return -	 */ -	public static UserDatabase getNewUserWithTokken(String tokken) { -		Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); - -		// select userdatabase from UserDatabase userdatabase where userdatabase.userRequestTokken = :tokken -		UserDatabase result = null; -		List<UserDatabase> allUsers = getAllUsers(); - -		for (UserDatabase user : nullGuard(allUsers)) { -			if (user.getUserRequestTokken().equals(tokken)) { -				result = user; -				break; -			} -		} - -		return result; -	} - -	/** -	 *  -	 * @param id -	 * @return -	 */ -	public static UserDatabase getUsersWithOADBID(long id) { -		Logger.trace("Getting Userinformation with OADBID " + id + " from database."); - -		// select userdatabase from UserDatabase userdatabase -		// inner join userdatabase.onlineApplication oa where oa.hjid = :id -		UserDatabase result = null; -		List<UserDatabase> allUsers = getAllUsers(); - -		boolean quit = false; -		for (UserDatabase user : nullGuard(allUsers)) { - -			for (OnlineApplication oa : user.getOnlineApplication()) { - -				if (oa.getHjid() == id) { -					result = user; -					quit = true; -					break; -				} -			} - -			if (quit) { -				break; -			} -		} - -		return result; -	} - -	/** -	 *  -	 * @param id -	 * @return -	 */ -	public static UserDatabase getUserWithID(long id) { -		Logger.trace("Getting Userinformation with ID " + id + " from database."); - -		// select userdatabase from UserDatabase userdatabase where userdatabase.hjid = :id -		UserDatabase result = null; -		List<UserDatabase> allUsers = getAllUsers(); - -		for (UserDatabase user : nullGuard(allUsers)) { -			if (user.getHjid() == id) { -				result = user; -				break; -			} -		} - -		return result; -	} - -	/** -	 *  -	 * @param username -	 * @return -	 */ -	public static UserDatabase getUserWithUserName(String username) { -		Logger.trace("Getting Userinformation with ID " + username + " from database."); - -		// select userdatabase from UserDatabase userdatabase where userdatabase.username = :username -		UserDatabase result = null; -		List<UserDatabase> allUsers = getAllUsers(); - -		for (UserDatabase user : nullGuard(allUsers)) { -			if (user.getUsername().equals(username)) { -				result = user; -				break; -			} -		} - -		return result; -	} - -	/** -	 *  -	 * @param bpkwbpk -	 * @return -	 */ -	public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { -		Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); - -		// select userdatabase from UserDatabase userdatabase where userdatabase.bpk = :bpk -		UserDatabase result = null; -		List<UserDatabase> allUsers = getAllUsers(); - -		for (UserDatabase user : nullGuard(allUsers)) { -			if (user.getBpk().equals(bpkwbpk)) { -				result = user; -				break; -			} -		} - -		return result; -	} - -} +//package at.gv.egovernment.moa.id.commons.db; +// +//import java.util.ArrayList; +//import java.util.Collections; +//import java.util.Date; +//import java.util.List; +// +//import org.springframework.beans.factory.annotation.Autowired; +// +//import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; +//import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; +//import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; +//import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; +//import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; +//import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; +//import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; +//import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; +//import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; +//import at.gv.egovernment.moa.logging.Logger; +// +///** +// *  +// * +// */ +//public class NewConfigurationDBRead { +// +//	private static MOAIDConfiguration conf; +// +//	@Autowired(required = true) +//	public void setConfiguration(MOAIDConfiguration conf) { +//		// https://jira.spring.io/browse/SPR-3845 +//		NewConfigurationDBRead.conf = conf; +//	} +// +//	@SuppressWarnings("unchecked") +//	public static <T extends Iterable<?>> T nullGuard(T item) { +//		if (item == null) { +//			return (T) Collections.emptyList(); +//		} else { +//			return item; +//		} +//	} +// +//	/** +//	 *  +//	 * @return +//	 */ +//	public static List<UserDatabase> getAllUsers() { +//		Logger.trace("Get All Users from database."); +// +//		// select userdatabase from UserDatabase userdatabase +//		List<UserDatabase> result = conf.getList("getAllUsers", UserDatabase.class); +//		if (result.size() == 0) { +//			Logger.trace("No entries found."); +//			return null; +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @return +//	 */ +//	public static List<OnlineApplication> getAllOnlineApplications() { +//		Logger.trace("Get All OnlineApplications from database."); +// +//		// select onlineapplication from OnlineApplication onlineapplication +//		return conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class); +// +//	} +// +//	/** +//	 *  +//	 * @return +//	 */ +//	public static List<OnlineApplication> getAllNewOnlineApplications() { +//		Logger.trace("Get All New OnlineApplications from database."); +// +//		// select onlineapplication from OnlineApplication onlineapplication +//		// where onlineapplication.isActive = '0' and onlineapplication.isAdminRequired = '1' +//		List<OnlineApplication> result = new ArrayList<OnlineApplication>(); +//		List<OnlineApplication> allOAs = getAllOnlineApplications(); +// +//		for (OnlineApplication oa : nullGuard(allOAs)) { +//			if (!oa.isIsActive() && oa.isIsAdminRequired()) { +//				result.add(oa); +//			} +//		} +// +//		if (result.size() == 0) { +//			Logger.trace("No entries found."); +//			return null; +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @return +//	 */ +//	public static at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration getMOAIDConfiguration() { +//		Logger.trace("Load MOAID Configuration from database."); +// +//		AuthComponentGeneral authComponent = (AuthComponentGeneral) conf.get(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, +//				AuthComponentGeneral.class); +// +//		ChainingModes chainingModes = (ChainingModes) conf.get(MOAIDConfigurationConstants.CHAINING_MODES_KEY, ChainingModes.class); +//		List<GenericConfiguration> genericConfigurations = (List<GenericConfiguration>) conf.getList( +//				MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, GenericConfiguration.class); +//		String trustedCaCertificates = (String) conf.get(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, String.class); +//		DefaultBKUs defaultBKUs = (DefaultBKUs) conf.get(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, DefaultBKUs.class); +//		SLRequestTemplates slrRequestRemplates = (SLRequestTemplates) conf.get(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, +//				SLRequestTemplates.class); +//		Date timeStamp = (Date) conf.get(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, Date.class); +//		Date pvp2Refresh = (Date) conf.get(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, Date.class); +// +//		// if (authComponent == null || chainingModes == null || trustedCaCertificates == null || defaultBKUs == null +//		// || slrRequestRemplates == null || timeStamp == null || pvp2Refresh == null +//		// +//		// ) { +//		// // TODO: is there a better approach in case of error? +//		// Logger.trace("Not all necessary data available. Create fresh instance."); +//		// return new MOAIDConfiguration(); +//		// } +// +//		// select moaidconfiguration from MOAIDConfiguration moaidconfiguration +//		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration result = new at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration(); +//		result.setAuthComponentGeneral(authComponent); +//		result.setChainingModes(chainingModes); +//		result.setGenericConfiguration(genericConfigurations); +//		result.setTrustedCACertificates(trustedCaCertificates); +//		result.setDefaultBKUs(defaultBKUs); +//		result.setSLRequestTemplates(slrRequestRemplates); +//		result.setTimestampItem(timeStamp); +//		result.setPvp2RefreshItem(pvp2Refresh); +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @return +//	 */ +//	public static List<OnlineApplication> getAllActiveOnlineApplications() { +//		Logger.trace("Get All New OnlineApplications from database."); +// +//		// select onlineapplication from OnlineApplication onlineapplication +//		// where onlineapplication.isActive = '1' +//		List<OnlineApplication> result = new ArrayList<OnlineApplication>(); +//		List<OnlineApplication> allOAs = getAllOnlineApplications(); +// +//		for (OnlineApplication oa : nullGuard(allOAs)) { +//			if (oa.isIsActive()) { +//				result.add(oa); +//			} +//		} +// +//		if (result.size() == 0) { +//			Logger.trace("No entries found."); +//			return null; +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param id +//	 * @return +//	 */ +//	public static OnlineApplication getActiveOnlineApplication(String id) { +//		Logger.trace("Getting Active OnlineApplication with ID " + id + " from database."); +// +//		// select onlineapplication from OnlineApplication onlineapplication +//		// where onlineapplication.publicURLPrefix = +//		// SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) and  onlineapplication.isActive = '1' +//		OnlineApplication result = null; +//		List<OnlineApplication> allActiveOAs = getAllActiveOnlineApplications(); +// +//		for (OnlineApplication oa : nullGuard(allActiveOAs)) { +//			String publicUrlPrefix = oa.getPublicURLPrefix(); +//			if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { +//				if ((id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix))) { +//					if (result != null) { +//						Logger.warn("OAIdentifier match to more then one DB-entry!"); +//						return null; +//					} else { +//						result = oa; +//					} +//				} +//			} +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param dbid +//	 * @return +//	 */ +//	public static OnlineApplication getOnlineApplication(long dbid) { +//		Logger.trace("Getting OnlineApplication with DBID " + dbid + " from database."); +// +//		// select onlineapplication from OnlineApplication onlineapplication where onlineapplication.hjid = :id +//		OnlineApplication result = null; +//		List<OnlineApplication> allOAs = getAllOnlineApplications(); +// +//		for (OnlineApplication oa : nullGuard(allOAs)) { +//			if (oa.getHjid() == dbid) { +//				result = oa; +//				break; +//			} +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param id +//	 * @return +//	 */ +//	public static OnlineApplication getOnlineApplication(String id) { +//		Logger.trace("Getting OnlineApplication with ID " + id + " from database."); +// +//		// select onlineapplication from OnlineApplication onlineapplication +//		// where onlineapplication.publicURLPrefix = SUBSTRING(:id, 1, LENGTH(onlineapplication.publicURLPrefix)) +//		OnlineApplication result = null; +//		List<OnlineApplication> allOAs = getAllOnlineApplications(); +// +//		for (OnlineApplication oa : nullGuard(allOAs)) { +//			String publicUrlPrefix = oa.getPublicURLPrefix(); +//			if (publicUrlPrefix != null && publicUrlPrefix.length() <= id.length()) { +//				if (id.substring(1, publicUrlPrefix.length()).equals(publicUrlPrefix)) { +//					if (result != null) { +//						Logger.warn("OAIdentifier match to more then one DB-entry!"); +//						return null; +//					} else { +//						result = oa; +//					} +//				} +//			} +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param id +//	 * @return +//	 */ +//	public static List<OnlineApplication> searchOnlineApplications(String id) { +//		Logger.trace("Getting OnlineApplication with ID " + id + " from database."); +// +//		// select onlineapplication from OnlineApplication onlineapplication +//		// where onlineapplication.friendlyName like :id +//		List<OnlineApplication> result = new ArrayList<OnlineApplication>(); +//		List<OnlineApplication> allOAs = getAllOnlineApplications(); +// +//		for (OnlineApplication oa : nullGuard(allOAs)) { +//			if (id.equals(oa.getFriendlyName())) { +//				result.add(oa); +//			} +//		} +// +//		if (result.size() == 0) { +//			Logger.trace("No entries found."); +//			return null; +//		} +//		 +//		return result; +//	} +// +//	/** +//	 *  +//	 * @return +//	 */ +//	public static List<UserDatabase> getAllOpenUsersRequests() { +//		Logger.trace("Get all new Users from Database"); +// +//		// select userdatabase from UserDatabase userdatabase +//		// where userdatabase.userRequestTokken is not null +//		// and userdatabase.isAdminRequest = '1' and userdatabase.isMailAddressVerified = '0' +//		List<UserDatabase> result = new ArrayList<UserDatabase>(); +//		List<UserDatabase> allUsers = getAllUsers(); +// +//		for (UserDatabase user : nullGuard(allUsers)) { +//			// TODO check result of query "... userdatabase.userRequestTokken is not null" if Tokken is null -> (null, "NULL", "", ... ?) +//			if ((user.getUserRequestTokken() != null && !user.getUserRequestTokken().isEmpty() && !user.getUserRequestTokken().equals("NULL")) +//					&& (user.isIsAdminRequest()) && (!user.isIsMailAddressVerified())) { +//				result.add(user); +//			} +//		} +// +//		if (result.size() == 0) { +//			Logger.trace("No entries found."); +//			return null; +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param tokken +//	 * @return +//	 */ +//	public static UserDatabase getNewUserWithTokken(String tokken) { +//		Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); +// +//		// select userdatabase from UserDatabase userdatabase where userdatabase.userRequestTokken = :tokken +//		UserDatabase result = null; +//		List<UserDatabase> allUsers = getAllUsers(); +// +//		for (UserDatabase user : nullGuard(allUsers)) { +//			if (user.getUserRequestTokken().equals(tokken)) { +//				result = user; +//				break; +//			} +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param id +//	 * @return +//	 */ +//	public static UserDatabase getUsersWithOADBID(long id) { +//		Logger.trace("Getting Userinformation with OADBID " + id + " from database."); +// +//		// select userdatabase from UserDatabase userdatabase +//		// inner join userdatabase.onlineApplication oa where oa.hjid = :id +//		UserDatabase result = null; +//		List<UserDatabase> allUsers = getAllUsers(); +// +//		boolean quit = false; +//		for (UserDatabase user : nullGuard(allUsers)) { +// +//			for (OnlineApplication oa : user.getOnlineApplication()) { +// +//				if (oa.getHjid() == id) { +//					result = user; +//					quit = true; +//					break; +//				} +//			} +// +//			if (quit) { +//				break; +//			} +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param id +//	 * @return +//	 */ +//	public static UserDatabase getUserWithID(long id) { +//		Logger.trace("Getting Userinformation with ID " + id + " from database."); +// +//		// select userdatabase from UserDatabase userdatabase where userdatabase.hjid = :id +//		UserDatabase result = null; +//		List<UserDatabase> allUsers = getAllUsers(); +// +//		for (UserDatabase user : nullGuard(allUsers)) { +//			if (user.getHjid() == id) { +//				result = user; +//				break; +//			} +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param username +//	 * @return +//	 */ +//	public static UserDatabase getUserWithUserName(String username) { +//		Logger.trace("Getting Userinformation with ID " + username + " from database."); +// +//		// select userdatabase from UserDatabase userdatabase where userdatabase.username = :username +//		UserDatabase result = null; +//		List<UserDatabase> allUsers = getAllUsers(); +// +//		for (UserDatabase user : nullGuard(allUsers)) { +//			if (user.getUsername().equals(username)) { +//				result = user; +//				break; +//			} +//		} +// +//		return result; +//	} +// +//	/** +//	 *  +//	 * @param bpkwbpk +//	 * @return +//	 */ +//	public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { +//		Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); +// +//		// select userdatabase from UserDatabase userdatabase where userdatabase.bpk = :bpk +//		UserDatabase result = null; +//		List<UserDatabase> allUsers = getAllUsers(); +// +//		for (UserDatabase user : nullGuard(allUsers)) { +//			if (user.getBpk().equals(bpkwbpk)) { +//				result = user; +//				break; +//			} +//		} +// +//		return result; +//	} +// +//} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBWrite.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBWrite.java index 69e03db28..a2b1f120e 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBWrite.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBWrite.java @@ -1,137 +1,137 @@ -package at.gv.egovernment.moa.id.commons.db; - -import java.util.Date; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; -import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; -import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; -import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; -import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; -import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; -import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; -import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; -import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; - -/** - * This class is used for writing to the key-value database. - */ -@Component -public class NewConfigurationDBWrite { - -	private static MOAIDConfiguration conf; -	 -	@Autowired(required = true) -	public void setConfiguration(MOAIDConfiguration conf) { -			// https://jira.spring.io/browse/SPR-3845 -		NewConfigurationDBWrite.conf = conf; -	} -	 -	private static boolean saveAuthComponentGeneral(AuthComponentGeneral dbo) { -		return conf.set(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, dbo); -	} - -	private static boolean saveChainingModes(ChainingModes dbo) { -		return conf.set(MOAIDConfigurationConstants.CHAINING_MODES_KEY, dbo); -	} - -	private static boolean saveOnlineApplication(OnlineApplication dbo) { - -		List<OnlineApplication> storedObjects = conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class); -		storedObjects.add(dbo); -		return conf.set(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, storedObjects); -	} - -	private static boolean saveGenericConfiguration(GenericConfiguration dbo) { -		 -		List<GenericConfiguration> storedObjects = conf.getList(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, GenericConfiguration.class); -		storedObjects.add(dbo); -		return conf.set(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, storedObjects); -	} - -	private static boolean saveTrustedCACertificates(String dbo) { -		return conf.set(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, dbo); -	} - -	private static boolean saveDefaultBKUs(DefaultBKUs dbo) { -		return conf.set(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, dbo); -	} - -	private static boolean saveSLRequestTemplates(SLRequestTemplates dbo) { -		return conf.set(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, dbo); -	} - -	private static boolean saveTimeStampItem(Date dbo) { -		return conf.set(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, dbo); -	} - -	private static boolean savePvp2RefreshItem(Date dbo) { -		return conf.set(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, dbo); -	} - -	/** -	 * Saves the given list of {@link OnlineApplication} objects to database. -	 * @param oas the list -	 * @return {@code true} on success; {@code false} otherwise. -	 */ -	public static boolean saveOnlineApplications(List<OnlineApplication> oas) { -		return conf.set(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, oas); -	} - -	/** -	 * Saves the given list of {@link GenericConfiguration} objects to database. -	 * @param gcs the list -	 * @return {@code true} on success; {@code false} otherwise. -	 */ -	public static boolean saveGenericConfigurations(List<GenericConfiguration> gcs) { -		return conf.set(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, gcs); -	} - - -	/** -	 * Saves the given object to database -	 * @param dbo the object to save -	 * @return {@code true} on success; {@code false} otherwise. -	 */ -	public static boolean save(Object dbo) { - -		boolean result = false; - -		if (dbo instanceof OnlineApplication) { - -			result = saveOnlineApplication((OnlineApplication) dbo); - -		} else if (dbo instanceof MOAIDConfiguration) { - -			at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration moaconfig =  -					(at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration) dbo; -			result = true; - -			result &= saveAuthComponentGeneral(moaconfig.getAuthComponentGeneral()); -			result &= saveChainingModes(moaconfig.getChainingModes()); -			result &= saveDefaultBKUs(moaconfig.getDefaultBKUs()); -			result &= saveGenericConfigurations(moaconfig.getGenericConfiguration()); -			result &= savePvp2RefreshItem(moaconfig.getPvp2RefreshItem()); -			result &= saveSLRequestTemplates(moaconfig.getSLRequestTemplates()); -			result &= saveTrustedCACertificates(moaconfig.getTrustedCACertificates()); -			result &= saveTimeStampItem(moaconfig.getTimestampItem()); - -		} else if (dbo instanceof UserDatabase) { -			// TODO implement user handling -		} - -		return result; -	} - -	/** -	 * Deletes the object associated with the given key. -	 * @param key the key -	 */ -	public static void delete(String key) { -		conf.set(key, null); -	} - -} +//package at.gv.egovernment.moa.id.commons.db; +// +//import java.util.Date; +//import java.util.List; +// +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Component; +// +//import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; +//import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; +//import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; +//import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; +//import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; +//import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; +//import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; +//import at.gv.egovernment.moa.id.commons.db.dao.config.SLRequestTemplates; +//import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; +// +///** +// * This class is used for writing to the key-value database. +// */ +//@Component +//public class NewConfigurationDBWrite { +// +//	private static MOAIDConfiguration conf; +//	 +//	@Autowired(required = true) +//	public void setConfiguration(MOAIDConfiguration conf) { +//			// https://jira.spring.io/browse/SPR-3845 +//		NewConfigurationDBWrite.conf = conf; +//	} +//	 +//	private static boolean saveAuthComponentGeneral(AuthComponentGeneral dbo) { +//		return conf.set(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, dbo); +//	} +// +//	private static boolean saveChainingModes(ChainingModes dbo) { +//		return conf.set(MOAIDConfigurationConstants.CHAINING_MODES_KEY, dbo); +//	} +// +//	private static boolean saveOnlineApplication(OnlineApplication dbo) { +// +//		List<OnlineApplication> storedObjects = conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class); +//		storedObjects.add(dbo); +//		return conf.set(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, storedObjects); +//	} +// +//	private static boolean saveGenericConfiguration(GenericConfiguration dbo) { +//		 +//		List<GenericConfiguration> storedObjects = conf.getList(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, GenericConfiguration.class); +//		storedObjects.add(dbo); +//		return conf.set(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, storedObjects); +//	} +// +//	private static boolean saveTrustedCACertificates(String dbo) { +//		return conf.set(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, dbo); +//	} +// +//	private static boolean saveDefaultBKUs(DefaultBKUs dbo) { +//		return conf.set(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, dbo); +//	} +// +//	private static boolean saveSLRequestTemplates(SLRequestTemplates dbo) { +//		return conf.set(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, dbo); +//	} +// +//	private static boolean saveTimeStampItem(Date dbo) { +//		return conf.set(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, dbo); +//	} +// +//	private static boolean savePvp2RefreshItem(Date dbo) { +//		return conf.set(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, dbo); +//	} +// +//	/** +//	 * Saves the given list of {@link OnlineApplication} objects to database. +//	 * @param oas the list +//	 * @return {@code true} on success; {@code false} otherwise. +//	 */ +//	public static boolean saveOnlineApplications(List<OnlineApplication> oas) { +//		return conf.set(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, oas); +//	} +// +//	/** +//	 * Saves the given list of {@link GenericConfiguration} objects to database. +//	 * @param gcs the list +//	 * @return {@code true} on success; {@code false} otherwise. +//	 */ +//	public static boolean saveGenericConfigurations(List<GenericConfiguration> gcs) { +//		return conf.set(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, gcs); +//	} +// +// +//	/** +//	 * Saves the given object to database +//	 * @param dbo the object to save +//	 * @return {@code true} on success; {@code false} otherwise. +//	 */ +//	public static boolean save(Object dbo) { +// +//		boolean result = false; +// +//		if (dbo instanceof OnlineApplication) { +// +//			result = saveOnlineApplication((OnlineApplication) dbo); +// +//		} else if (dbo instanceof MOAIDConfiguration) { +// +//			at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration moaconfig =  +//					(at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration) dbo; +//			result = true; +// +//			result &= saveAuthComponentGeneral(moaconfig.getAuthComponentGeneral()); +//			result &= saveChainingModes(moaconfig.getChainingModes()); +//			result &= saveDefaultBKUs(moaconfig.getDefaultBKUs()); +//			result &= saveGenericConfigurations(moaconfig.getGenericConfiguration()); +//			result &= savePvp2RefreshItem(moaconfig.getPvp2RefreshItem()); +//			result &= saveSLRequestTemplates(moaconfig.getSLRequestTemplates()); +//			result &= saveTrustedCACertificates(moaconfig.getTrustedCACertificates()); +//			result &= saveTimeStampItem(moaconfig.getTimestampItem()); +// +//		} else if (dbo instanceof UserDatabase) { +//			// TODO implement user handling +//		} +// +//		return result; +//	} +// +//	/** +//	 * Deletes the object associated with the given key. +//	 * @param key the key +//	 */ +//	public static void delete(String key) { +//		conf.set(key, null); +//	} +// +//} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAHttpProtocolSocketFactory.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAHttpProtocolSocketFactory.java index 3b6fc34ea..2ade63c1c 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAHttpProtocolSocketFactory.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAHttpProtocolSocketFactory.java @@ -37,7 +37,6 @@ import org.apache.commons.httpclient.ConnectTimeoutException;  import org.apache.commons.httpclient.params.HttpConnectionParams;  import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; -import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModeType;  import at.gv.egovernment.moa.id.commons.ex.MOAHttpProtocolSocketFactoryException;  import at.gv.egovernment.moa.id.commons.utils.ssl.SSLConfigurationException;  import at.gv.egovernment.moa.id.commons.utils.ssl.SSLUtils; @@ -57,7 +56,7 @@ public class MOAHttpProtocolSocketFactory implements SecureProtocolSocketFactory  			String certStoreRootDirParam,  			String trustStoreURL,  			String acceptedServerCertURL, -			ChainingModeType chainingMode, +			String chainingMode,  			boolean checkRevocation  			) throws MOAHttpProtocolSocketFactoryException {  		super(); @@ -68,7 +67,7 @@ public class MOAHttpProtocolSocketFactory implements SecureProtocolSocketFactory  					certStoreRootDirParam,   					trustStoreURL,   					acceptedServerCertURL,  -					chainingMode.value(),  +					chainingMode,   					checkRevocation,   					null,   					null,  diff --git a/id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java b/id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java index c8a234565..896a26064 100644 --- a/id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java +++ b/id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java @@ -1,128 +1,128 @@ -package at.gv.egovernment.moa.id.commons.db; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; -import java.util.Properties; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.IfProfileValue; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; -import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; -import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; - -import com.fasterxml.jackson.annotation.JsonProperty; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("configuration.beans-test.xml") -@IfProfileValue(name = "test-groups", values = { "manual" }) -public class ConfigurationDBReadTest { - -	@Autowired -	MOAIDConfiguration configDataBase; - -	private Properties getHibernateProperties() throws FileNotFoundException, IOException { - -		Properties configProp = null; -		try (InputStream in = ConfigurationDBReadTest.class.getResourceAsStream("hibernate.properties");) { -			Properties props = new Properties(); -			props.load(in); -			// read Config Hibernate properties -			configProp = new Properties(); -			for (Object key : props.keySet()) { -				String propPrefix = "configuration."; -				if (key.toString().startsWith(propPrefix + "hibernate")) { -					String propertyName = key.toString().substring(propPrefix.length()); -					configProp.put(propertyName, props.get(key.toString())); -				} -			} -		} - -		return configProp; -	} - -	private void migrateDatabase(List<String> methodNames) throws IllegalAccessException, IllegalArgumentException, -			InvocationTargetException, NoSuchMethodException, SecurityException { -		for (String name : methodNames) { -			Method method = ConfigurationFromDBExtractor.class.getMethod(name); -			Object tmp = method.invoke(null, new Object[] {}); -			JsonProperty annotation = method.getAnnotation(JsonProperty.class); -			if (annotation != null) { -				configDataBase.set(annotation.value(), tmp); -			} else { -				System.out.println("Methods must be annotated, annotation is used as key in key-value db."); -				assertTrue(false); -			} -		} -	} - -	@Before -	public void initialize() throws FileNotFoundException, MOADatabaseException, IOException, IllegalAccessException, -			IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - -		// initialize the connection to the old database -		ConfigurationDBUtils.initHibernate(getHibernateProperties()); - -		// migrate the data in the old database to a new key value database -		List<String> methodNames = Arrays.asList("getAuthComponentGeneral", "getChainingModes", -				"getTrustedCACertificates", "getDefaultBKUs", "getSLRequestTemplates", "getTimeStampItem", -				"getPvp2RefreshItem", "getOnlineApplications", "getGenericConfigurations"); -		migrateDatabase(methodNames); - -		// close the session with the old database -		ConfigurationDBUtils.closeSession(); -	} - -	@Test -	public void testGetMOAIDConfiguration() throws FileNotFoundException, MOADatabaseException, IOException, -			IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, -			SecurityException { - -		// get the old moaid configuration -		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration oldConfig = ConfigurationDBRead.getMOAIDConfiguration(); - -		// get the a new moaid configuration from the data in the key value -		// database -		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration newConfig = NewConfigurationDBRead.getMOAIDConfiguration(); - -		// check if both configurations yield a similar MOAIDConfiguration -		// object -		assertTrue(oldConfig.equals(newConfig)); - -	} - -	@Test -	public void testGetMOAIDConfigurationNotEqual() throws FileNotFoundException, MOADatabaseException, IOException, -			IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, -			SecurityException { - -		// get the old moaid configuration -		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration oldConfig = ConfigurationDBRead.getMOAIDConfiguration(); - -		// delete part of the configuration -		oldConfig.setAuthComponentGeneral(new AuthComponentGeneral()); - -		// get the a new moaid configuration from the data in the key value -		// database -		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration newConfig = NewConfigurationDBRead.getMOAIDConfiguration(); - -		// check if both configurations yield a similar MOAIDConfiguration -		// object -		assertFalse(oldConfig.equals(newConfig)); - -	} - -} +//package at.gv.egovernment.moa.id.commons.db; +// +//import static org.junit.Assert.assertFalse; +//import static org.junit.Assert.assertTrue; +// +//import java.io.FileNotFoundException; +//import java.io.IOException; +//import java.io.InputStream; +//import java.lang.reflect.InvocationTargetException; +//import java.lang.reflect.Method; +//import java.util.Arrays; +//import java.util.List; +//import java.util.Properties; +// +//import org.junit.Before; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.test.annotation.IfProfileValue; +//import org.springframework.test.context.ContextConfiguration; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +// +//import at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration; +//import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; +//import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; +// +//import com.fasterxml.jackson.annotation.JsonProperty; +// +//@RunWith(SpringJUnit4ClassRunner.class) +//@ContextConfiguration("configuration.beans-test.xml") +//@IfProfileValue(name = "test-groups", values = { "manual" }) +//public class ConfigurationDBReadTest { +// +//	@Autowired +//	MOAIDConfiguration configDataBase; +// +//	private Properties getHibernateProperties() throws FileNotFoundException, IOException { +// +//		Properties configProp = null; +//		try (InputStream in = ConfigurationDBReadTest.class.getResourceAsStream("hibernate.properties");) { +//			Properties props = new Properties(); +//			props.load(in); +//			// read Config Hibernate properties +//			configProp = new Properties(); +//			for (Object key : props.keySet()) { +//				String propPrefix = "configuration."; +//				if (key.toString().startsWith(propPrefix + "hibernate")) { +//					String propertyName = key.toString().substring(propPrefix.length()); +//					configProp.put(propertyName, props.get(key.toString())); +//				} +//			} +//		} +// +//		return configProp; +//	} +// +//	private void migrateDatabase(List<String> methodNames) throws IllegalAccessException, IllegalArgumentException, +//			InvocationTargetException, NoSuchMethodException, SecurityException { +//		for (String name : methodNames) { +//			Method method = ConfigurationFromDBExtractor.class.getMethod(name); +//			Object tmp = method.invoke(null, new Object[] {}); +//			JsonProperty annotation = method.getAnnotation(JsonProperty.class); +//			if (annotation != null) { +//				configDataBase.set(annotation.value(), tmp); +//			} else { +//				System.out.println("Methods must be annotated, annotation is used as key in key-value db."); +//				assertTrue(false); +//			} +//		} +//	} +// +//	@Before +//	public void initialize() throws FileNotFoundException, MOADatabaseException, IOException, IllegalAccessException, +//			IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { +// +//		// initialize the connection to the old database +//		ConfigurationDBUtils.initHibernate(getHibernateProperties()); +// +//		// migrate the data in the old database to a new key value database +//		List<String> methodNames = Arrays.asList("getAuthComponentGeneral", "getChainingModes", +//				"getTrustedCACertificates", "getDefaultBKUs", "getSLRequestTemplates", "getTimeStampItem", +//				"getPvp2RefreshItem", "getOnlineApplications", "getGenericConfigurations"); +//		migrateDatabase(methodNames); +// +//		// close the session with the old database +//		ConfigurationDBUtils.closeSession(); +//	} +// +//	@Test +//	public void testGetMOAIDConfiguration() throws FileNotFoundException, MOADatabaseException, IOException, +//			IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, +//			SecurityException { +// +//		// get the old moaid configuration +//		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration oldConfig = ConfigurationDBRead.getMOAIDConfiguration(); +// +//		// get the a new moaid configuration from the data in the key value +//		// database +//		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration newConfig = NewConfigurationDBRead.getMOAIDConfiguration(); +// +//		// check if both configurations yield a similar MOAIDConfiguration +//		// object +//		assertTrue(oldConfig.equals(newConfig)); +// +//	} +// +//	@Test +//	public void testGetMOAIDConfigurationNotEqual() throws FileNotFoundException, MOADatabaseException, IOException, +//			IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, +//			SecurityException { +// +//		// get the old moaid configuration +//		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration oldConfig = ConfigurationDBRead.getMOAIDConfiguration(); +// +//		// delete part of the configuration +//		oldConfig.setAuthComponentGeneral(new AuthComponentGeneral()); +// +//		// get the a new moaid configuration from the data in the key value +//		// database +//		at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration newConfig = NewConfigurationDBRead.getMOAIDConfiguration(); +// +//		// check if both configurations yield a similar MOAIDConfiguration +//		// object +//		assertFalse(oldConfig.equals(newConfig)); +// +//	} +// +//} | 
