/******************************************************************************* * 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 at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; import at.gv.egovernment.moa.id.commons.db.dao.config.deprecated.OnlineApplication; import at.gv.egovernment.moa.id.commons.validation.ValidationHelper; import at.gv.egovernment.moa.id.config.webgui.exception.ConfigurationException; import at.gv.egovernment.moa.id.configuration.Constants; import at.gv.egovernment.moa.id.configuration.data.OAListElement; import at.gv.egovernment.moa.id.configuration.exception.BasicActionException; import at.gv.egovernment.moa.id.configuration.helper.FormDataHelper; import at.gv.egovernment.moa.id.configuration.helper.LanguageHelper; import at.gv.egovernment.moa.util.MiscUtil; import lombok.extern.slf4j.Slf4j; @Slf4j public class ListOAsAction extends BasicAction { private static final long serialVersionUID = 1L; private List formOAs; private String friendlyname; public ListOAsAction() throws ConfigurationException { // configuration = ConfigurationProvider.getInstance(); } public String listAllOnlineAppliactions() { try { populateBasicInformations(); } catch (final BasicActionException e) { return Constants.STRUTS_ERROR; } List dbOAs = null; if (authUser.isAdmin()) { dbOAs = configuration.getDbRead().getAllOnlineApplications(); } else { final UserDatabase authUserDB = configuration.getUserManagement().getUserWithID(authUser.getUserID()); if (authUserDB != null) { for (final String el : authUserDB.getOnlineApplication()) { dbOAs.add(configuration.getDbRead().getOnlineApplication(Long.valueOf(el))); } } } if (dbOAs == null || dbOAs.size() == 0) { addActionError(LanguageHelper.getErrorString("errors.listOAs.noOA", request)); } else { formOAs = FormDataHelper.populateFormWithOAs(dbOAs); } session.setAttribute(Constants.SESSION_RETURNAREA, Constants.STRUTS_RETURNAREA_VALUES.main.name()); return Constants.STRUTS_SUCCESS; } public String searchOAInit() { try { populateBasicInformations(); } catch (final BasicActionException e) { return Constants.STRUTS_ERROR; } formOAs = null; friendlyname = ""; return Constants.STRUTS_SUCCESS; } public String searchOA() { try { populateBasicInformations(); } catch (final BasicActionException e) { return Constants.STRUTS_ERROR; } if (MiscUtil.isEmpty(friendlyname)) { log.info("SearchOA textfield is empty"); addActionError(LanguageHelper.getErrorString("validation.general.oafriendlyname.empty", request)); return Constants.STRUTS_SUCCESS; } else { if (ValidationHelper.containsNotValidCharacter(friendlyname, false)) { log.warn("SearchOA textfield contains potential XSS characters"); addActionError(LanguageHelper.getErrorString("validation.general.oafriendlyname.valid", new Object[] { ValidationHelper.getNotValidCharacter(false) }, request)); return Constants.STRUTS_SUCCESS; } } List dbOAs = null; if (authUser.isAdmin()) { dbOAs = configuration.getDbRead().searchOnlineApplications(friendlyname); } else { final UserDatabase authUserDB = configuration.getUserManagement().getUserWithID(authUser.getUserID()); if (authUserDB != null) { final List alldbOAs = authUserDB.getOnlineApplication(); dbOAs = new ArrayList<>(); for (final String el : alldbOAs) { final OnlineApplication oa = configuration.getDbRead().getOnlineApplication(Long.valueOf(el)); if (oa.getPublicURLPrefix() .toLowerCase().indexOf(friendlyname.toLowerCase()) > -1) { dbOAs.add(oa); } } } } if (dbOAs == null || dbOAs.size() == 0) { log.debug("No IDPs found with Identifier " + friendlyname); addActionError(LanguageHelper.getErrorString("errors.listOAs.noOA", request)); } else { formOAs = FormDataHelper.populateFormWithOAs(dbOAs); } return Constants.STRUTS_SUCCESS; } /** * @return the formOAs */ public List getFormOAs() { return formOAs; } /** * @return the friendlyname */ public String getFriendlyname() { return friendlyname; } /** * @param friendlyname the friendlyname to set */ public void setFriendlyname(String friendlyname) { this.friendlyname = friendlyname; } }