package at.gv.egovernment.moa.id.configuration.struts.action; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import com.opensymphony.xwork2.ActionSupport; 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.dao.config.OnlineApplication; import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; 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.data.OAListElement; import at.gv.egovernment.moa.id.configuration.exception.ConfigurationException; import at.gv.egovernment.moa.id.configuration.helper.LanguageHelper; import at.gv.egovernment.moa.id.configuration.validation.ValidationHelper; import at.gv.egovernment.moa.util.MiscUtil; public class ListOAsAction extends ActionSupport implements ServletRequestAware, ServletResponseAware { private final Logger log = Logger.getLogger(ListOAsAction.class); private static final long serialVersionUID = 1L; private HttpServletRequest request; private HttpServletResponse response; private ConfigurationProvider configuration; private List formOAs; private AuthenticatedUser authUser; private String friendlyname; public ListOAsAction() throws ConfigurationException { configuration = ConfigurationProvider.getInstance(); } public String listAllOnlineAppliactions() { Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { authUser = (AuthenticatedUser) authUserObj; List dbOAs = null; if (authUser.isAdmin()) { dbOAs = ConfigurationDBRead.getAllOnlineApplications(); } else { UserDatabase authUserDB = ConfigurationDBRead.getUserWithID(authUser.getUserID()); dbOAs = authUserDB.getRegistratedOAs(); } addFormOAs(dbOAs); return Constants.STRUTS_SUCCESS; } return Constants.STRUTS_ERROR; } public String searchOAInit() { Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { authUser = (AuthenticatedUser) authUserObj; formOAs = null; friendlyname = ""; return Constants.STRUTS_SUCCESS; } else { return Constants.STRUTS_REAUTHENTICATE; } } public String searchOA() { Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { authUser = (AuthenticatedUser) authUserObj; 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.containsPotentialCSSCharacter(friendlyname, false)) { log.warn("SearchOA textfield contains potential XSS characters"); addActionError(LanguageHelper.getErrorString("validation.general.oafriendlyname", new Object[] {ValidationHelper.getPotentialCSSCharacter(false)}, request)); return Constants.STRUTS_SUCCESS; } } List dbOAs = null; if (authUser.isAdmin()) { dbOAs = ConfigurationDBRead.searchOnlineApplications(friendlyname); } else { dbOAs = ConfigurationDBRead.searchOnlineApplicationsFromUser(authUser.getUserID(), friendlyname); } addFormOAs(dbOAs); return Constants.STRUTS_SUCCESS; } return Constants.STRUTS_REAUTHENTICATE; } private void addFormOAs(List dbOAs) { formOAs = new ArrayList(); if (dbOAs == null) { addActionError(LanguageHelper.getErrorString("errors.listOAs.noOA", request)); } else { for (OnlineApplication dboa : dbOAs) { OAListElement listoa = new OAListElement(); listoa.setActive(dboa.isIsActive()); listoa.setDataBaseID(dboa.getHjid()); listoa.setOaFriendlyName(dboa.getFriendlyName()); listoa.setOaIdentifier(dboa.getPublicURLPrefix()); listoa.setOaType(dboa.getType()); formOAs.add(listoa); } } } public void setServletResponse(HttpServletResponse arg0) { this.response = arg0; } public void setServletRequest(HttpServletRequest arg0) { this.request = arg0; } /** * @return the authUser */ public AuthenticatedUser getAuthUser() { return authUser; } /** * @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; } }