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.ApplicationManager;
27: import org.apache.cocoon.auth.User;
28:
29: /**
30: * This action logs the current user into a given application. If the
31: * authentication is successful, a map is returned with the authentication
32: * information and a session is created (if it not already exists).
33: *
34: * @version $Id: LoginAction.java 433543 2006-08-22 06:22:54Z crossley $
35: */
36: public final class LoginAction extends AbstractAuthAction {
37:
38: /**
39: * @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)
40: */
41: public Map act(final Redirector redirector,
42: final SourceResolver resolver, final Map objectModel,
43: final String source, final Parameters par) 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: final String applicationName = par.getParameter("application");
52:
53: Map map = null;
54:
55: final Map loginContext = new HashMap();
56: loginContext.put(
57: ApplicationManager.LOGIN_CONTEXT_PARAMETERS_KEY, par);
58: final User user = this .applicationManager.login(
59: applicationName, loginContext);
60:
61: if (user != null) {
62: // success
63: map = new HashMap();
64: map.put("ID", user.getId());
65: Iterator i = user.getAttributeNames();
66: while (i.hasNext()) {
67: final String key = (String) i.next();
68: map.put(key, user.getAttribute(key));
69: }
70: }
71:
72: if (this .getLogger().isDebugEnabled()) {
73: this .getLogger().debug("END act map=" + map);
74: }
75:
76: return map;
77: }
78:
79: }
|