/* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.id.configuration.struts.action; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import at.gv.egiz.eaaf.core.impl.utils.Random; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.AttributeProviderPlugin; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.IdentificationNumber; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.OnlineApplication; import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; import at.gv.egovernment.moa.id.commons.validation.ValidationHelper; import at.gv.egovernment.moa.id.configuration.Constants; import at.gv.egovernment.moa.id.configuration.data.FormularCustomization; import at.gv.egovernment.moa.id.configuration.data.OAListElement; import at.gv.egovernment.moa.id.configuration.data.oa.IOnlineApplicationData; import at.gv.egovernment.moa.id.configuration.data.oa.OAAuthenticationData; import at.gv.egovernment.moa.id.configuration.data.oa.OAMOAIDPInterfederationConfig; import at.gv.egovernment.moa.id.configuration.data.oa.OASTORKConfig; import at.gv.egovernment.moa.id.configuration.data.oa.OATargetConfiguration; import at.gv.egovernment.moa.id.configuration.data.oa.PVPGatewayInterfederationConfig; import at.gv.egovernment.moa.id.configuration.exception.BasicActionException; import at.gv.egovernment.moa.id.configuration.exception.BasicOAActionException; import at.gv.egovernment.moa.id.configuration.helper.FormDataHelper; import at.gv.egovernment.moa.id.configuration.helper.LanguageHelper; /** * @author tlenz * */ public class InterfederationIDPAction extends BasicOAAction { private static final Logger log = Logger.getLogger(InterfederationIDPAction.class); private static final long serialVersionUID = 2879192135387083131L; public static final String STRUTS_IDP_VIDP = "-VIDP"; public static final String STRUTS_IDP_MOA = "-MOAIDP"; public static final String STRUTS_IDP_GATEWAY = "-IDPGATEWAY"; private List formOAs; private String interfederationType; public InterfederationIDPAction() { super(); } public String listAllIDPs() { try { populateBasicInformations(); if (authUser.isAdmin()) { List dbOAs = configuration.getDbRead().getAllOnlineApplications(); if (dbOAs == null || dbOAs.size() == 0) { addActionError(LanguageHelper.getErrorString("errors.listOAs.noOA", request)); } else { formOAs = FormDataHelper.populateFormWithInderfederationIDPs(dbOAs); } session.setAttribute(Constants.SESSION_RETURNAREA, Constants.STRUTS_RETURNAREA_VALUES.main.name()); return Constants.STRUTS_SUCCESS; } else { log.warn("User with ID " + authUser.getUserID() + " not allowed to manage interfederation IDPs."); addActionError(LanguageHelper.getErrorString("errors.notallowed", request)); return Constants.STRUTS_NOTALLOWED; } } catch (BasicActionException e) { return Constants.STRUTS_ERROR; } finally { } } public String newIDP() { log.debug("insert new interfederation IDP"); try { populateBasicInformations(); if (!authUser.isAdmin()) { log.warn("User with ID " + authUser.getUserID() + " not allowed to manage interfederation IDPs."); addActionError(LanguageHelper.getErrorString("errors.notallowed", request)); return Constants.STRUTS_NOTALLOWED; } populateBasicNewOnlineApplicationInformation(); if (STRUTS_IDP_MOA.equals(interfederationType)) { formList.putAll(MOAIDPAction.buildMOAIDPFormList()); } else if (STRUTS_IDP_GATEWAY.equals(interfederationType)) { formList.putAll(IDPGatewayAction.buildIDPGatewayFormList()); } else if (STRUTS_IDP_VIDP.equals(interfederationType)) { formList.putAll(VIDPAction.buildVIDPFormList()); getStorkOA().setVidpEnabled(true); getStorkOA().getAttributeProviderPlugins().add(new AttributeProviderPlugin()); session.setAttribute(Constants.SESSION_BKUFORMPREVIEW, getFormOA().getFormMap()); } else { log.warn("Unkown interfederation IDP type"); addActionError("Unkown interfederation IDP type"); return Constants.STRUTS_ERROR; } } catch (BasicActionException e) { return Constants.STRUTS_ERROR; } finally { } return Constants.STRUTS_OA_EDIT + interfederationType; } public String loadIDPInformation() { try { populateBasicInformations(); if (!authUser.isAdmin()) { log.warn("User with ID " + authUser.getUserID() + " not allowed to manage interfederation IDPs."); addActionError(LanguageHelper.getErrorString("errors.notallowed", request)); return Constants.STRUTS_NOTALLOWED; } OnlineApplication oa = populateOnlineApplicationFromRequest(); if (oa.isIsInterfederationIDP() != null && oa.isIsInterfederationIDP()) { formList.putAll(MOAIDPAction.buildMOAIDPFormList()); interfederationType = STRUTS_IDP_MOA; } else if (oa.getAuthComponentOA().getOASTORK() != null && oa.getAuthComponentOA().getOASTORK().isVidpEnabled() != null && oa.getAuthComponentOA().getOASTORK().isVidpEnabled()) { formList.putAll(VIDPAction.buildVIDPFormList()); if (getStorkOA().getAttributeProviderPlugins() == null || getStorkOA().getAttributeProviderPlugins().size() == 0) getStorkOA().getAttributeProviderPlugins().add(new AttributeProviderPlugin()); interfederationType = STRUTS_IDP_VIDP; } else if (oa.isIsInterfederationGateway() != null && oa.isIsInterfederationGateway()) { formList.putAll(IDPGatewayAction.buildIDPGatewayFormList()); interfederationType = STRUTS_IDP_GATEWAY; } else { log.warn("Requested application is not an interfederation IDP."); return Constants.STRUTS_NOTALLOWED; } parseOAToForm(oa); return Constants.STRUTS_SUCCESS + interfederationType; } catch (BasicActionException e) { return Constants.STRUTS_ERROR; } catch (BasicOAActionException e) { addActionError(e.getStrutsError()); return e.getStrutsReturnValue(); } finally { } } public String saveIDP() { OnlineApplication onlineapplication= null; try { populateBasicInformations(); if (!authUser.isAdmin()) { log.warn("User with ID " + authUser.getUserID() + " not allowed to manage interfederation IDPs."); addActionError(LanguageHelper.getErrorString("errors.notallowed", request)); return Constants.STRUTS_NOTALLOWED; } onlineapplication = preProcessSaveOnlineApplication(); if ( onlineapplication != null && !((onlineapplication.isIsInterfederationIDP() != null && onlineapplication.isIsInterfederationIDP()) || (onlineapplication.isIsInterfederationGateway() != null && onlineapplication.isIsInterfederationGateway()) || (onlineapplication.getAuthComponentOA().getOASTORK() != null && onlineapplication.getAuthComponentOA().getOASTORK().isVidpEnabled() != null && onlineapplication.getAuthComponentOA().getOASTORK().isVidpEnabled()))) { log.warn("IDP which should be stored is not of type interfederation IDP."); addActionError("IDP which should be stored is not of type MOA-ID interfederation IDP."); return Constants.STRUTS_ERROR; } List errors = new ArrayList(); //validate forms for (IOnlineApplicationData form : formList.values()) errors.addAll(form.validate(getGeneralOA(), authUser, request)); if (getPvp2OA() != null) { boolean publicServiceAllowed = ValidationHelper.isPublicServiceAllowed(getPvp2OA().getMetaDataURL()); if (!publicServiceAllowed && !getGeneralOA().isBusinessService()) { log.info("Metadata URL " + getPvp2OA().getMetaDataURL() + " does not allow PublicService."); errors.add(LanguageHelper.getErrorString("validation.interfederation.moaidp.metadataurl.publicservice", new Object[] {getPvp2OA().getMetaDataURL()}, request )); getGeneralOA().setBusinessService(true); } } if (errors.size() > 0) { log.info("IDP-Configuration with ID " + getGeneralOA().getIdentifier() + " has some errors."); for (String el : errors) addActionError(el); formID = Random.nextRandom(); session.setAttribute(Constants.SESSION_FORMID, formID); return Constants.STRUTS_ERROR_VALIDATION; } else { onlineapplication = postProcessSaveOnlineApplication(onlineapplication, !(this instanceof MOAIDPAction)); //set default Target interfederated nameID caluclation if (getPvp2OA() != null) { if (getGeneralOA().isBusinessService()) { IdentificationNumber businessID = onlineapplication.getAuthComponentOA().getIdentificationNumber(); if (businessID == null) { businessID = new IdentificationNumber(); onlineapplication.getAuthComponentOA().setIdentificationNumber(businessID); } businessID.setValue(Constants.PREFIX_WPBK + "MOA-IDP+MOA-IDP"); } else onlineapplication.setTarget("MOA-IDP"); try { save(onlineapplication); } catch (MOADatabaseException e) { log.warn("Online-Application can not be stored.", e); return LanguageHelper.getErrorString("error.db.oa.store", request); } } } //remove session attributes session.setAttribute(Constants.SESSION_OAID, null); addActionMessage(LanguageHelper.getGUIString("webpages.idp.success", getGeneralOA().getIdentifier(), request)); return Constants.STRUTS_SUCCESS; } catch (BasicActionException e) { return Constants.STRUTS_ERROR; } catch (BasicOAActionException e) { addActionError(e.getStrutsError()); return e.getStrutsReturnValue(); } finally { } } public String cancleAndBackIDP() { try { populateBasicInformations(); if (!authUser.isAdmin()) { log.warn("User with ID " + authUser.getUserID() + " not allowed to manage interfederation IDPs."); addActionError(LanguageHelper.getErrorString("errors.notallowed", request)); return Constants.STRUTS_NOTALLOWED; } session.setAttribute(Constants.SESSION_OAID, null); addActionMessage(LanguageHelper.getGUIString("webpages.idp.cancle", getGeneralOA().getIdentifier(), request)); return Constants.STRUTS_SUCCESS; } catch (BasicActionException e) { return Constants.STRUTS_ERROR; } finally { } } public String deleteIDP() { String oaidentifier = null; try { populateBasicInformations(); if (!authUser.isAdmin()) { log.warn("User with ID " + authUser.getUserID() + " not allowed to manage interfederation IDPs."); addActionError(LanguageHelper.getErrorString("errors.notallowed", request)); return Constants.STRUTS_NOTALLOWED; } oaidentifier = preProcessDeleteOnlineApplication(); session.setAttribute(Constants.SESSION_OAID, null); OnlineApplication onlineapplication = configuration.getDbRead().getOnlineApplication(oaidentifier); // try { // if (onlineapplication.getAuthComponentOA().getOAPVP2() != null && // MiscUtil.isNotEmpty(onlineapplication.getAuthComponentOA().getOAPVP2().getMetadataURL())) { // MOAIDConfiguration moaconfig = configuration.getDbRead().getMOAIDConfiguration(); // moaconfig.setPvp2RefreshItem(new Date()); // ConfigurationDBUtils.saveOrUpdate(moaconfig); // // } // } catch (Throwable e) { // log.info("Found no MetadataURL in OA-Databaseconfig!", e); // } if (delete(onlineapplication)) { addActionMessage(LanguageHelper.getGUIString("webpages.oaconfig.delete.message", oaidentifier, request)); return Constants.STRUTS_SUCCESS; } else { addActionError(LanguageHelper.getGUIString("webpages.oaconfig.delete.error", oaidentifier, request)); return Constants.STRUTS_SUCCESS; } } catch (BasicActionException e) { return Constants.STRUTS_ERROR; } catch (BasicOAActionException e) { addActionError(e.getStrutsError()); return e.getStrutsReturnValue(); } finally { } } /** * @param oa */ private void parseOAToForm(OnlineApplication oa) { List errors = new ArrayList(); for (IOnlineApplicationData form : formList.values()) { List error = form.parse(oa, authUser, request); if (error != null) errors.addAll(error); } if (errors.size() > 0) { for (String el : errors) addActionError(el); } setNewOA(false); formID = Random.nextRandom(); session.setAttribute(Constants.SESSION_FORMID, formID); session.setAttribute(Constants.SESSION_OAID, oaid); } /** * @return the formOAs */ public List getFormOAs() { return formOAs; } public OAMOAIDPInterfederationConfig getMoaIDP() { return (OAMOAIDPInterfederationConfig) formList.get(new OAMOAIDPInterfederationConfig().getName()); } public void setMoaIDP(OAMOAIDPInterfederationConfig pvp2oa) { formList.put(pvp2oa.getName(), pvp2oa); } public PVPGatewayInterfederationConfig getPVPGateway() { return (PVPGatewayInterfederationConfig) formList.get(new PVPGatewayInterfederationConfig().getName()); } public void setPVPGateway(PVPGatewayInterfederationConfig val) { formList.put(val.getName(), val); } /** * @return the formOA */ public OATargetConfiguration getTargetConfig() { return (OATargetConfiguration) formList.get(new OATargetConfiguration().getName()); } /** * @param formOA the formOA to set */ public void setTargetConfig(OATargetConfiguration formOA) { formList.put(formOA.getName(), formOA); } /** * @return the formOA */ public FormularCustomization getFormOA() { return (FormularCustomization) formList.get(new FormularCustomization(null).getName()); } /** * @param formOA the formOA to set */ public void setFormOA(FormularCustomization formOA) { formList.put(formOA.getName(), formOA); } public OASTORKConfig getStorkOA() { return (OASTORKConfig) formList.get(new OASTORKConfig().getName()); } public void setStorkOA(OASTORKConfig storkOA) { formList.put(storkOA.getName(), storkOA); } public OAAuthenticationData getAuthOA() { return (OAAuthenticationData) formList.get(new OAAuthenticationData().getName()); } public void setAuthOA(OAAuthenticationData generalOA) { formList.put(generalOA.getName(), generalOA); } /** * @return the interfederationType */ public String getInterfederationType() { return interfederationType; } /** * @param interfederationType the interfederationType to set */ public void setInterfederationType(String interfederationType) { this.interfederationType = interfederationType; } }