diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2013-07-26 17:07:15 +0200 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2013-07-26 17:07:15 +0200 |
commit | 99694b29f82f858f5b6163e6a3d6c11caaeb487e (patch) | |
tree | b46883533cd71c9f47047c38b5c43469a311a731 /id/ConfigWebTool/src/main/java/at/gv | |
parent | cc2e2e4ecf5bd8c4bbe16edba5a7d63fa808adcb (diff) | |
download | moa-id-spss-99694b29f82f858f5b6163e6a3d6c11caaeb487e.tar.gz moa-id-spss-99694b29f82f858f5b6163e6a3d6c11caaeb487e.tar.bz2 moa-id-spss-99694b29f82f858f5b6163e6a3d6c11caaeb487e.zip |
Configuration Web-Application
Diffstat (limited to 'id/ConfigWebTool/src/main/java/at/gv')
10 files changed, 781 insertions, 0 deletions
diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/Constants.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/Constants.java new file mode 100644 index 000000000..a5a5de33c --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/Constants.java @@ -0,0 +1,11 @@ +package at.gv.egovernment.moa.id.configuration; + +public class Constants { + public static final String STRUTS_SUCCESS = "success"; + public static final String STRUTS_ERROR = "error"; + + + public static final String SESSION_AUTH = "authsession"; + public static final String SESSION_AUTH_ERROR = "authsessionerror"; + +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/auth/AuthenticatedUser.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/auth/AuthenticatedUser.java new file mode 100644 index 000000000..3ff48e92b --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/auth/AuthenticatedUser.java @@ -0,0 +1,117 @@ +package at.gv.egovernment.moa.id.configuration.auth; + +import java.util.Date; + +public class AuthenticatedUser { + + private boolean isAuthenticated = false; + private boolean isAdmin = false; + + private long userID; + private String givenName; + private String familyName; + private Date lastLogin; + + public AuthenticatedUser() { + + } + + public AuthenticatedUser(long userID, String givenName, String familyName, + boolean isAuthenticated, boolean isAdmin) { + + this.familyName = familyName; + this.givenName = givenName; + this.userID = userID; + this.isAdmin = isAdmin; + this.isAuthenticated = isAuthenticated; + this.lastLogin = new Date(); + } + + /** + * @return the isAuthenticated + */ + public boolean isAuthenticated() { + return isAuthenticated; + } + + /** + * @param isAuthenticated the isAuthenticated to set + */ + public void setAuthenticated(boolean isAuthenticated) { + this.isAuthenticated = isAuthenticated; + } + + /** + * @return the isAdmin + */ + public boolean isAdmin() { + return isAdmin; + } + + /** + * @param isAdmin the isAdmin to set + */ + public void setAdmin(boolean isAdmin) { + this.isAdmin = isAdmin; + } + + /** + * @return the userID + */ + public long getUserID() { + return userID; + } + + /** + * @param userID the userID to set + */ + public void setUserID(long userID) { + this.userID = userID; + } + + /** + * @return the givenName + */ + public String getGivenName() { + return givenName; + } + + /** + * @param givenName the givenName to set + */ + public void setGivenName(String givenName) { + this.givenName = givenName; + } + + /** + * @return the familyName + */ + public String getFamilyName() { + return familyName; + } + + /** + * @param familyName the familyName to set + */ + public void setFamilyName(String familyName) { + this.familyName = familyName; + } + + /** + * @return the lastLogin + */ + public Date getLastLogin() { + return lastLogin; + } + + /** + * @param lastLogin the lastLogin to set + */ + public void setLastLogin(Date lastLogin) { + this.lastLogin = lastLogin; + } + + + + +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java new file mode 100644 index 000000000..07f599284 --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java @@ -0,0 +1,80 @@ +package at.gv.egovernment.moa.id.configuration.config; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; + +import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; +import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; +import at.gv.egovernment.moa.id.configuration.exception.ConfigurationException; +import at.gv.egovernment.moa.logging.Logger; + + +public class ConfigurationProvider { + + private static final String SYSTEM_PROP_CONFIG = "moa.id.webconfig"; + + private static ConfigurationProvider instance; + private Properties props; + + public static ConfigurationProvider getInstance() throws ConfigurationException { + if (instance == null) { + instance = new ConfigurationProvider(); + } + + return instance; + } + + private ConfigurationProvider() throws ConfigurationException { + inizialize(); + } + + private void inizialize() throws ConfigurationException { + + String configFileName = System.getProperty(SYSTEM_PROP_CONFIG); + + if (configFileName == null) { + throw new ConfigurationException("config.01"); + } + Logger.info("Loading MOA-ID-AUTH configuration " + configFileName); + + //Initial Hibernate Framework + Logger.trace("Initializing Hibernate framework."); + + //Load MOAID-2.0 properties file + File propertiesFile = new File(configFileName); + FileInputStream fis; + props = new Properties(); + + + try { + fis = new FileInputStream(propertiesFile); + props.load(fis); + + // initialize hibernate + synchronized (ConfigurationProvider.class) { + + //Initial config Database + ConfigurationDBUtils.initHibernate(props); + } + Logger.trace("Hibernate initialization finished."); + + + + } catch (FileNotFoundException e) { + throw new ConfigurationException("config.01", e); + } catch (IOException e) { + throw new ConfigurationException("config.02", e); + } catch (MOADatabaseException e) { + throw new ConfigurationException("config.03", e); + } + + } + + public boolean isLoginDeaktivated() { + String result = props.getProperty("general.login.deaktivate", "false"); + return Boolean.parseBoolean(result); + } +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/data/OAListElement.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/data/OAListElement.java new file mode 100644 index 000000000..0ea21617e --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/data/OAListElement.java @@ -0,0 +1,77 @@ +package at.gv.egovernment.moa.id.configuration.data; + +public class OAListElement { + + private long dataBaseID; + private String oaIdentifier; + private String oaFriendlyName; + private String oaType; + private boolean isActive; + + + /** + * @return the dataBaseID + */ + public long getDataBaseID() { + return dataBaseID; + } + /** + * @param dataBaseID the dataBaseID to set + */ + public void setDataBaseID(long dataBaseID) { + this.dataBaseID = dataBaseID; + } + /** + * @return the oaIdentifier + */ + public String getOaIdentifier() { + return oaIdentifier; + } + /** + * @param oaIdentifier the oaIdentifier to set + */ + public void setOaIdentifier(String oaIdentifier) { + this.oaIdentifier = oaIdentifier; + } + /** + * @return the oaFriendlyName + */ + public String getOaFriendlyName() { + return oaFriendlyName; + } + /** + * @param oaFriendlyName the oaFriendlyName to set + */ + public void setOaFriendlyName(String oaFriendlyName) { + this.oaFriendlyName = oaFriendlyName; + } + /** + * @return the oaType + */ + public String getOaType() { + return oaType; + } + /** + * @param oaType the oaType to set + */ + public void setOaType(String oaType) { + this.oaType = oaType; + } + /** + * @return the isActive + */ + public boolean isActive() { + return isActive; + } + /** + * @param isActive the isActive to set + */ + public void setActive(boolean isActive) { + this.isActive = isActive; + } + + public String getIsActive(){ + return String.valueOf(isActive); + } + +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/exception/ConfigurationException.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/exception/ConfigurationException.java new file mode 100644 index 000000000..39a18309a --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/exception/ConfigurationException.java @@ -0,0 +1,17 @@ +package at.gv.egovernment.moa.id.configuration.exception; + +import at.gv.egovernment.moa.id.configuration.helper.LanguageHelper; + +public class ConfigurationException extends Exception { + + private static final long serialVersionUID = 1L; + + public ConfigurationException(String errorname) { + super(LanguageHelper.getErrorString(errorname, null)); + } + + public ConfigurationException(String errorname, Throwable e) { + super(LanguageHelper.getErrorString(errorname, null), e); + } + +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/filter/AuthenticationFilter.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/filter/AuthenticationFilter.java new file mode 100644 index 000000000..517786d11 --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/filter/AuthenticationFilter.java @@ -0,0 +1,236 @@ +package at.gv.egovernment.moa.id.configuration.filter; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.util.regex.Pattern; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +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.exception.ConfigurationException; +import at.gv.egovernment.moa.util.MiscUtil; +import at.gv.util.ToStringUtil; +import at.gv.util.WebAppUtil; + +public class AuthenticationFilter implements Filter{ + + private final Logger log = Logger.getLogger(AuthenticationFilter.class); + + private static ConfigurationProvider config; + + public static final String STORED_REQUEST_URL_ID = String.class.getName() + ":" + "storedRequestURL"; + public static final String WEB_XML_INIT_PARAM_LOGIN_PAGE = "loginPage"; + public static final String WEB_XML_INIT_PARAM_ERROR_PAGE = "errorPage"; + public static final String WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE = "authenticatedPage"; // optional + public static final String WEB_XML_INIT_PARAM_SESSION_LOST_PAGE = "sessionLostPage"; // optional + public static final String WEB_XML_INIT_PARAM_ALLOWED_LIST = "allowedList"; + public static final String WEB_XML_INIT_PARAM_ALLOWED_REGEX = "allowed"; + + private static final String WEB_XML_INIT_PARAM_EXCLUDED_PAGES_DELIMITER = ","; + + private static String loginPage = null; + private boolean loginPageForward = true; + private static String errorPage = null; + private static String authenticatedPage = null; + private static String sessionLostPage = null; + + private static String[] excludedPages = null; + private static Pattern excludedRegEx = null; + + + + public AuthenticationFilter() throws ServletException { + try { + config = ConfigurationProvider.getInstance(); + + } catch (ConfigurationException e) { + throw new ServletException(AuthenticationFilter.class + ": Configuration can not be loaded!", e); + } + } + + public static String getErrorPage() { + return errorPage; + } + + public static String getAuthenticatedPage() { + return authenticatedPage; + } + + public static String getLoginPage() { + return loginPage; + } + + public static String getSessionLostPage() { + return sessionLostPage; + } + + private boolean isExcluded(String url) { + boolean excluded = false; + if (MiscUtil.isNotEmpty(excludedPages)) { + for (String candidate : excludedPages) { + if (StringUtils.upperCase(url).endsWith(StringUtils.upperCase(candidate))) { + excluded = true; + break; + } + } + } + if (excludedRegEx != null && !excluded) { + // log.debug("Trying to match regex \"{}\" with \"{}\".", + // excludedRegEx.toString(), url); + if (excludedRegEx.matcher(url).matches()) { + excluded = true; + } + } + log.debug("URL \"" + url + "\" is " + (excluded ? "" : "NOT ") + "excluded from filter."); + return excluded; + } + + + public void destroy() { + log.trace("Shutting down" + this.getClass().getName() + "..."); + + } + + public void doFilter(ServletRequest req, ServletResponse resp, + FilterChain filterchain) throws IOException, ServletException { + + HttpServletRequest httpServletRequest = (HttpServletRequest) req; + HttpServletResponse httpServletResponse = (HttpServletResponse) resp; + + HttpSession session = httpServletRequest.getSession(); + + Object authuser = session.getAttribute(Constants.SESSION_AUTH); + + String requestURL = WebAppUtil.getRequestURLWithParameters(httpServletRequest, true); + + log.trace("Request URL: " + requestURL); + + if (authuser == null && !this.isExcluded(requestURL)) { + + if (config.isLoginDeaktivated()) { + //add dummy Daten + log.warn("Authentication is deaktivated. Dummy authentication-information are used!"); + + if (authuser == null) { + + authuser = new AuthenticatedUser(0000000, "Max", "TestUser", true, true); + httpServletRequest.getSession().setAttribute(Constants.SESSION_AUTH, authuser); + } + + if (MiscUtil.isNotEmpty(getAuthenticatedPage())) { + if (loginPageForward) { + log.debug("Authenticated page is set. Forwarding to \"" + getAuthenticatedPage() + "\"."); + RequestDispatcher dispatcher = req.getRequestDispatcher(getAuthenticatedPage()); + dispatcher.forward(httpServletRequest, httpServletResponse); + } else { + log.debug("Authenticated page is set. Redirecting to \"" + getAuthenticatedPage() + "\"."); + httpServletResponse.sendRedirect(httpServletResponse.encodeRedirectURL(getAuthenticatedPage())); + } + return; + } + + } else { + //check login Daten + if (MiscUtil.isNotEmpty(getAuthenticatedPage())) { + log.debug("Unable to find authentication data. Authenticated page is given so there is no need to save original request url. " + (loginPageForward ? "Forwarding" : "Redirecting") + " to login page \"" + loginPage + "\"."); + + } + else { + log.debug("Unable to find authentication data. Storing request url and " + (loginPageForward ? "forwarding" : "redirecting") + " to login page \"" + loginPage + "\"."); + // TODO: save HttpServletRequest + // log.debug("new CustomHttpServletRequest(request).toString() = + // {}", new + // CustomHttpServletRequest(httpServletRequest).toString()); + session.setAttribute(STORED_REQUEST_URL_ID, requestURL); + } + + if (loginPageForward) { + RequestDispatcher dispatcher = req.getRequestDispatcher(loginPage); + dispatcher.forward(httpServletRequest, httpServletResponse); + + } else { + httpServletResponse.sendRedirect(httpServletResponse.encodeRedirectURL(loginPage)); + + } + + } + } + + filterchain.doFilter(req, resp); + + } + + public void init(FilterConfig filterConfig) throws ServletException { + log.debug("Starting init of " + this.getClass().getName() + "."); + + // login page + loginPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_LOGIN_PAGE)); + if (MiscUtil.isEmpty(loginPage)) { + throw new ServletException("ServletInitParameter \"" + WEB_XML_INIT_PARAM_LOGIN_PAGE + "\" must not be empty."); + } + loginPageForward = false; //!WebAppUtil.isFullQualifiedURL(loginPage); + + // error page + errorPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ERROR_PAGE)); + if (MiscUtil.isEmpty(errorPage)) { + throw new ServletException("ServletInitParameter \"" + WEB_XML_INIT_PARAM_ERROR_PAGE + "\" must not be empty."); + } + + // session lost page + sessionLostPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_SESSION_LOST_PAGE)); + if (MiscUtil.isEmpty(sessionLostPage)) { + log.warn("ServletInitParameter \"" + WEB_XML_INIT_PARAM_SESSION_LOST_PAGE + + "\" is empty. This parameter defines a failsafe url the browser is redirected to if the original url has been lost due to session timeout."); + } + + // authenticated page + authenticatedPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE)); + if (MiscUtil.isEmpty(authenticatedPage)) { + log.debug("ServletInitParameter \"" + WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE + + "\" is empty. This parameter defines the url the user is redirected to (instead of the original url) on successful authentication."); + } + String excluded = filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ALLOWED_LIST); + ArrayList<String> excludedList = new ArrayList<String>(); + if (MiscUtil.isNotEmpty(excluded)) { + StringTokenizer tokenizer = new StringTokenizer(excluded, WEB_XML_INIT_PARAM_EXCLUDED_PAGES_DELIMITER); + while (tokenizer.hasMoreTokens()) { + String ex = StringUtils.trim(tokenizer.nextToken()); + if (MiscUtil.isNotEmpty(ex)) { + excludedList.add(ex); + } + } + } + excludedList.add(loginPage); + excludedList.add(errorPage); + excludedPages = new String[excludedList.size()]; + excludedPages = excludedList.toArray(excludedPages); + + String excludedRegExString = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ALLOWED_REGEX)); + if (MiscUtil.isNotEmpty(excludedRegExString)) { + excludedRegEx = Pattern.compile(excludedRegExString); + } + + log.debug(WEB_XML_INIT_PARAM_LOGIN_PAGE + " [" + (loginPageForward ? "forward" : "redirect") + "] = \"" + loginPage + "\""); + log.debug(WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE + " = \"" + (MiscUtil.isNotEmpty(authenticatedPage) ? authenticatedPage : "<n/a>") + "\""); + log.debug(WEB_XML_INIT_PARAM_ERROR_PAGE + " = \"" + errorPage + "\""); + log.debug(WEB_XML_INIT_PARAM_SESSION_LOST_PAGE + " = \"" + (MiscUtil.isNotEmpty(sessionLostPage) ? sessionLostPage : "<n/a>") + "\""); + log.debug(WEB_XML_INIT_PARAM_ALLOWED_LIST + " = " + ToStringUtil.toString(excludedPages, ", ", "\"")); + log.debug(WEB_XML_INIT_PARAM_ALLOWED_REGEX + " = \"" + (excludedRegEx != null ? excludedRegEx.pattern() : "<n/a>") + "\""); + } + +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/helper/LanguageHelper.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/helper/LanguageHelper.java new file mode 100644 index 000000000..80db5877c --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/helper/LanguageHelper.java @@ -0,0 +1,34 @@ +package at.gv.egovernment.moa.id.configuration.helper; + + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.ResourceBundle; + +import javax.servlet.http.HttpServletRequest; + + +public class LanguageHelper { + + private static ResourceBundle errorRes_DE = ResourceBundle.getBundle("applicationResources", Locale.GERMAN); + private static ResourceBundle guiRes_DE = ResourceBundle.getBundle("applicationResources", Locale.GERMAN); + + public static String getGUIString(String code, HttpServletRequest request) { + return guiRes_DE.getString(code); + } + + public static String getErrorString(String code, HttpServletRequest request) { + return errorRes_DE.getString(code); + } + + public static String getGUIString(String code, String parameter, HttpServletRequest request) { + + return MessageFormat.format(getGUIString(code, request), parameter); + } + + public static String getErrorString(String code, Object[] parameter, HttpServletRequest request) { + + return MessageFormat.format(getGUIString(code, request), parameter); + } +} + diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/IndexAction.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/IndexAction.java new file mode 100644 index 000000000..4e8e44007 --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/IndexAction.java @@ -0,0 +1,32 @@ +package at.gv.egovernment.moa.id.configuration.struts.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.interceptor.ServletRequestAware; +import org.apache.struts2.interceptor.ServletResponseAware; + +import at.gv.egovernment.moa.id.configuration.Constants; +import at.gv.egovernment.moa.id.configuration.config.ConfigurationProvider; +import at.gv.egovernment.moa.id.configuration.exception.ConfigurationException; + +public class IndexAction implements ServletRequestAware, + ServletResponseAware { + + private HttpServletRequest request; + private HttpServletResponse response; + + public String start() { + + return Constants.STRUTS_SUCCESS; + } + + + public void setServletResponse(HttpServletResponse arg0) { + this.response = arg0; + } + public void setServletRequest(HttpServletRequest arg0) { + this.request = arg0; + } + +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ListOAsAction.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ListOAsAction.java new file mode 100644 index 000000000..cc613ef7b --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/ListOAsAction.java @@ -0,0 +1,112 @@ +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.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; + +public class ListOAsAction extends ActionSupport implements ServletRequestAware, + ServletResponseAware { + + private static final long serialVersionUID = 1L; + + private HttpServletRequest request; + private HttpServletResponse response; + + private ConfigurationProvider configuration; + + private List<OAListElement> formOAs; + + + private AuthenticatedUser authUser; + + + 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<OnlineApplication> dbOAs = null; + + if (authUser.isAdmin()) { + dbOAs = ConfigurationDBRead.getAllOnlineApplications(); + + } else { + UserDatabase authUserDB = ConfigurationDBRead.getUserWithID(authUser.getUserID()); + dbOAs = authUserDB.getRegistratedOAs(); + } + + + formOAs = new ArrayList<OAListElement>(); + if (dbOAs == null) { + addActionError(LanguageHelper.getErrorString("errors.listOAs.noOA", request)); + return Constants.STRUTS_SUCCESS; + + } 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); + } + } + + return Constants.STRUTS_SUCCESS; + + } + + return Constants.STRUTS_ERROR; + } + + + 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<OAListElement> getFormOAs() { + return formOAs; + } + +} diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/MainAction.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/MainAction.java new file mode 100644 index 000000000..ba9b0cc3f --- /dev/null +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/MainAction.java @@ -0,0 +1,65 @@ +package at.gv.egovernment.moa.id.configuration.struts.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.interceptor.ServletRequestAware; +import org.apache.struts2.interceptor.ServletResponseAware; + +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.exception.ConfigurationException; + +public class MainAction implements ServletRequestAware, + ServletResponseAware { + + private HttpServletRequest request; + private HttpServletResponse response; + + private ConfigurationProvider configuration; + + + private AuthenticatedUser authUser; + + + public MainAction() throws ConfigurationException { + configuration = ConfigurationProvider.getInstance(); + } + + + public String generateMainFrame() { + + Object authUserObj = request.getSession().getAttribute(Constants.SESSION_AUTH); + + if (authUserObj != null && authUserObj instanceof AuthenticatedUser) { + authUser = (AuthenticatedUser) authUserObj; + + + + + return Constants.STRUTS_SUCCESS; + } + return Constants.STRUTS_ERROR; + + } + + + public void setServletResponse(HttpServletResponse arg0) { + this.response = arg0; + } + public void setServletRequest(HttpServletRequest arg0) { + this.request = arg0; + } + + + /** + * @return the authUser + */ + public AuthenticatedUser getAuthUser() { + return authUser; + } + + + +} |