01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.webapps.session.acting;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.parameters.Parameters;
22: import org.apache.avalon.framework.service.ServiceException;
23: import org.apache.avalon.framework.thread.ThreadSafe;
24: import org.apache.cocoon.ProcessingException;
25: import org.apache.cocoon.acting.ServiceableAction;
26: import org.apache.cocoon.environment.Redirector;
27: import org.apache.cocoon.environment.SourceResolver;
28: import org.apache.cocoon.webapps.session.SessionManager;
29:
30: /**
31: * This action creates and terminates a session.
32: * The action is controlled via parameters. The action parameter defines
33: * the action (creating or terminating).
34: * The value "create" creates a new session (if not already available)
35: * The value "terminate" terminates the session. The termination can be controlled
36: * with a second parameter "mode": The default value "immediately" terminates
37: * the session, the value "if-unused" terminates the session only if no
38: * session context is available anymore. This means the user must not have
39: * any own session context and must not be authenticated anymore using
40: * the uthentication framework.
41: *
42: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
43: * @deprecated This block is deprecated and will be removed in future versions.
44: * @version CVS $Id: SessionAction.java 433543 2006-08-22 06:22:54Z crossley $
45: */
46: public final class SessionAction extends ServiceableAction implements
47: ThreadSafe {
48:
49: public Map act(Redirector redirector, SourceResolver resolver,
50: Map objectModel, String source, Parameters par)
51: throws ProcessingException {
52: SessionManager sessionManager = null;
53: try {
54: sessionManager = (SessionManager) this .manager
55: .lookup(SessionManager.ROLE);
56: final String action = par.getParameter("action", "create");
57:
58: if (action.equals("create")) {
59:
60: // create a session
61: sessionManager.createSession();
62:
63: } else if (action.equals("terminate")) {
64:
65: // terminate a session
66: final String mode = par.getParameter("mode",
67: "immediately");
68: if (mode.equals("immediately")) {
69: sessionManager.terminateSession(true);
70: } else if (mode.equals("if-unused")) {
71: sessionManager.terminateSession(false);
72: } else {
73: throw new ProcessingException("Unknown mode "
74: + mode + " for action " + action);
75: }
76:
77: } else {
78: throw new ProcessingException("Unknown action: "
79: + action);
80: }
81: } catch (ServiceException ce) {
82: throw new ProcessingException(
83: "Error during lookup of sessionManager component.",
84: ce);
85: } finally {
86: this.manager.release(sessionManager);
87: }
88:
89: return EMPTY_MAP;
90: }
91:
92: }
|