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.AuthenticationManager;
28: import org.apache.cocoon.webapps.authentication.user.UserHandler;
29: import org.apache.excalibur.source.SourceParameters;
30:
31: /**
32: * This action logs the current user into a given handler. If the
33: * authentication is successful, a map is returned with the authentication
34: * information and a session is created (if it not already exists).
35: * If the authentication is not successful, the error information is stored
36: * into the temporary context.
37: *
38: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
39: * @deprecated This block is deprecated and will be removed in future versions.
40: * @version CVS $Id: LoginAction.java 433543 2006-08-22 06:22:54Z crossley $
41: */
42: public final class LoginAction extends ServiceableAction implements
43: ThreadSafe {
44:
45: public Map act(Redirector redirector, SourceResolver resolver,
46: Map objectModel, String source, Parameters par)
47: throws Exception {
48: if (getLogger().isDebugEnabled()) {
49: getLogger().debug(
50: "BEGIN act resolver=" + resolver + ", objectModel="
51: + objectModel + ", source=" + source
52: + ", par=" + par);
53: }
54:
55: final String handlerName = par.getParameter("handler", null);
56: if (handlerName == null) {
57: throw new ProcessingException(
58: "LoginAction requires at least the handler parameter.");
59: }
60:
61: // Build authentication parameters
62: SourceParameters authenticationParameters = new SourceParameters();
63: String[] keys = par.getNames();
64: if (keys != null) {
65: for (int i = 0; i < keys.length; i++) {
66: final String key = keys[i];
67: if (key.startsWith("parameter_")) {
68: authenticationParameters.setParameter(key
69: .substring("parameter_".length()), par
70: .getParameter(key));
71: }
72: }
73: }
74:
75: Map map = null;
76:
77: // authenticate
78: AuthenticationManager authManager = null;
79: try {
80: authManager = (AuthenticationManager) this .manager
81: .lookup(AuthenticationManager.ROLE);
82: UserHandler handler = authManager.login(handlerName, par
83: .getParameter("application", null),
84: authenticationParameters);
85: if (handler != null) {
86: // success
87: map = handler.getContext().getContextInfo();
88: }
89: } finally {
90: this .manager.release(authManager);
91: }
92:
93: if (getLogger().isDebugEnabled()) {
94: getLogger().debug("END act map=" + map);
95: }
96:
97: return map;
98: }
99: }
|