Source Code Cross Referenced for UserInfoAttributesServiceImpl.java in  » Portal » Pluto » org » apache » pluto » driver » services » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Pluto » org.apache.pluto.driver.services.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.pluto.driver.services.impl;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.util.HashMap;
022:        import java.util.Map;
023:        import java.util.Properties;
024:
025:        import javax.portlet.PortletRequest;
026:
027:        import org.apache.commons.logging.Log;
028:        import org.apache.commons.logging.LogFactory;
029:        import org.apache.pluto.PortletContainerException;
030:        import org.apache.pluto.PortletWindow;
031:        import org.apache.pluto.spi.optional.UserInfoAttributesService;
032:        import org.apache.pluto.spi.optional.P3PAttributes;
033:
034:        /**
035:         * FIXME: Only include attributes that are defined in portlet.xml
036:         *
037:         * This is a default implementation of that gets user information attributes
038:         * from a properties file where the user information attribute name (as defined
039:         * in PLT.D of the JSR-168 spec) is prefixed by the user name (e.g. craig.user.name.given=Craig).
040:         *
041:         */
042:        public class UserInfoAttributesServiceImpl implements 
043:                UserInfoAttributesService {
044:
045:            private static UserInfoAttributesServiceImpl instance = new UserInfoAttributesServiceImpl();
046:
047:            private static final String USER_INFO_ATTR_FILE = "/user-info-attributes.properties";
048:            /** Logger. */
049:            private static final Log LOG = LogFactory
050:                    .getLog(UserInfoAttributesServiceImpl.class);
051:            private static Properties props = new Properties();
052:            private static Map cache = new HashMap();
053:
054:            private UserInfoAttributesServiceImpl() {
055:
056:            }
057:
058:            public static UserInfoAttributesServiceImpl getInstance()
059:                    throws IOException {
060:                loadProperties();
061:                return instance;
062:            }
063:
064:            public static UserInfoAttributesServiceImpl getInstance(
065:                    Properties inprops) throws IOException {
066:                props = inprops;
067:                return instance;
068:            }
069:
070:            /**
071:             * Implementation of PLT.17.2 used to access user information attributes.
072:             *
073:             * @see UserInfoAttributesService#getUserInfo(javax.portlet.PortletRequest)
074:             * @return As per the spec, return null if the user is not authenticated or an empty Map if there are
075:             * no attributes in the properties file or a Map containing only those attributes found in the attribute
076:             * data store (properties file).
077:             */
078:            public Map getUserInfo(PortletRequest request)
079:                    throws PortletContainerException {
080:                Map map = null;
081:                String user = request.getRemoteUser();
082:                if (user == null) {
083:                    return null;
084:                }
085:                map = (Map) cache.get(user);
086:                if (map == null) {
087:                    map = new HashMap();
088:                    int len = P3PAttributes.ATTRIBUTE_ARRAY.length;
089:                    StringBuffer prefix = new StringBuffer();
090:                    prefix.append(user);
091:                    prefix.append('.');
092:                    StringBuffer name = null;
093:                    for (int i = 0; i < len; i++) {
094:                        name = new StringBuffer();
095:                        name.append(prefix);
096:                        String attr = P3PAttributes.ATTRIBUTE_ARRAY[i];
097:                        name.append(attr);
098:                        String prop = props.getProperty(name.toString());
099:                        //spec says that Map only attributes that have data
100:                        if (prop != null) {
101:                            //TODO: convert user.bdate to milliseconds since January 1, 1970, 00:00:00 GMT.
102:                            map.put(attr, prop);
103:                        }
104:                    }
105:                    cache.put(user, map);
106:                }
107:                return map;
108:            }
109:
110:            public Map getUserInfo(PortletRequest request, PortletWindow window)
111:                    throws PortletContainerException {
112:                return getUserInfo(request);
113:            }
114:
115:            private static void loadProperties() throws IOException {
116:                //get the properties from prop file
117:                if (props.isEmpty()) {
118:                    InputStream stream = UserInfoAttributesServiceImpl.class
119:                            .getResourceAsStream(USER_INFO_ATTR_FILE);
120:                    if (stream == null) {
121:                        String msg = "The properties file '"
122:                                + USER_INFO_ATTR_FILE
123:                                + "' cannot be found."
124:                                + " Please make sure this file exists and is in the classpath (i.e. WEB-INF/classes).";
125:                        LOG.error(msg);
126:                        throw new IOException(msg);
127:                    }
128:                    props.load(stream);
129:                }
130:            }
131:
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.