Source Code Cross Referenced for UserAttributes.java in  » Portal » Open-Portal » com » sun » portal » netlet » util » 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 » Open Portal » com.sun.portal.netlet.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.netlet.util;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collections;
005:        import java.util.HashMap;
006:        import java.util.HashSet;
007:        import java.util.Iterator;
008:        import java.util.List;
009:        import java.util.Map;
010:        import java.util.Set;
011:
012:        import com.iplanet.am.sdk.AMException;
013:        import com.iplanet.am.sdk.AMStoreConnection;
014:        import com.iplanet.am.sdk.AMUser;
015:        import com.iplanet.sso.SSOException;
016:        import com.iplanet.sso.SSOToken;
017:        import com.sun.identity.policy.PolicyEvaluator;
018:        import com.sun.identity.policy.PolicyException;
019:
020:        /**
021:         * To be used only by Netlet.
022:         * 
023:         * @modified bs126381
024:         */
025:        public class UserAttributes implements  NetletConstants {
026:
027:            private SSOToken ssoToken = null;
028:
029:            private AMUser user = null;
030:
031:            private Map userAttributes;
032:
033:            private boolean applyDefault;
034:
035:            public UserAttributes(SSOToken token) {
036:                try {
037:                    ssoToken = token;
038:                    AMStoreConnection connection = new AMStoreConnection(
039:                            ssoToken);
040:                    user = connection.getUser(token.getPrincipal().getName());
041:                    userAttributes = user
042:                            .getServiceAttributes(NetletConstants.NETLET_SERVICE_NAME);
043:                    applyDefault = false;
044:                } catch (SSOException ssoe) {
045:                    applyDefault = true;
046:                } catch (AMException dpe) {
047:                    applyDefault = true;
048:                }
049:            }
050:
051:            public boolean isPolicyAssigned() {
052:                return true;
053:                /*boolean policyAssigned = false;
054:                try {
055:                   PolicyEvaluator policyEval = new PolicyEvaluator(
056:                           NetletConstants.NETLET_SERVICE_NAME);
057:                   policyAssigned = policyEval
058:                           .isAllowed(ssoToken, "", NetletConstants.NETLET_POLICY,
059:                                      Collections.EMPTY_MAP);
060:                } catch (PolicyException pe) {
061:                   policyAssigned = false;
062:                } catch (SSOException ssoe) {
063:                   policyAssigned = false;
064:                }
065:                return policyAssigned;*/
066:            }
067:
068:            public boolean isServiceAssigned() {
069:                boolean serviceAssigned = false;
070:                try {
071:                    Set vals = null;
072:                    vals = user.getAssignedServices();
073:                    if ((vals == null) || (vals.isEmpty())) {
074:                        serviceAssigned = false;
075:                    }
076:                    Iterator iter = vals.iterator();
077:                    while (iter.hasNext()) {
078:                        String serviceName = (String) iter.next();
079:                        if (NetletConstants.NETLET_SERVICE_NAME
080:                                .equalsIgnoreCase(serviceName)) {
081:                            serviceAssigned = true;
082:                            break;
083:                        }
084:                    }
085:                } catch (Exception ex) {
086:                    serviceAssigned = false;
087:                }
088:                return serviceAssigned;
089:            }
090:
091:            public boolean isAllowed() {
092:                return (isServiceAssigned() && isPolicyAssigned());
093:            }
094:
095:            public String getString(String name, String defaultValue) {
096:                return applyDefault ? defaultValue : AttributeExtractor
097:                        .getString(userAttributes, name, defaultValue);
098:            }
099:
100:            public String getString(String name) {
101:                return getString(name, "");
102:            }
103:
104:            public void setString(String name, String value) {
105:                HashSet hs = new HashSet(1);
106:                hs.add((Object) value);
107:                Map changedMap = new HashMap();
108:                changedMap.put(name, hs);
109:                try {
110:                    user.setAttributes(changedMap);
111:                    user.store();
112:                } catch (SSOException ssoe) {
113:                } catch (AMException ame) {
114:                }
115:            }
116:
117:            public int getInt(String name, int defaultValue) {
118:                return applyDefault ? defaultValue : AttributeExtractor.getInt(
119:                        userAttributes, name, defaultValue);
120:            }
121:
122:            public int getInt(String name) {
123:                return getInt(name, -1);
124:            }
125:
126:            public void setInt(String name, int value) {
127:                String val = "" + value;
128:                HashSet hs = new HashSet(1);
129:                hs.add((Object) val);
130:                Map changedMap = new HashMap();
131:                changedMap.put(name, hs);
132:                try {
133:                    user.setAttributes(changedMap);
134:                    user.store();
135:                } catch (SSOException ssoe) {
136:                } catch (AMException ame) {
137:                }
138:            }
139:
140:            public boolean getBoolean(String name, boolean defaultValue) {
141:                return applyDefault ? defaultValue : AttributeExtractor
142:                        .getBoolean(userAttributes, name, defaultValue);
143:            }
144:
145:            public boolean getBoolean(String name) {
146:                return getBoolean(name, false);
147:            }
148:
149:            public void setBoolean(String name, boolean value) {
150:                String val = "" + value;
151:                HashSet hs = new HashSet(1);
152:                hs.add((Object) val);
153:                Map changedMap = new HashMap();
154:                changedMap.put(name, hs);
155:                try {
156:                    user.setAttributes(changedMap);
157:                    user.store();
158:                } catch (SSOException ssoe) {
159:                } catch (AMException ame) {
160:                }
161:            }
162:
163:            public List getStringList(String name) {
164:                return applyDefault ? new ArrayList() : AttributeExtractor
165:                        .getStringList(userAttributes, name);
166:            }
167:
168:            public void setStringList(String name, List value) {
169:                HashSet hs = new HashSet(value);
170:                Map changedMap = new HashMap();
171:                changedMap.put(name, hs);
172:                try {
173:                    user.setAttributes(changedMap);
174:                    user.store();
175:                } catch (SSOException ssoe) {
176:                } catch (AMException ame) {
177:                }
178:            }
179:
180:            public String getUserAttribute(String name, String defaultValue) {
181:                try {
182:                    Set set = user.getAttribute(name);
183:                    if (set != null) {
184:                        Iterator it = set.iterator();
185:                        return (it.hasNext()) ? (String) it.next()
186:                                : defaultValue;
187:                    }
188:                } catch (SSOException ssoe) {
189:                    return defaultValue;
190:                } catch (AMException ame) {
191:                    return defaultValue;
192:                }
193:                return defaultValue;
194:            }
195:
196:            public String getUserAttribute(String name) {
197:                return getUserAttribute(name, "");
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.