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.acting.ServiceableAction;
24: import org.apache.cocoon.environment.Redirector;
25: import org.apache.cocoon.environment.SourceResolver;
26: import org.apache.cocoon.webapps.authentication.AuthenticationManager;
27: import org.apache.cocoon.webapps.authentication.user.UserHandler;
28:
29: /**
30: * This action tests if the user is logged in for a given handler.
31: *
32: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
33: * @deprecated This block is deprecated and will be removed in future versions.
34: * @version CVS $Id: LoggedInAction.java 433543 2006-08-22 06:22:54Z crossley $
35: */
36: public final class LoggedInAction extends ServiceableAction implements
37: ThreadSafe {
38:
39: public Map act(Redirector redirector, SourceResolver resolver,
40: Map objectModel, String source, Parameters par)
41: throws Exception {
42: if (this .getLogger().isDebugEnabled()) {
43: this .getLogger().debug(
44: "BEGIN act resolver=" + resolver + ", objectModel="
45: + objectModel + ", source=" + source
46: + ", par=" + par);
47: }
48:
49: Map map = null;
50: String handlerName = par.getParameter("handler", null);
51: AuthenticationManager authManager = null;
52:
53: final boolean testNotLoggedIn = par.getParameterAsBoolean(
54: "negate-result", false);
55:
56: try {
57: authManager = (AuthenticationManager) this .manager
58: .lookup(AuthenticationManager.ROLE);
59: UserHandler handler = authManager
60: .isAuthenticated(handlerName);
61: if (testNotLoggedIn) {
62: if (handler == null) {
63: map = EMPTY_MAP;
64: }
65: } else {
66: if (handler != null) {
67: map = EMPTY_MAP;
68: }
69: }
70: } finally {
71: this .manager.release(authManager);
72: }
73:
74: if (this .getLogger().isDebugEnabled()) {
75: this .getLogger().debug("END act map=" + map);
76: }
77:
78: return map;
79: }
80:
81: }
|