aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java263
1 files changed, 0 insertions, 263 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java
deleted file mode 100644
index e04600b42..000000000
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/entrypoints/AuthDispatcherServlet.java
+++ /dev/null
@@ -1,263 +0,0 @@
-package at.gv.egovernment.moa.id.entrypoints;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import at.gv.egovernment.moa.id.MOAIDException;
-import at.gv.egovernment.moa.id.auth.MOAIDAuthInitializer;
-import at.gv.egovernment.moa.id.auth.WrongParametersException;
-import at.gv.egovernment.moa.id.auth.servlet.AuthServlet;
-import at.gv.egovernment.moa.id.moduls.AuthenticationManager;
-import at.gv.egovernment.moa.id.moduls.IAction;
-import at.gv.egovernment.moa.id.moduls.IModulInfo;
-import at.gv.egovernment.moa.id.moduls.IRequest;
-import at.gv.egovernment.moa.id.moduls.ModulStorage;
-import at.gv.egovernment.moa.id.moduls.NoPassivAuthenticationException;
-import at.gv.egovernment.moa.id.moduls.ServletInfo;
-import at.gv.egovernment.moa.id.moduls.ServletType;
-import at.gv.egovernment.moa.id.util.MOAIDMessageProvider;
-import at.gv.egovernment.moa.logging.Logger;
-
-public class AuthDispatcherServlet extends AuthServlet {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public static final String PARAM_TARGET_PATH = "mod";
- public static final String PARAM_TARGET_PROTOCOL = "action";
-/* public static final String PARAM_DISPATCHER_TARGETS = "DispatcherTargets";
- public static final String PARAM_DISPATCHER_TYPE = "DispatcherType";
- public static final String PARAM_DISPATCHER_TYPE_UNAUTH = "UNAUTH";
- public static final String PARAM_DISPATCHER_TYPE_AUTH = "AUTH";
- public static String SYSTEM_NEWLINE = System.getProperty("line.separator");
-
- private HashMap<String, HashMap<String, HttpServlet>> endpointMap = new HashMap<String, HashMap<String, HttpServlet>>();
-
- private void registerModule(IModulInfo modulInfo) {
-
- HashMap<String, HttpServlet> tempMap = new HashMap<String, HttpServlet>();
-
- try {
-
- String path = modulInfo.getPath();
-
- if (path == null) {
- throw new Exception(String.format(
- "%s does not return a valid target path!",
- new Object[] { modulInfo.getClass().getName() }));
- }
-
- Logger.debug("Registering: " + modulInfo.getName() + " under "
- + path);
-
- List<ServletInfo> servletInfos = modulInfo.getServlets();
-
- Iterator<ServletInfo> servletInfoIterator = servletInfos.iterator();
-
- while (servletInfoIterator.hasNext()) {
-
- ServletInfo servletInfo = servletInfoIterator.next();
-
- if (servletInfo.getType() == ServletType.AUTH) {
- HttpServlet servlet = servletInfo.getServletInstance();
- String target = servletInfo.getTarget();
-
- if (target == null) {
- throw new Exception(
- String.format(
- "%s does not return a valid target identifier!",
- new Object[] { servlet.getClass()
- .getName() }));
- }
-
- if (tempMap.containsKey(target)) {
- throw new Exception(String.format(
- "%s tried to overwrite %s/%s", new Object[] {
- servlet.getClass().getName(), path,
- target }));
- }
-
- tempMap.put(target, servlet);
- Logger.info("Registered Servlet class: "
- + servlet.getClass().getName() + " OK");
- }
-
- }
-
- // when there was no error we register all servlets into the real
- // endpoint map ...
- if (!tempMap.isEmpty()) {
- endpointMap.put(path, tempMap);
- }
- } catch (Throwable e) {
- Logger.error("Registering Modul class: "
- + modulInfo.getClass().getName() + " FAILED!!", e);
- }
- }
-*/
- @Override
- public void init(ServletConfig config) throws ServletException {
- try {
- super.init(config);
- MOAIDAuthInitializer.initialize();
- Logger.info(MOAIDMessageProvider.getInstance().getMessage(
- "init.00", null));
- } catch (Exception ex) {
- Logger.fatal(
- MOAIDMessageProvider.getInstance().getMessage("init.02",
- null), ex);
- throw new ServletException(ex);
- }
- Logger.info("Auth dispatcher Servlet initialization");
-/*
- List<IModulInfo> modules = ModulStorage.getAllModules();
- Iterator<IModulInfo> it = modules.iterator();
- while (it.hasNext()) {
- IModulInfo info = it.next();
- String targetClass = info.getClass().getName();
- try {
- registerModule(info);
- } catch (Throwable e) {
- Logger.error("Registering Class " + targetClass + " FAILED!!",
- e);
- }
- }*/
- }
-
- protected void processRequest(HttpServletRequest req,
- HttpServletResponse resp) throws ServletException, IOException {
- try {
- Object pathObject = req.getParameter(PARAM_TARGET_PATH);
- String path = null;
-
- HttpSession session = req.getSession();
-
- if (pathObject != null && (pathObject instanceof String)) {
- path = (String) pathObject;
- }
-
- if (path == null) {
- path = (String) session.getAttribute(PARAM_TARGET_PATH);
- }
-
- Object protocolObject = req.getParameter(PARAM_TARGET_PROTOCOL);
- String protocol = null;
- if (protocolObject != null && (protocolObject instanceof String)) {
- protocol = (String) protocolObject;
- }
-
- if (protocol == null) {
- protocol = (String) session.getAttribute(PARAM_TARGET_PROTOCOL);
- }
-
- Logger.debug("dispatching to " + path + " protocol " + protocol);
-/*
- if (path != null && protocol != null
- && endpointMap.containsKey(path)) {
-
- IModulInfo info = ModulStorage.getModuleByPath(path);
-
- if (info == null) {
- resp.sendError(HttpServletResponse.SC_NOT_FOUND);
- Logger.error("Path " + path + " has no module registered");
- return;
- }
-
- IAction action = info.getAction(protocol);
-
- if (action == null) {
- resp.sendError(HttpServletResponse.SC_NOT_FOUND);
- Logger.error("Action " + protocol + " is not available!");
- return;
- }
-
-
-
- try {
- IRequest configuration = info.preProcess(req, resp, protocol);
-
- if(configuration.forceAuth()) {
- session.setAttribute(PARAM_TARGET_PATH, path);
- session.setAttribute(PARAM_TARGET_PROTOCOL, protocol);
-
- AuthenticationManager.doAuthentication(req, resp,
- configuration);
- return;
- }
-
- if (!AuthenticationManager.isAuthenticated(req, resp)) {
-
- session.setAttribute(PARAM_TARGET_PATH, path);
- session.setAttribute(PARAM_TARGET_PROTOCOL, protocol);
-
- if(configuration.isPassiv()) {
- throw new NoPassivAuthenticationException();
- }
-
- AuthenticationManager.doAuthentication(req, resp,
- configuration);
- return;
- }
-
- HashMap<String, HttpServlet> pathMap = endpointMap.get(path);
- Logger.debug("found path");
- if (pathMap.containsKey(protocol)) {
- Logger.debug("found protocol");
- try {
- HttpServlet servlet = (HttpServlet) pathMap
- .get(protocol);
- String forward = servlet.getClass().getName();
- Logger.info("Forwarding to Servlet: " + forward);
- getServletContext().getNamedDispatcher(forward)
- .forward(req, resp);
- // TODO: disabled SSO
- AuthenticationManager.logout(req, resp);
- return;
- } catch (Throwable e) {
- e.printStackTrace();
- resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- }
- }
- catch (Throwable e) {
- // Try handle module specific, if not possible rethrow
- if(!info.generateErrorMessage(e, req, resp)) {
- throw e;
- }
- }
- }*/
- resp.sendError(HttpServletResponse.SC_NOT_FOUND);
- }/* catch (WrongParametersException ex) {
- handleWrongParameters(ex, req, resp);
- } catch (MOAIDException ex) {
- handleError(null, ex, req, resp);
- } */catch (Throwable e) {
- e.printStackTrace();
- resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
-
- }
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- processRequest(req, resp);
- }
-
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- processRequest(req, resp);
- }
-}