package at.gv.egovernment.moa.id.auth.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringEscapeUtils; import at.gv.egovernment.moa.id.auth.MOAIDAuthInitializer; import at.gv.egovernment.moa.id.auth.builder.StartAuthenticationBuilder; import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; import at.gv.egovernment.moa.id.auth.exception.MOAIDException; import at.gv.egovernment.moa.id.auth.exception.WrongParametersException; import at.gv.egovernment.moa.id.auth.parser.StartAuthentificationParameterParser; 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.config.auth.AuthConfigurationProvider; import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import at.gv.egovernment.moa.id.storage.AuthenticationSessionStoreage; import at.gv.egovernment.moa.id.util.MOAIDMessageProvider; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; import at.gv.egovernment.moa.util.StringUtils; public class GenerateIFrameTemplateServlet extends AuthServlet { private static final long serialVersionUID = 1L; public void init(ServletConfig servletConfig) throws ServletException { // try { super.init(servletConfig); // MOAIDAuthInitializer.initialize(); // Logger.debug("default platform file.encoding: " + System.getProperty("file.encoding")); // Logger.info(MOAIDMessageProvider.getInstance().getMessage("init.00", null)); // } // catch (Exception ex) { // Logger.fatal(MOAIDMessageProvider.getInstance().getMessage("init.02", null), ex); // throw new ServletException(ex); // } } protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Logger.info("Receive " + GenerateIFrameTemplateServlet.class + " Request"); String pendingRequestID = null; try { String bkuid = req.getParameter(PARAM_BKU); String useMandate = req.getParameter(PARAM_USEMANDATE); String ccc = req.getParameter(PARAM_CCC); String moasessionid = req.getParameter(PARAM_SESSIONID); moasessionid = StringEscapeUtils.escapeHtml(moasessionid); AuthenticationSession moasession = null; try { //moasessionid = (String) req.getSession().getAttribute(AuthenticationManager.MOA_SESSION); pendingRequestID = AuthenticationSessionStoreage.getPendingRequestID(moasessionid); moasession = AuthenticationSessionStoreage.getSession(moasessionid); AuthenticationSessionStoreage.changeSessionID(moasession); } catch (MOADatabaseException e) { Logger.info("MOASession with SessionID="+ moasessionid + " is not found in Database"); throw new MOAIDException("init.04", new Object[] { moasessionid}); } catch (Throwable e) { Logger.info("No HTTP Session found!"); throw new MOAIDException("auth.18", new Object[] {}); } //load OA Config OAAuthParameter oaParam = AuthConfigurationProvider.getInstance() .getOnlineApplicationParameter(moasession.getOAURLRequested()); if (oaParam == null) throw new AuthenticationException("auth.00", new Object[] { moasession.getOAURLRequested() }); else { //load Parameters from config String target = oaParam.getTarget(); String bkuURL = oaParam.getBKUURL(bkuid); if (MiscUtil.isEmpty(bkuURL)) { Logger.info("No OA specific BKU defined. Use BKU from default configuration"); bkuURL = AuthConfigurationProvider.getInstance().getDefaultBKUURL(bkuid); } String templateURL = AuthConfigurationProvider.getInstance().getSLRequestTemplates(bkuid); if (oaParam.isOnlyMandateAllowed()) useMandate = "true"; if (!oaParam.isShowMandateCheckBox()) useMandate = "false"; //parse all OA parameters i StartAuthentificationParameterParser.parse(moasession, target, moasession.getOAURLRequested(), bkuURL, templateURL, useMandate, ccc, moasession.getModul(), moasession.getAction(), req); } StartAuthenticationBuilder startauth = StartAuthenticationBuilder.getInstance(); String getIdentityLinkForm = startauth.build(moasession, req, resp); //store MOASession try { AuthenticationSessionStoreage.storeSession(moasession); } catch (MOADatabaseException e) { Logger.error("Database Error! MOASession is not stored!"); throw new MOAIDException("init.04", new Object[] { moasession.getSessionID()}); } if (!StringUtils.isEmpty(getIdentityLinkForm)) { resp.setContentType("text/html;charset=UTF-8"); PrintWriter out = new PrintWriter(resp.getOutputStream()); out.print(getIdentityLinkForm); out.flush(); Logger.debug("Finished GET "+GenerateIFrameTemplateServlet.class); } } catch (WrongParametersException ex) { handleWrongParameters(ex, req, resp); } catch (MOAIDException ex) { handleError(null, ex, req, resp, pendingRequestID); } finally { ConfigurationDBUtils.closeSession(); } } }