/** Display the login form. */ public void addBody(Body body) throws SQLException, SAXException, WingException { // Check if the user has previously attempted to login. Request request = ObjectModelHelper.getRequest(objectModel); HttpSession session = request.getSession(); String previousUserName = request.getParameter("username"); // Get any message parameters String header = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER); String message = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE); String characters = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS); if (header != null || message != null || characters != null) { Division reason = body.addDivision("login-reason"); if (header != null) { reason.setHead(message(header)); } else { // Always have a head. reason.setHead("Authentication Required"); } if (message != null) { reason.addPara(message(message)); } if (characters != null) { reason.addPara(characters); } } Division login = body.addInteractiveDivision( "login", contextPath + "/ldap-login", Division.METHOD_POST, "primary"); login.setHead(T_head1); List list = login.addList("ldap-login", List.TYPE_FORM); Text email = list.addItem().addText("username"); email.setRequired(); email.setAutofocus("autofocus"); email.setLabel(T_userName); if (previousUserName != null) { email.setValue(previousUserName); email.addError(T_error_bad_login); } Item item = list.addItem(); Password password = item.addPassword("ldap_password"); password.setRequired(); password.setLabel(T_password); list.addLabel(); Item submit = list.addItem("login-in", null); submit.addButton("submit").setValue(T_submit); }
/** Generate the cache validity object. */ public SourceValidity getValidity() { Request request = ObjectModelHelper.getRequest(objectModel); String previous_username = request.getParameter("username"); // Get any message parameters HttpSession session = request.getSession(); String header = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER); String message = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE); String characters = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS); // If there is a message or previous email attempt then the page is not // cachable if (header == null && message == null && characters == null && previous_username == null) { // Always valid return NOPValidity.SHARED_INSTANCE; } else { // invalid return null; } }
/** * Generate the unique caching key. This key must be unique inside the space of this component. */ public Serializable getKey() { Request request = ObjectModelHelper.getRequest(objectModel); String previous_username = request.getParameter("username"); // Get any message parameters HttpSession session = request.getSession(); String header = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_HEADER); String message = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_MESSAGE); String characters = (String) session.getAttribute(AuthenticationUtil.REQUEST_INTERRUPTED_CHARACTERS); // If there is a message or previous email attempt then the page is not // cachable if (header == null && message == null && characters == null && previous_username == null) { // cacheable return "1"; } else { // Uncachable return "0"; } }
/** * Obtains the submission info for the current submission process. If a submissionInfo object has * already been created for this HTTP request, it is re-used, otherwise it is created. * * @param objectModel the cocoon Objectmodel * @param workspaceID the workspaceID of the submission info to obtain * @return a SubmissionInfo object */ public static SubmissionInfo obtainSubmissionInfo(Map objectModel, String workspaceID) throws SQLException, IOException, AuthorizeException { Request request = ObjectModelHelper.getRequest(objectModel); Context context = ContextUtil.obtainContext(objectModel); // try loading subInfo from HTTP request SubmissionInfo subInfo = (SubmissionInfo) request.getAttribute(DSPACE_SUBMISSION_INFO); // get the submission represented by the WorkspaceID InProgressSubmission submission = findSubmission(context, workspaceID); // if no submission info, or wrong submission info, reload it! if ((subInfo == null && submission != null) || (subInfo != null && submission != null && subInfo.getSubmissionItem().getID() != submission.getID())) { try { final HttpServletRequest httpRequest = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT); // load submission info subInfo = SubmissionInfo.load(httpRequest, submission); // Set the session ID context.setExtraLogInfo("session_id=" + request.getSession().getId()); // Store the submissionInfo in the request request.setAttribute(DSPACE_SUBMISSION_INFO, subInfo); } catch (Exception e) { throw new SQLException("Error loading Submission Info: " + e.getMessage(), e); } } else if (subInfo == null && submission == null) { throw new SQLException( "Unable to load Submission Information, since WorkspaceID (ID:" + workspaceID + ") is not a valid in-process submission."); } return subInfo; }
/** Get the parameters for the logicsheet */ protected Map getLogicSheetParameters() { if (this.logicSheetParameters != null) { return this.logicSheetParameters; } HashMap map = null; if (par != null) { String[] params = par.getNames(); if (params != null) { for (int i = 0; i < params.length; i++) { String name = params[i]; if (isValidXSLTParameterName(name)) { String value = par.getParameter(name, null); if (value != null) { if (map == null) { map = new HashMap(params.length); } map.put(name, value); } } } } } if (this._useParameters) { Request request = ObjectModelHelper.getRequest(objectModel); Enumeration parameters = request.getParameterNames(); if (parameters != null) { while (parameters.hasMoreElements()) { String name = (String) parameters.nextElement(); if (isValidXSLTParameterName(name)) { String value = request.getParameter(name); if (map == null) { map = new HashMap(); } map.put(name, value); } } } } if (this._useSessionInfo) { final Request request = ObjectModelHelper.getRequest(objectModel); if (map == null) { map = new HashMap(6); } final Session session = request.getSession(false); if (session != null) { map.put("session-available", "true"); map.put("session-is-new", BooleanUtils.toStringTrueFalse(session.isNew())); map.put( "session-id-from-cookie", BooleanUtils.toStringTrueFalse(request.isRequestedSessionIdFromCookie())); map.put( "session-id-from-url", BooleanUtils.toStringTrueFalse(request.isRequestedSessionIdFromURL())); map.put( "session-valid", BooleanUtils.toStringTrueFalse(request.isRequestedSessionIdValid())); map.put("session-id", session.getId()); } else { map.put("session-available", "false"); } } if (this._useCookies) { Request request = ObjectModelHelper.getRequest(objectModel); Cookie cookies[] = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { String name = cookies[i].getName(); if (isValidXSLTParameterName(name)) { String value = cookies[i].getValue(); if (map == null) { map = new HashMap(cookies.length); } map.put(name, value); } } } } this.logicSheetParameters = map; return this.logicSheetParameters; }