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.console.web.admin.audit;
009:
010: //base classes
011: import java.io.IOException;
012: import java.math.BigDecimal;
013: import java.util.ArrayList;
014: import java.util.Calendar;
015: import java.util.GregorianCalendar;
016: import java.util.StringTokenizer;
017: import javax.servlet.ServletException;
018:
019: //project specific classes
020: import org.jfolder.common.utils.misc.MiscHelper;
021: import org.jfolder.common.utils.web.ParameterSet;
022: import org.jfolder.common.web.template.ConsoleParameterContext;
023: import org.jfolder.common.web.template.CreationResultParameterContext;
024: import org.jfolder.common.web.template.SubmitActionContext;
025: import org.jfolder.common.web.template.SubmitActionParameters;
026: import org.jfolder.console.base.BaseConsoleServlet;
027: import org.jfolder.console.base.ConsolePageContext;
028: import org.jfolder.console.base.ConsolePageSession;
029: import org.jfolder.security.audit.SecurityAudit;
030: import org.jfolder.security.audit.SecurityAuditSet;
031: import org.jfolder.security.model.UserHolder;
032: import org.jfolder.services.console.ConsoleService;
033: import org.jfolder.services.console.ConsoleServiceCallerFactory;
034:
035: //other classes
036:
037: public class AuditQueryServlet extends BaseConsoleServlet {
038:
039: public AuditQueryServlet() {
040: }
041:
042: protected boolean checkAccess(ConsolePageSession inCps)
043: throws IOException, ServletException {
044:
045: boolean outValue = false;
046:
047: outValue = (inCps.isAdministrator());
048:
049: return outValue;
050: }
051:
052: public ConsolePageContext process(ConsolePageSession inCps,
053: UserHolder inUser, ParameterSet inPs,
054: SubmitActionContext inSac) throws IOException,
055: ServletException {
056:
057: //
058: ConsolePageContext outValue = null;
059:
060: if (inSac.isAction(SubmitActionParameters.OPEN)) {
061: //
062: //
063: //
064: }
065: //else if (inSac.isAction(SubmitActionParameters.DO_NOTHING)) {
066: //}
067: else if (inSac.isAction(SubmitActionParameters.UPDATE)) {
068: //
069: CreationResultParameterContext crpc = inSac
070: .getCreationResultParameterContext();
071: //
072: String firstCrpc = crpc
073: .getParameter(ConsoleParameterContext.FIRST_INPUT);
074: String secondCrpc = crpc
075: .getParameter(ConsoleParameterContext.SECOND_INPUT);
076: String thirdCrpc = crpc
077: .getParameter(ConsoleParameterContext.THIRD_INPUT);
078: //
079: MiscHelper.println("AuQuServ Crpc01 = " + firstCrpc);
080: MiscHelper.println("AuQuServ Crpc02 = " + secondCrpc);
081: MiscHelper.println("AuQuServ Crpc03 = " + thirdCrpc);
082: //
083: //
084: Boolean status = null;
085: if (firstCrpc != null) {
086: status = new Boolean(firstCrpc);
087: }
088: String annotation = secondCrpc;
089: BigDecimal auditId = new BigDecimal(thirdCrpc);
090: //
091: ConsoleService cs = ConsoleServiceCallerFactory
092: .getConsoleService();
093: //
094: cs.updateAudit(auditId, inUser.getUserIdentity(),
095: MiscHelper.currentUTC(), annotation, status);
096: //
097: SecurityAuditSet sas = inCps.getSecurityAuditSet();
098: if (status != null) {
099: for (int i = 0; i < sas.getSecurityAuditCount(); i++) {
100: SecurityAudit nextSa = sas.getSecurityAudit(i);
101: BigDecimal nextId = sas.getId(i);
102: if (nextId.compareTo(auditId) == 0) {
103: nextSa.setAuditOpened(status.booleanValue());
104: }
105: }
106: }
107: } else if (inSac.isAction(SubmitActionParameters.EXECUTE)) {
108: //
109: //
110: //
111: String firstParam = inSac
112: .getParameter(ConsoleParameterContext.FIRST_INPUT);
113: MiscHelper.println("AuQuServ Param01 = " + firstParam);
114: //
115: String secondParam = inSac
116: .getParameter(ConsoleParameterContext.SECOND_INPUT);
117: MiscHelper.println("AuQuServ Param02 = " + secondParam);
118: //
119: String thirdParam = inSac
120: .getParameter(ConsoleParameterContext.THIRD_INPUT);
121: MiscHelper.println("AuQuServ Param03 = " + thirdParam);
122: //
123: String fourthParam = inSac
124: .getParameter(ConsoleParameterContext.FOURTH_INPUT);
125: MiscHelper.println("AuQuServ Param04 = " + fourthParam);
126: //
127: String fifthParam = inSac
128: .getParameter(ConsoleParameterContext.FIFTH_INPUT);
129: MiscHelper.println("AuQuServ Param05 = " + fifthParam);
130: //
131: String sixthParam = inSac
132: .getParameter(ConsoleParameterContext.SIXTH_INPUT);
133: MiscHelper.println("AuQuServ Param06 = " + sixthParam);
134: //
135: String seventhParam = inSac
136: .getParameter(ConsoleParameterContext.SEVENTH_INPUT);
137: MiscHelper.println("AuQuServ Param07 = " + seventhParam);
138: //
139: String eighthParam = inSac
140: .getParameter(ConsoleParameterContext.EIGHTH_INPUT);
141: MiscHelper.println("AuQuServ Param08 = " + eighthParam);
142: //
143: String ninthParam = inSac
144: .getParameter(ConsoleParameterContext.NINTH_INPUT);
145: MiscHelper.println("AuQuServ Param09 = " + ninthParam);
146: //
147: String tenthParam = inSac
148: .getParameter(ConsoleParameterContext.TENTH_INPUT);
149: MiscHelper.println("AuQuServ Param10 = " + tenthParam);
150: //
151: //
152: //
153: //
154: //
155: //
156: //
157: //
158: long startDate = 0;
159: long endDate = 0;
160: Boolean status = null;
161: BigDecimal severityLevels[] = null;
162: String categoryTypes[] = null;
163: String sourceTypes[] = null;
164: BigDecimal customCodes[] = null;
165: String customCategoryTypes[] = null;
166: String customSourceTypes[] = null;
167: //
168: //
169: if (inPs.getParameter(firstParam).length() > 0) {
170: startDate = Long.parseLong(inPs
171: .getParameter(firstParam));
172: long locEndDate = (new GregorianCalendar())
173: .getTimeInMillis();
174: endDate = MiscHelper
175: .fromLocalizedTimeToUTCTime(locEndDate);
176: } else {
177: startDate = MiscHelper.fromStringToTime(inPs
178: .getParameter(secondParam));
179: startDate = MiscHelper
180: .fromLocalizedTimeToUTCTime(startDate);
181: endDate = MiscHelper.fromStringToTime(inPs
182: .getParameter(thirdParam));
183: endDate = MiscHelper
184: .fromLocalizedTimeToUTCTime(endDate);
185: }
186: //
187: if (inPs.getParameter(fourthParam).length() > 0) {
188: status = new Boolean(inPs.getParameter(fourthParam));
189: }
190: //
191: severityLevels = parseParamsToBigDecimals(inPs, fifthParam);
192: //
193: categoryTypes = parseParamsToStrings(inPs, sixthParam);
194: //
195: sourceTypes = parseParamsToStrings(inPs, seventhParam);
196: //
197: customCodes = parseParamsToBigDecimals(inPs, eighthParam);
198: //
199: customCategoryTypes = parseParamsToStrings(inPs, ninthParam);
200: //
201: customSourceTypes = parseParamsToStrings(inPs, tenthParam);
202: //
203: //
204: ConsoleService cs = ConsoleServiceCallerFactory
205: .getConsoleService();
206:
207: SecurityAuditSet sas = cs.getSecurityAudits(startDate,
208: endDate, severityLevels, categoryTypes,
209: sourceTypes, customCodes, customCategoryTypes,
210: customSourceTypes, status);
211: //
212: inCps.setSecurityAuditSet(sas);
213: } else {
214: inSac.unknownAction();
215: }
216:
217: outValue = AuditQueryContext.newInstance(inCps);
218:
219: return outValue;
220:
221: }
222:
223: //
224: //
225: //
226: private final static BigDecimal[] parseParamsToBigDecimals(
227: ParameterSet inPs, String inParamList) {
228: //
229: BigDecimal outValue[] = null;
230:
231: String initValues[] = parseParamsToStrings(inPs, inParamList);
232:
233: ArrayList values = new ArrayList();
234: for (int i = 0; i < initValues.length; i++) {
235: String nextInitValue = initValues[i];
236: if (MiscHelper.isStringNonNegativeNumber(nextInitValue)) {
237: values.add(nextInitValue);
238: }
239: }
240:
241: outValue = new BigDecimal[values.size()];
242: for (int i = 0; i < values.size(); i++) {
243: outValue[i] = new BigDecimal(values.get(i).toString());
244: }
245:
246: return outValue;
247: }
248:
249: private final static String[] parseParamsToStrings(
250: ParameterSet inPs, String inParamList) {
251: //
252: String outValue[] = null;
253:
254: ArrayList values = new ArrayList();
255: StringTokenizer st = new StringTokenizer(inParamList,
256: ConsolePageContext.HANDLE_SEPARATOR);
257: //
258: while (st.hasMoreTokens()) {
259: String nextParam = st.nextToken();
260: int icount = inPs.getParameterValuesLength(nextParam);
261: for (int i = 0; i < icount; i++) {
262: String nextParamValue = inPs.getParameter(nextParam, i);
263: if (nextParamValue.trim().length() > 0) {
264: values.add(nextParamValue);
265: }
266: }
267: }
268:
269: outValue = new String[values.size()];
270: for (int i = 0; i < values.size(); i++) {
271: outValue[i] = values.get(i).toString();
272: }
273:
274: return outValue;
275: }
276: }
|