001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jul 23, 2005
014: * @author James Dixon
015: *
016: */
017:
018: package org.pentaho.core.session;
019:
020: import java.util.Locale;
021:
022: import org.pentaho.core.audit.AuditHelper;
023: import org.pentaho.core.audit.MessageTypes;
024: import org.pentaho.core.system.PentahoBase;
025: import org.pentaho.messages.Messages;
026: import org.pentaho.util.logging.ILogger;
027:
028: public abstract class BaseSession extends PentahoBase implements
029: IPentahoSession {
030:
031: /**
032: * key into the server provided session's attributes to retrieve the IPentahoSession
033: */
034: public static final String PENTAHO_SESSION_KEY = "pentaho-session"; //$NON-NLS-1$
035:
036: private String name;
037:
038: private String id;
039:
040: private String processId;
041:
042: private String actionName;
043:
044: private Locale locale;
045:
046: private boolean authenticated;
047:
048: private volatile boolean backgroundExecutionAlert;
049:
050: public BaseSession(String name, String id, Locale locale) {
051: this .name = name;
052: this .id = id;
053: this .locale = locale;
054: actionName = ""; //$NON-NLS-1$
055: setLogId(Messages
056: .getString(
057: "BaseSession.CODE_LOG_ID", id, ILogger.SESSION_LOG, name)); //$NON-NLS-1$
058: AuditHelper.audit(id, name, actionName, getObjectName(),
059: "", MessageTypes.SESSION_START, "", "", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
060: authenticated = false;
061: }
062:
063: public boolean isAuthenticated() {
064: return authenticated;
065: }
066:
067: public void setAuthenticated(String name) {
068: if (name != null) {
069: authenticated = true;
070: this .name = name;
071: }
072: }
073:
074: public void setNotAuthenticated() {
075: name = null;
076: authenticated = false;
077: }
078:
079: public Locale getLocale() {
080: return locale;
081: }
082:
083: public void destroy() {
084: AuditHelper.audit(id, name, actionName, getObjectName(),
085: "", MessageTypes.SESSION_END, "", "", null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
086: }
087:
088: public void setActionName(String actionName) {
089: this .actionName = actionName;
090: }
091:
092: public void setProcessId(String processId) {
093: this .processId = processId;
094: }
095:
096: /*
097: * (non-Javadoc)
098: *
099: * @see org.pentaho.core.session.IPentahoSession#getName()
100: */
101: public String getName() {
102: return name;
103: }
104:
105: /*
106: * (non-Javadoc)
107: *
108: * @see org.pentaho.audit.IAuditable#getId()
109: */
110: public String getId() {
111: return id;
112: }
113:
114: /*
115: * (non-Javadoc)
116: *
117: * @see org.pentaho.audit.IAuditable#getObjectName()
118: */
119: public String getObjectName() {
120: return this .getClass().getName();
121: }
122:
123: /*
124: * (non-Javadoc)
125: *
126: * @see org.pentaho.audit.IAuditable#getProcessId()
127: */
128: public String getProcessId() {
129: return processId;
130: }
131:
132: /*
133: * (non-Javadoc)
134: *
135: * @see org.pentaho.audit.IAuditable#getActionName()
136: */
137: public String getActionName() {
138: return actionName;
139: }
140:
141: public synchronized void setBackgroundExecutionAlert() {
142: this .backgroundExecutionAlert = true;
143: }
144:
145: public synchronized boolean getBackgroundExecutionAlert() {
146: return this .backgroundExecutionAlert;
147: }
148:
149: public synchronized void resetBackgroundExecutionAlert() {
150: this .backgroundExecutionAlert = false;
151: }
152:
153: }
|