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.context;
18:
19: import org.apache.avalon.framework.component.Component;
20: import org.apache.avalon.framework.logger.AbstractLogEnabled;
21: import org.apache.avalon.framework.service.ServiceException;
22: import org.apache.avalon.framework.service.ServiceManager;
23: import org.apache.avalon.framework.service.Serviceable;
24: import org.apache.avalon.framework.thread.ThreadSafe;
25: import org.apache.cocoon.ProcessingException;
26: import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
27: import org.apache.cocoon.webapps.authentication.AuthenticationManager;
28: import org.apache.cocoon.webapps.authentication.user.RequestState;
29: import org.apache.cocoon.webapps.authentication.user.UserHandler;
30: import org.apache.cocoon.webapps.session.context.SessionContext;
31: import org.apache.cocoon.webapps.session.context.SessionContextProvider;
32:
33: /**
34: * Context provider for the authentication context
35: *
36: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
37: * @deprecated This block is deprecated and will be removed in future versions.
38: * @version CVS $Id: AuthenticationContextProvider.java 433543 2006-08-22 06:22:54Z crossley $
39: */
40: public final class AuthenticationContextProvider extends
41: AbstractLogEnabled implements SessionContextProvider,
42: ThreadSafe, Component, Serviceable {
43:
44: protected ServiceManager manager;
45:
46: /**
47: * Get the context
48: * @param name The name of the context
49: * @return The context
50: * @throws ProcessingException If the context is not available.
51: */
52: public SessionContext getSessionContext(String name)
53: throws ProcessingException {
54: AuthenticationContext context = null;
55: if (name.equals(AuthenticationConstants.SESSION_CONTEXT_NAME)) {
56:
57: AuthenticationManager authManager = null;
58: RequestState state = null;
59: try {
60: authManager = (AuthenticationManager) this .manager
61: .lookup(AuthenticationManager.ROLE);
62: state = authManager.getState();
63: } catch (ServiceException ignore) {
64: } finally {
65: this .manager.release(authManager);
66: }
67:
68: if (null != state) {
69: UserHandler handler = state.getHandler();
70: if (handler != null) {
71: context = handler.getContext();
72: }
73: }
74: }
75: return context;
76: }
77:
78: /**
79: * Does the context exist?
80: */
81: public boolean existsSessionContext(String name)
82: throws ProcessingException {
83: return (this .getSessionContext(name) != null);
84: }
85:
86: /* (non-Javadoc)
87: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
88: */
89: public void service(ServiceManager manager) throws ServiceException {
90: this.manager = manager;
91: }
92:
93: }
|