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.authentication.acting;
18:
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.apache.cocoon.webapps.authentication.AuthenticationConstants;
28: import org.apache.cocoon.webapps.authentication.AuthenticationManager;
29: import org.apache.cocoon.webapps.authentication.user.RequestState;
30:
31: /**
32: * This action logs the current user out of a given handler
33: *
34: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
35: * @deprecated This block is deprecated and will be removed in future versions.
36: * @version CVS $Id: LogoutAction.java 433543 2006-08-22 06:22:54Z crossley $
37: */
38: public final class LogoutAction extends ServiceableAction implements
39: ThreadSafe {
40:
41: public Map act(Redirector redirector, SourceResolver resolver,
42: Map objectModel, String source, Parameters par)
43: throws Exception {
44: if (this .getLogger().isDebugEnabled()) {
45: this .getLogger().debug(
46: "BEGIN act resolver=" + resolver + ", objectModel="
47: + objectModel + ", source=" + source
48: + ", par=" + par);
49: }
50:
51: int mode;
52: final String modeString = par.getParameter("mode",
53: "if-not-authenticated");
54: if (modeString.equals("if-not-authenticated")) {
55: mode = AuthenticationConstants.LOGOUT_MODE_IF_NOT_AUTHENTICATED;
56: } else if (modeString.equalsIgnoreCase("if-unused")) {
57: mode = AuthenticationConstants.LOGOUT_MODE_IF_UNUSED;
58: } else if (modeString.equalsIgnoreCase("immediately")) {
59: mode = AuthenticationConstants.LOGOUT_MODE_IMMEDIATELY;
60: } else {
61: throw new ProcessingException("Unknown mode " + modeString);
62: }
63:
64: // logout
65: AuthenticationManager authManager = null;
66: try {
67: authManager = (AuthenticationManager) this .manager
68: .lookup(AuthenticationManager.ROLE);
69: RequestState state = authManager.getState();
70:
71: final String handlerName = par.getParameter("handler",
72: (state == null ? null : state.getHandlerName()));
73: if (null == handlerName) {
74: throw new ProcessingException(
75: "LogoutAction requires at least the handler parameter.");
76: }
77: authManager.logout(handlerName, mode);
78: } finally {
79: this .manager.release(authManager);
80: }
81:
82: if (this .getLogger().isDebugEnabled()) {
83: this .getLogger().debug("END act map={}");
84: }
85:
86: return EMPTY_MAP;
87: }
88:
89: }
|