KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > profile > impl > AuthenticationFWUserInfoProvider


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.profile.impl;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.service.ServiceException;
23 import org.apache.avalon.framework.service.ServiceManager;
24 import org.apache.avalon.framework.service.Serviceable;
25 import org.apache.cocoon.ProcessingException;
26 import org.apache.cocoon.webapps.authentication.AuthenticationManager;
27 import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
28 import org.apache.cocoon.webapps.authentication.user.RequestState;
29 import org.apache.cocoon.webapps.authentication.user.UserHandler;
30
31 /**
32  * Get the information about the current user.
33  * This implementation uses the authentication-fw block
34  *
35  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
36  * @version CVS $Id: MapProfileLS.java 30941 2004-07-29 19:56:58Z vgritsenko $
37  */

38 public class AuthenticationFWUserInfoProvider
39 implements UserInfoProvider, Serviceable {
40     
41     protected ServiceManager manager;
42     
43     
44     /* (non-Javadoc)
45      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
46      */

47     public void service(ServiceManager manager) throws ServiceException {
48         this.manager = manager;
49     }
50
51     /* (non-Javadoc)
52      * @see org.apache.cocoon.portal.profile.impl.UserInfoProvider#getUserInfo(java.lang.String, java.lang.String)
53      */

54     public UserInfo getUserInfo(String JavaDoc portalName, String JavaDoc layoutKey)
55     throws Exception JavaDoc {
56         AuthenticationManager authManager = null;
57         try {
58             authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE);
59             final RequestState state = authManager.getState();
60             final UserHandler handler = state.getHandler();
61
62             final UserInfo info = new AFWUserInfo(portalName, layoutKey, handler);
63
64
65             info.setUserName(handler.getUserId());
66             try {
67                 info.setGroup((String JavaDoc)handler.getContext().getContextInfo().get("group"));
68             } catch (ProcessingException pe) {
69                 // ignore this
70
}
71
72             final ApplicationConfiguration ac = state.getApplicationConfiguration();
73             if ( ac == null ) {
74                 throw new ProcessingException("Configuration for portal not found in application configuration.");
75             }
76             final Configuration appConf = ac.getConfiguration("portal");
77             if ( appConf == null ) {
78                 throw new ProcessingException("Configuration for portal not found in application configuration.");
79             }
80             final Configuration config = appConf.getChild("profiles");
81             final Configuration[] children = config.getChildren();
82             final Map JavaDoc configs = new HashMap JavaDoc();
83             if ( children != null ) {
84                 for(int i=0; i < children.length; i++) {
85                     configs.put(children[i].getName(), children[i].getAttribute("uri"));
86                 }
87             }
88             info.setConfigurations(configs);
89             return info;
90         } finally {
91             this.manager.release( authManager );
92         }
93     }
94     
95     public static final class AFWUserInfo extends UserInfo {
96         
97         protected final UserHandler handler;
98         /**
99          * @param portalName
100          * @param layoutKey
101          */

102         public AFWUserInfo(String JavaDoc portalName, String JavaDoc layoutKey, UserHandler handler) {
103             super(portalName, layoutKey);
104             this.handler = handler;
105         }
106     
107         /* (non-Javadoc)
108          * @see org.apache.cocoon.portal.profile.PortalUser#isUserInRole(java.lang.String)
109          */

110         public boolean isUserInRole(String JavaDoc role) {
111             return this.isUserInRole(role);
112         }
113     }
114 }
115
Popular Tags