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


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