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.auth.acting;
18:
19: import java.util.HashMap;
20: import java.util.Iterator;
21: import java.util.Map;
22:
23: import org.apache.avalon.framework.parameters.Parameters;
24: import org.apache.cocoon.environment.Redirector;
25: import org.apache.cocoon.environment.SourceResolver;
26: import org.apache.cocoon.auth.ApplicationUtil;
27: import org.apache.cocoon.auth.User;
28:
29: /**
30: * This action tests if the user is logged in for a given application.
31: *
32: * @version $Id: LoggedInAction.java 433543 2006-08-22 06:22:54Z crossley $
33: */
34: public final class LoggedInAction extends AbstractAuthAction {
35:
36: /**
37: * @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)
38: */
39: public Map act(final Redirector redirector,
40: final SourceResolver resolver, final Map objectModel,
41: final String source, final Parameters par) 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: final String applicationName = par.getParameter("application");
51: final String roleName = par.getParameter("role", null);
52:
53: final boolean negate = par.getParameterAsBoolean(
54: "negate-result", false);
55: if (this .applicationManager.isLoggedIn(applicationName)) {
56: final User user = ApplicationUtil.getUser(objectModel);
57: if (roleName == null || user.isUserInRole(roleName)) {
58: if (!negate) {
59: map = new HashMap();
60: map.put("ID", user.getId());
61: Iterator i = user.getAttributeNames();
62: while (i.hasNext()) {
63: final String key = (String) i.next();
64: map.put(key, user.getAttribute(key));
65: }
66: }
67: }
68: } else {
69: if (negate) {
70: map = EMPTY_MAP;
71: }
72: }
73:
74: if (this .getLogger().isDebugEnabled()) {
75: this .getLogger().debug("END act map={}");
76: }
77:
78: return map;
79: }
80:
81: }
|