View Javadoc

1   /*
2    * Copyright 2004-2005 OSOCO.org (Carsten Ziegeler)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.osoco.cowarp.acting;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.apache.avalon.framework.parameters.Parameters;
22  import org.apache.avalon.framework.thread.ThreadSafe;
23  import org.apache.cocoon.ProcessingException;
24  import org.apache.cocoon.acting.ServiceableAction;
25  import org.apache.cocoon.environment.Redirector;
26  import org.apache.cocoon.environment.SourceResolver;
27  import org.osoco.cowarp.ApplicationManager;
28  
29  /***
30   * This action logs the current user out of a given application.
31   *
32   * @author <a href="mailto:cziegeler.at.osoco.org">Carsten Ziegeler</a>
33   * @version CVS $Id: LogoutAction.java,v 1.6 2005/02/21 09:28:14 cziegeler Exp $
34  */
35  public final class LogoutAction
36  extends ServiceableAction
37  implements ThreadSafe {
38  
39      /* (non-Javadoc)
40       * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
41       */
42      public Map act(final Redirector redirector,
43                     final SourceResolver resolver,
44                     final Map objectModel,
45                     final String source,
46                     final Parameters par)
47      throws Exception {
48          if (this.getLogger().isDebugEnabled() ) {
49              this.getLogger().debug("BEGIN act resolver="+resolver+
50                                     ", objectModel="+objectModel+
51                                     ", source="+source+
52                                     ", par="+par);
53          }
54  
55          final String applicationName = par.getParameter("application");
56  
57          final String modeString = par.getParameter("mode", "terminate");
58          final String mode;
59          if ( modeString.equals("terminate") ) {
60              mode = ApplicationManager.LOGOUT_MODE_TERMINATE_SESSION_IF_UNUSED;
61          } else if ( modeString.equalsIgnoreCase("keep") ) {
62              mode = ApplicationManager.LOGOUT_MODE_KEEP_SESSION;
63          } else {
64             throw new ProcessingException("Unknown mode " + modeString);
65          }
66  
67          ApplicationManager appManager = null;
68          try {
69              final Map logoutContext = new HashMap();
70              logoutContext.put(ApplicationManager.LOGOUT_CONTEXT_PARAMETERS_KEY, par);
71              logoutContext.put(ApplicationManager.LOGOUT_CONTEXT_MODE_KEY, mode);
72              
73              appManager = (ApplicationManager) this.manager.lookup(ApplicationManager.class.getName());
74              appManager.logout(applicationName, logoutContext);
75          } finally {
76              this.manager.release( appManager );
77          }
78  
79          if (this.getLogger().isDebugEnabled() ) {
80              this.getLogger().debug("END act map={}");
81          }
82  
83          return EMPTY_MAP;
84      }
85  
86  }