diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2013-08-12 13:31:30 +0200 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2013-08-12 13:31:30 +0200 |
commit | 7c6ecaa8adb365a6c670cb86bb68be94136dc6a0 (patch) | |
tree | f69c954a387513aa14adf86d4bf9a81a59b80c36 /id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ImportExportAction.java | |
parent | 45e170310a012dca93d5e5d4dc0b54e6b0808e95 (diff) | |
download | moa-id-spss-7c6ecaa8adb365a6c670cb86bb68be94136dc6a0.tar.gz moa-id-spss-7c6ecaa8adb365a6c670cb86bb68be94136dc6a0.tar.bz2 moa-id-spss-7c6ecaa8adb365a6c670cb86bb68be94136dc6a0.zip |
Bugfixes:
@ConfigurationTool
- AuthenticationFilter: handle of non authenticated requests after restart
- Legacy Import: update legacy Configuration import process
@MOA-ID
- Change Legacy Configuration import
Diffstat (limited to 'id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ImportExportAction.java')
-rw-r--r-- | id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ImportExportAction.java | 349 |
1 files changed, 176 insertions, 173 deletions
diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ImportExportAction.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ImportExportAction.java index b683a95f9..1cb4fa802 100644 --- a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ImportExportAction.java +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ImportExportAction.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; import java.io.StringWriter; +import java.net.MalformedURLException; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -32,6 +33,7 @@ import at.gv.egovernment.moa.id.config.ConfigurationException; import at.gv.egovernment.moa.id.config.legacy.BuildFromLegacyConfig; import at.gv.egovernment.moa.id.configuration.Constants; import at.gv.egovernment.moa.id.configuration.auth.AuthenticatedUser; +import at.gv.egovernment.moa.id.configuration.config.ConfigurationProvider; import at.gv.egovernment.moa.id.configuration.helper.LanguageHelper; import at.iaik.commons.util.IOUtil; @@ -60,232 +62,233 @@ implements ServletRequestAware, ServletResponseAware { Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); - if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { - authUser = (AuthenticatedUser) authUserObj; - - if (authUser.isAdmin()) { - - return Constants.STRUTS_SUCCESS; - - } else { - log.info("No access to Import/Export for User with ID" + authUser.getUserID()); - addActionError(LanguageHelper.getErrorString("errors.notallowed")); - return Constants.STRUTS_NOTALLOWED; - } - } - return Constants.STRUTS_REAUTHENTICATE; + authUser = (AuthenticatedUser) authUserObj; + if (authUser.isAdmin()) { + + return Constants.STRUTS_SUCCESS; + + } else { + log.info("No access to Import/Export for User with ID" + authUser.getUserID()); + addActionError(LanguageHelper.getErrorString("errors.notallowed")); + return Constants.STRUTS_NOTALLOWED; + } } public String importLegacyConfig() { Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); - if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { - authUser = (AuthenticatedUser) authUserObj; - - if (authUser.isAdmin()) { - - //load legacy config if it is configured + authUser = (AuthenticatedUser) authUserObj; + + if (authUser.isAdmin()) { + + //load legacy config if it is configured + + if (fileUpload == null) { + addActionError(LanguageHelper.getErrorString("errors.importexport.nofile")); + return Constants.STRUTS_ERROR_VALIDATION; + } - if (fileUpload == null) { - addActionError(LanguageHelper.getErrorString("errors.importexport.nofile")); - return Constants.STRUTS_ERROR_VALIDATION; - } + //Initialize OpenSAML for STORK + log.info("Starting initialization of OpenSAML..."); + try { + STORKBootstrap.bootstrap(); - //Initialize OpenSAML for STORK - log.info("Starting initialization of OpenSAML..."); - try { - STORKBootstrap.bootstrap(); - - } catch (org.opensaml.xml.ConfigurationException e1) { - log.info("Legacy configuration has an Import Error", e1); - addActionError(LanguageHelper.getErrorString("errors.importexport.legacyimport", new Object[] {e1.getMessage()})); - return Constants.STRUTS_ERROR_VALIDATION; - } - log.debug("OpenSAML successfully initialized"); + } catch (org.opensaml.xml.ConfigurationException e1) { + log.info("Legacy configuration has an Import Error", e1); + addActionError(LanguageHelper.getErrorString("errors.importexport.legacyimport", new Object[] {e1.getMessage()})); + return Constants.STRUTS_ERROR_VALIDATION; + } + log.debug("OpenSAML successfully initialized"); + try { + + MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); + + MOAIDConfiguration moaconfig; try { + log.warn("WARNING! The legacy import deletes the hole old config"); - MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); + String rootConfigFileDir = new File(ConfigurationProvider.getInstance().getConfigFile()).getParent(); - MOAIDConfiguration moaconfig; try { - log.warn("WARNING! The legacy import deletes the hole old config"); - - moaconfig = BuildFromLegacyConfig.build(fileUpload, "", moaidconfig); - - } catch (ConfigurationException e) { - log.info("Legacy configuration has an Import Error", e); - addActionError(LanguageHelper.getErrorString("errors.importexport.legacyimport", new Object[] {e.getMessage()})); - ConfigurationDBUtils.closeSession(); - return Constants.STRUTS_ERROR_VALIDATION; + rootConfigFileDir = new File(rootConfigFileDir).toURL().toString(); + + } catch (MalformedURLException t) { + log.warn("RootConfiguration Directory is not found"); + rootConfigFileDir = ""; } - //check if XML config should be use - log.warn("WARNING! MOA-ID 2.0 is started with XML configuration. This setup overstrike the actual configuration in the Database!"); + moaconfig = BuildFromLegacyConfig.build(fileUpload, rootConfigFileDir, moaidconfig); + } catch (ConfigurationException e) { + log.info("Legacy configuration has an Import Error", e); + addActionError(LanguageHelper.getErrorString("errors.importexport.legacyimport", new Object[] {e.getMessage()})); + ConfigurationDBUtils.closeSession(); + return Constants.STRUTS_ERROR_VALIDATION; - if (moaidconfig != null) - ConfigurationDBUtils.delete(moaidconfig); - - List<OnlineApplication> oas = ConfigurationDBRead.getAllOnlineApplications(); - if (oas != null && oas.size() > 0) { - for (OnlineApplication oa : oas) - ConfigurationDBUtils.delete(oa); - } - - - oas = moaconfig.getOnlineApplication(); - for (OnlineApplication oa : oas) - ConfigurationDBUtils.save(oa); - - moaconfig.setOnlineApplication(null); - ConfigurationDBUtils.save(moaconfig); - - } catch (MOADatabaseException e) { - log.warn("General MOA-ID config can not be stored in Database"); - addActionError(e.getMessage()); + } catch (at.gv.egovernment.moa.id.configuration.exception.ConfigurationException e) { + ConfigurationDBUtils.closeSession(); return Constants.STRUTS_ERROR_VALIDATION; } - finally { - ConfigurationDBUtils.closeSession(); + //check if XML config should be use + log.warn("WARNING! MOA-ID 2.0 is started with XML configuration. This setup overstrike the actual configuration in the Database!"); + + + if (moaidconfig != null) + ConfigurationDBUtils.delete(moaidconfig); + + List<OnlineApplication> oas = ConfigurationDBRead.getAllOnlineApplications(); + if (oas != null && oas.size() > 0) { + for (OnlineApplication oa : oas) + ConfigurationDBUtils.delete(oa); } + - log.info("Legacy Configuration load is completed."); - addActionMessage(LanguageHelper.getGUIString("webpages.inportexport.success")); - return Constants.STRUTS_SUCCESS; + oas = moaconfig.getOnlineApplication(); + for (OnlineApplication oa : oas) + ConfigurationDBUtils.save(oa); + + moaconfig.setOnlineApplication(null); + ConfigurationDBUtils.save(moaconfig); - } else { - log.info("No access to Import/Export for User with ID" + authUser.getUserID()); - addActionError(LanguageHelper.getErrorString("errors.notallowed")); - return Constants.STRUTS_NOTALLOWED; + } catch (MOADatabaseException e) { + log.warn("General MOA-ID config can not be stored in Database"); + addActionError(e.getMessage()); + return Constants.STRUTS_ERROR_VALIDATION; + } + + finally { + ConfigurationDBUtils.closeSession(); } + + log.info("Legacy Configuration load is completed."); + addActionMessage(LanguageHelper.getGUIString("webpages.inportexport.success")); + return Constants.STRUTS_SUCCESS; + + } else { + log.info("No access to Import/Export for User with ID" + authUser.getUserID()); + addActionError(LanguageHelper.getErrorString("errors.notallowed")); + return Constants.STRUTS_NOTALLOWED; } - return Constants.STRUTS_REAUTHENTICATE; } public String downloadXMLConfig() { Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); - if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { - authUser = (AuthenticatedUser) authUserObj; - - if (authUser.isAdmin()) { - - log.info("Write MOA-ID 2.x xml config"); - JAXBContext jc; - try { - jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config"); + authUser = (AuthenticatedUser) authUserObj; - Marshaller m = jc.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + if (authUser.isAdmin()) { + + log.info("Write MOA-ID 2.x xml config"); + JAXBContext jc; + try { + jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config"); + + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // File test = new File(xmlconfigout); // m.marshal(moaidconfig, test); - MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); - - if (moaidconfig == null) { - log.info("No MOA-ID 2.x configruation available"); - addActionError(LanguageHelper.getErrorString("errors.importexport.export.noconfig")); - return Constants.STRUTS_ERROR_VALIDATION; - } - - List<OnlineApplication> oaconfigs = ConfigurationDBRead.getAllOnlineApplications(); - moaidconfig.setOnlineApplication(oaconfigs); - - StringWriter writer = new StringWriter(); - m.marshal(moaidconfig, writer); - fileInputStream = IOUtils.toInputStream(writer.toString(), "UTF-8"); - - } catch (JAXBException e) { - log.info("MOA-ID 2.x configruation could not be exported into a XML file.", e); - addActionError(LanguageHelper.getErrorString("errors.importexport.export", - new Object[]{e.getMessage()})); - return Constants.STRUTS_ERROR_VALIDATION; - } catch (IOException e) { - log.info("MOA-ID 2.x configruation could not be exported into a XML file.", e); - addActionError(LanguageHelper.getErrorString("errors.importexport.export", - new Object[]{e.getMessage()})); + MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); + + if (moaidconfig == null) { + log.info("No MOA-ID 2.x configruation available"); + addActionError(LanguageHelper.getErrorString("errors.importexport.export.noconfig")); return Constants.STRUTS_ERROR_VALIDATION; } - finally { - ConfigurationDBUtils.closeSession(); - } + List<OnlineApplication> oaconfigs = ConfigurationDBRead.getAllOnlineApplications(); + moaidconfig.setOnlineApplication(oaconfigs); + + StringWriter writer = new StringWriter(); + m.marshal(moaidconfig, writer); + fileInputStream = IOUtils.toInputStream(writer.toString(), "UTF-8"); - return Constants.STRUTS_SUCCESS; - } else { - log.info("No access to Import/Export for User with ID" + authUser.getUserID()); - addActionError(LanguageHelper.getErrorString("errors.notallowed")); - return Constants.STRUTS_NOTALLOWED; + } catch (JAXBException e) { + log.info("MOA-ID 2.x configruation could not be exported into a XML file.", e); + addActionError(LanguageHelper.getErrorString("errors.importexport.export", + new Object[]{e.getMessage()})); + return Constants.STRUTS_ERROR_VALIDATION; + } catch (IOException e) { + log.info("MOA-ID 2.x configruation could not be exported into a XML file.", e); + addActionError(LanguageHelper.getErrorString("errors.importexport.export", + new Object[]{e.getMessage()})); + return Constants.STRUTS_ERROR_VALIDATION; } + + finally { + ConfigurationDBUtils.closeSession(); + } + + return Constants.STRUTS_SUCCESS; + } else { + log.info("No access to Import/Export for User with ID" + authUser.getUserID()); + addActionError(LanguageHelper.getErrorString("errors.notallowed")); + return Constants.STRUTS_NOTALLOWED; } - return Constants.STRUTS_REAUTHENTICATE; } public String importXMLConfig() { Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); - if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { - authUser = (AuthenticatedUser) authUserObj; + authUser = (AuthenticatedUser) authUserObj; + + if (authUser.isAdmin()) { - if (authUser.isAdmin()) { - - if (fileUpload == null) { - addActionError(LanguageHelper.getErrorString("errors.importexport.nofile")); - return Constants.STRUTS_ERROR_VALIDATION; - } + if (fileUpload == null) { + addActionError(LanguageHelper.getErrorString("errors.importexport.nofile")); + return Constants.STRUTS_ERROR_VALIDATION; + } + + log.info("Load configuration from MOA-ID 2.x XML configuration"); - log.info("Load configuration from MOA-ID 2.x XML configuration"); - - try { - JAXBContext jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config"); - Unmarshaller m = jc.createUnmarshaller(); - MOAIDConfiguration moaconfig = (MOAIDConfiguration) m.unmarshal(fileUpload); + try { + JAXBContext jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config"); + Unmarshaller m = jc.createUnmarshaller(); + MOAIDConfiguration moaconfig = (MOAIDConfiguration) m.unmarshal(fileUpload); - - log.warn("WARNING! The XML import deletes the hole old config"); - List<OnlineApplication> oas = ConfigurationDBRead.getAllOnlineApplications(); - if (oas != null && oas.size() > 0) { - for (OnlineApplication oa : oas) - ConfigurationDBUtils.delete(oa); - } - MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); - if (moaidconfig != null) - ConfigurationDBUtils.delete(moaidconfig); - - List<OnlineApplication> importoas = moaconfig.getOnlineApplication(); - for (OnlineApplication importoa : importoas) { - ConfigurationDBUtils.saveOrUpdate(importoa); - } - - moaconfig.setOnlineApplication(null); - ConfigurationDBUtils.saveOrUpdate(moaconfig); - - } catch (Exception e) { - log.warn("MOA-ID XML configuration can not be loaded from File.", e); - addActionError(LanguageHelper.getErrorString("errors.importexport.import", - new Object[]{e.getMessage()})); - return Constants.STRUTS_ERROR_VALIDATION; - - } - finally { - ConfigurationDBUtils.closeSession(); + log.warn("WARNING! The XML import deletes the hole old config"); + List<OnlineApplication> oas = ConfigurationDBRead.getAllOnlineApplications(); + if (oas != null && oas.size() > 0) { + for (OnlineApplication oa : oas) + ConfigurationDBUtils.delete(oa); + } + MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); + if (moaidconfig != null) + ConfigurationDBUtils.delete(moaidconfig); + + List<OnlineApplication> importoas = moaconfig.getOnlineApplication(); + for (OnlineApplication importoa : importoas) { + ConfigurationDBUtils.saveOrUpdate(importoa); } - log.info("XML Configuration load is completed."); - addActionMessage(LanguageHelper.getGUIString("webpages.inportexport.success")); - return Constants.STRUTS_SUCCESS; + moaconfig.setOnlineApplication(null); + ConfigurationDBUtils.saveOrUpdate(moaconfig); + + } catch (Exception e) { + log.warn("MOA-ID XML configuration can not be loaded from File.", e); + addActionError(LanguageHelper.getErrorString("errors.importexport.import", + new Object[]{e.getMessage()})); + return Constants.STRUTS_ERROR_VALIDATION; + + } - } else { - log.info("No access to Import/Export for User with ID" + authUser.getUserID()); - addActionError(LanguageHelper.getErrorString("errors.notallowed")); - return Constants.STRUTS_NOTALLOWED; + finally { + ConfigurationDBUtils.closeSession(); } - } - return Constants.STRUTS_REAUTHENTICATE; + log.info("XML Configuration load is completed."); + addActionMessage(LanguageHelper.getGUIString("webpages.inportexport.success")); + return Constants.STRUTS_SUCCESS; + + } else { + log.info("No access to Import/Export for User with ID" + authUser.getUserID()); + addActionError(LanguageHelper.getErrorString("errors.notallowed")); + return Constants.STRUTS_NOTALLOWED; + } + } /** |