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.portal;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.context.Context;
22: import org.apache.avalon.framework.context.ContextException;
23: import org.apache.avalon.framework.context.Contextualizable;
24: import org.apache.cocoon.components.ContextHelper;
25: import org.apache.cocoon.portal.profile.impl.UserInfo;
26: import org.apache.cocoon.portal.profile.impl.UserInfoProvider;
27: import org.apache.cocoon.auth.ApplicationUtil;
28: import org.apache.cocoon.auth.User;
29:
30: /**
31: * Get the information about the current user.
32: * This implementation uses CAuth.
33: * Note: This class belongs to cauth but has to be defined in the portal block for now.
34: * This will be cleaned up with Cocoon 2.2.
35: * @version $Id: UserInfoProviderImpl.java 433543 2006-08-22 06:22:54Z crossley $
36: */
37: public class UserInfoProviderImpl implements UserInfoProvider,
38: Contextualizable {
39:
40: /** The component context. */
41: protected Context context;
42:
43: /**
44: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
45: */
46: public void contextualize(final Context aContext)
47: throws ContextException {
48: this .context = aContext;
49: }
50:
51: /**
52: * @see org.apache.cocoon.portal.profile.impl.UserInfoProvider#getUserInfo(java.lang.String, java.lang.String)
53: */
54: public UserInfo getUserInfo(final String portalName,
55: final String layoutKey) throws Exception {
56: final Map objectModel = ContextHelper
57: .getObjectModel(this .context);
58: final User user = ApplicationUtil.getUser(objectModel);
59:
60: final UserInfo info = new PortalUserInfo(portalName, layoutKey,
61: user);
62:
63: info.setUserName(user.getId());
64: info.setGroup((String) user.getAttribute("group"));
65: final PortalApplication app = (PortalApplication) ApplicationUtil
66: .getApplication(objectModel);
67: info.setConfigurations(app.getPortalConfiguration());
68:
69: return info;
70: }
71:
72: /**
73: * The user info for the portal engine.
74: */
75: public static final class PortalUserInfo extends UserInfo {
76:
77: /** The CAuth user object. */
78: protected final User user;
79:
80: /**
81: * Create a new user info object.
82: * @param portalName The current portal name.
83: * @param layoutKey The layout information.
84: * @param aUser The CAuth user object.
85: */
86: public PortalUserInfo(final String portalName,
87: final String layoutKey, final User aUser) {
88: super (portalName, layoutKey);
89: this .user = aUser;
90: }
91:
92: /**
93: * @see org.apache.cocoon.portal.profile.PortalUser#isUserInRole(java.lang.String)
94: */
95: public boolean isUserInRole(final String role) {
96: return user.isUserInRole(role);
97: }
98: }
99: }
|