001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.security.lifecycle;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.HashMap;
013: import javax.servlet.http.HttpServletRequest;
014:
015: //project specific classes
016: import org.jfolder.common.UnexpectedSystemException;
017: import org.jfolder.common.utils.xml.LinearXPath;
018: import org.jfolder.common.utils.xml.XMLHelper;
019: import org.jfolder.common.web.template.ConsoleParameterContext;
020: import org.jfolder.common.web.template.ConsoleTemplateContext;
021: import org.jfolder.common.web.template.ConsoleTemplateParameters;
022: import org.jfolder.common.web.template.SubmitActionContext;
023: import org.jfolder.common.web.template.SubmitActionParameters;
024: import org.jfolder.config.instance.ConfigInstance;
025: import org.jfolder.config.instance.ConfigInstanceConfig;
026: import org.jfolder.security.lifecycle.SecurityLifecycleHelper;
027: import org.jfolder.security.model.UserHolder;
028: import org.jfolder.services.config.ConfigService;
029: import org.jfolder.services.config.ConfigServiceCaller;
030: import org.jfolder.services.config.ConfigServiceCallerFactory;
031:
032: //other classes
033:
034: public class GenericConfigFailedLoginPageContext extends
035: ConsoleTemplateContext {
036:
037: //
038: private final static LinearXPath XPATH_SECURITY_CONSOLE = LinearXPath
039: .r("security").b("console");
040: private final static LinearXPath XPATH_SECURITY_CONSOLE_DEFAULT = XPATH_SECURITY_CONSOLE
041: .b("default");
042: //
043: private final static String BUTTON__LOGIN = "BUTTON__LOGIN";
044:
045: //
046: private UserHolder uh = null;
047:
048: protected GenericConfigFailedLoginPageContext(UserHolder inUh) {
049: //
050: super ();
051: //
052: this .uh = inUh;
053: }
054:
055: //protected final static LoginPageContext newInstance(UserHolder inUh) {
056: //
057: // return new LoginPageContext(inUh);
058: //}
059:
060: public String getFromPage() {
061: return ConsoleTemplateParameters.SERVLET_CONSOLE;
062: }
063:
064: public String getHandle() {
065: return NULL_HANDLE;
066: }
067:
068: public String getHandleExtension() {
069: throw new UnexpectedSystemException(
070: "This function should not be called in this class");
071: }
072:
073: protected void renderConsolePage() throws IOException {
074:
075: //get dynamic values
076: ConfigService cs = ConfigServiceCallerFactory
077: .getConfigService();
078: ConfigInstanceConfig cic = cs
079: .accessConfig(ConfigInstance.SECURITY);
080: boolean showDomain = cic.getPropertyAttribute(
081: ConfigInstance.STANDARD_CONTENT,
082: XPATH_SECURITY_CONSOLE, "show-domain", "").equals(
083: "true");
084: String username = cic.getPropertyAttribute(
085: ConfigInstance.STANDARD_CONTENT,
086: XPATH_SECURITY_CONSOLE_DEFAULT, "username", "");
087: String password = cic.getPropertyAttribute(
088: ConfigInstance.STANDARD_CONTENT,
089: XPATH_SECURITY_CONSOLE_DEFAULT, "password", "");
090: String domain = cic.getPropertyAttribute(
091: ConfigInstance.STANDARD_CONTENT,
092: XPATH_SECURITY_CONSOLE_DEFAULT, "domain", "");
093: if (!this .uh.getUserIdentity().isValid()) {
094: username = this .uh.getUserIdentity().getName();
095: password = "";
096: }
097:
098: //cm.close();
099:
100: //render content
101: HashMap attrs = new HashMap();
102:
103: setColumnWidth(110);
104:
105: startCommonPage();
106:
107: printAndIndent("<table width=\"100%\" height=\"100%\" align=\"center\">");
108: printAndIndent("<tr>");
109: printAndIndent("<td width=\"100%\" height=\"100%\" align=\"center\">");
110: //
111: attrs.clear();
112: attrs.put("border", "1");
113: attrs.put("bordercolor", "#666666");
114: startEnclosingTableAndRowAndCell(attrs);
115: //
116: startAndEndStretchTableAndRowAndCell("<hr color=\"#FFFFF\"/>");
117: //
118: attrs.clear();
119: attrs.put("style",
120: "font-size: 22; font-family: Arial; color: #000000;");
121: attrs.put("align", "center");
122: startAndEndSimpleTableAndRowAndCell(3, "Welcome to JFolder!",
123: attrs);
124: //
125: startAndEndStretchTableAndRowAndCell("<hr/>");
126: //
127: startTable(3);
128: startRow();
129: attrs.clear();
130: attrs.put("style",
131: "font-size: 16; font-family: Arial; color: #000000;");
132: startAndEndCell(1, XMLHelper.NBSP_XML + "User Name:", attrs);
133: attrs.clear();
134: attrs.put("style",
135: "font-size: 16; font-family: Arial; color: #000000;");
136: attrs.put("align", "center");
137: startAndEndCell(2, "<input type=\"text\" name=\""
138: + SecurityLifecycleHelper.USERNAME + "\" value=\""
139: + XMLHelper.fromStringToCData(username) + "\"/>", attrs);
140: endRow();
141: endTable();
142: //
143: startAndEndStretchTableAndRowAndCell("<hr color=\"#FFFFF\"/>");
144: //
145: startTable(3);
146: startRow();
147: attrs.clear();
148: attrs.put("style",
149: "font-size: 16; font-family: Arial; color: #000000;");
150: startAndEndCell(1, XMLHelper.NBSP_XML + "Password:", attrs);
151: attrs.clear();
152: attrs.put("style",
153: "font-size: 16; font-family: Arial; color: #000000;");
154: attrs.put("align", "center");
155: startAndEndCell(2, "<input type=\"password\" name=\""
156: + SecurityLifecycleHelper.PASSWORD + "\" value=\""
157: + XMLHelper.fromStringToCData(password) + "\"/>", attrs);
158: endRow();
159: endTable();
160: //
161: if (showDomain) {
162: startAndEndStretchTableAndRowAndCell("<hr color=\"#FFFFF\"/>");
163: //
164: startTable(3);
165: startRow();
166: attrs.clear();
167: attrs
168: .put("style",
169: "font-size: 16; font-family: Arial; color: #000000;");
170: startAndEndCell(1, XMLHelper.NBSP_XML + "Domain:", attrs);
171: attrs.clear();
172: attrs
173: .put("style",
174: "font-size: 16; font-family: Arial; color: #000000;");
175: attrs.put("align", "center");
176: startAndEndCell(2, "<input type=\"text\" name=\""
177: + SecurityLifecycleHelper.DOMAIN + "\" value=\""
178: + XMLHelper.fromStringToCData(domain) + "\"/>",
179: attrs);
180: endRow();
181: endTable();
182: }
183: //
184: startAndEndStretchTableAndRowAndCell("<hr/>");
185: //
186: SubmitActionContext sacLogin = SubmitActionContext
187: .newInstance(this );
188: sacLogin.addAction(ConsoleParameterContext.FIRST_INPUT,
189: singleQuotes(SubmitActionParameters.LOGIN));
190:
191: SubmitActionContext sacLicense = SubmitActionContext
192: .newInstance(this );
193: sacLicense.addAction(ConsoleParameterContext.FIRST_INPUT,
194: singleQuotes(SubmitActionParameters.GET_SUPPORT));
195: //sacLicense.setTarget(SubmitActionContext.TARGET_BLANK);
196: sacLicense
197: .setGoToPage("http://www.jfolder.com/support/support.html");
198:
199: startTable(3);
200: startRow();
201: //startAndEndCell(1, "");
202: attrs.clear();
203: attrs.put("align", "center");
204: startCell(3, attrs);
205: createButton(BUTTON__LOGIN, "Login", 150,
206: submitActionCall(sacLogin), null, null, null, null);
207: endCell();
208: //attrs.clear();
209: //attrs.put("align", "center");
210: //startCell(1, attrs);
211: //simpleAndPrint(padNbsp(1));
212: ////createButton(null, "Support", 75, sacLicense.submitActionCall(),
213: //// null, null, null, null);
214: //endCell();
215: endRow();
216: endTable();
217: //
218: startAndEndStretchTableAndRowAndCell("<hr color=\"#FFFFF\"/>");
219: //
220: endEnclosingTableAndRowAndCell();
221: //
222: revertAndPrint("</td>");
223: revertAndPrint("</tr>");
224: revertAndPrint("</table>");
225:
226: endCommonPage();
227: }
228:
229: //public String getDisplayUserName() {
230: //
231: // String returnString = null;
232: //
233: // if (isNotFirstLoginAttempt()) {
234: // returnString = getUser().getName();
235: // }
236: // else {
237: // ConfigManager cm = ConfigManagerFactory.getConfigManager();
238: // returnString = cm.getPropertyAttribute(
239: // "/project-properties[1]/security[1]/console[1]/default[1]",
240: // "username", null);
241: // cm.close();
242: // //returnString = PFUtils.getPFProperty(
243: //"pf.login.default.username");
244: // if (returnString == null) {
245: // returnString = "";
246: // }
247: // }
248: //
249: // return returnString;
250: //}
251:
252: //public String getDisplayPassword() {
253: //
254: // String returnString = null;
255: //
256: // if (isNotFirstLoginAttempt()) {
257: // returnString = "";
258: // }
259: // else {
260: // ConfigManager cm = ConfigManagerFactory.getConfigManager();
261: // returnString = cm.getPropertyAttribute(
262: // "/project-properties[1]/security[1]/console[1]/default[1]",
263: // "password", null);
264: // cm.close();
265: // //returnString = PFUtils.getPFProperty(
266: //"pf.login.default.password");
267: // if (returnString == null) {
268: // returnString = "";
269: // }
270: // }
271: //
272: // return returnString;
273: //}
274:
275: }
|