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


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject
004:         * to license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users
006:         * Subject to Standard License Terms and
007:         * Conditions.
008:         *
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010:         * are trademarks or registered trademarks of Sun Microsystems,
011:         * Inc. in the United States and other countries.
012:         */
013:
014:        package com.sun.portal.wsrp.wssso.common;
015:
016:        import java.net.MalformedURLException;
017:        import java.net.URL;
018:        import java.util.Iterator;
019:        import java.util.Set;
020:        import java.util.logging.Level;
021:        import java.util.logging.Logger;
022:        import java.util.List;
023:        import java.net.URLEncoder;
024:        import java.util.Properties;
025:        import java.io.UnsupportedEncodingException;
026:        import java.io.FileNotFoundException;
027:        import java.io.IOException;
028:
029:        import com.iplanet.am.sdk.AMException;
030:        import com.iplanet.am.sdk.AMStoreConnection;
031:        import com.iplanet.am.sdk.AMUser;
032:        import com.iplanet.sso.SSOException;
033:        import com.iplanet.sso.SSOToken;
034:
035:        import com.sun.ssoadapter.SSOAdapter;
036:        import com.sun.ssoadapter.SSOAdapterFactory;
037:        import com.sun.ssoadapter.SSOAdapterSession;
038:        import com.sun.ssoadapter.SSOAdapterException;
039:
040:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
041:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
042:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
043:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManagerFactory;
044:
045:        import com.sun.portal.log.common.PortalLogger;
046:        import com.sun.portal.util.ResourceLoader;
047:        import com.sun.portal.util.SSOUtil;
048:
049:        public class WSSSOMigrator implements  WSSSOConstants {
050:
051:            private String orgDN = null;
052:            private SSOAdapterFactory adapterFactory = null;
053:            private SSOAdapterSession session = null;
054:
055:            private static Logger debugLogger = PortalLogger
056:                    .getLogger(WSSSOMigrator.class);
057:            private static String portalId = System
058:                    .getProperty("com.sun.portal.portal.id");
059:            private static Properties locales = getWSSSOProperties();
060:
061:            public WSSSOMigrator(SSOToken userToken) {
062:                try {
063:                    orgDN = getUserOrganization(userToken);
064:                } catch (SSOException ssoe) {
065:                    debugLogger.log(Level.SEVERE, "", ssoe);
066:                } catch (AMException ame) {
067:                    debugLogger.log(Level.SEVERE, "", ame);
068:                }
069:                adapterFactory = SSOAdapterFactory.getInstance();
070:                session = new SSOAdapterSession(userToken);
071:            }
072:
073:            public String getIdentityPropagationType(SSOAdapter adapter,
074:                    String markupURL) {
075:
076:                if (orgDN == null) {
077:                    return null;
078:                }
079:                try {
080:                    ProducerEntityManager pem = ProducerEntityManagerFactory
081:                            .getInstance().getProducerEntityManager(
082:                                    getAdminSSOToken(), portalId, orgDN);
083:                    URL inputURL = new URL(markupURL);
084:                    URL comparisonURL = null;
085:                    Set producerEntityIds = pem.getProducerEntityIds();
086:                    if ((producerEntityIds != null)
087:                            && (producerEntityIds.size() > 0)) {
088:                        for (Iterator i = producerEntityIds.iterator(); i
089:                                .hasNext();) {
090:                            String producerEntityId = (String) i.next();
091:                            ProducerEntity pe = pem
092:                                    .getProducerEntity(producerEntityId);
093:                            comparisonURL = new URL(pe.getMarkupEndpoint()
094:                                    .toString());
095:                            if (inputURL.equals(comparisonURL)) {
096:                                migrateUserConfiguration(adapter, pem, pe);
097:                                return pe.getIdentityPropagationType();
098:                            }
099:                        }
100:                    }
101:                } catch (WSRPConsumerException we) {
102:                    debugLogger.log(Level.SEVERE, "", we);
103:                } catch (MalformedURLException me) {
104:                    debugLogger.log(Level.SEVERE, "", me);
105:                }
106:                return null;
107:            }
108:
109:            private void migrateUserConfiguration(SSOAdapter adapter,
110:                    ProducerEntityManager pem, ProducerEntity pe) {
111:                URL wsURL = pe.getURL();
112:                List endPoints = null;
113:
114:                try {
115:                    endPoints = pem.getEndpoints(wsURL);
116:                } catch (WSRPConsumerException wce) {
117:                    //Abort migration Producer may be down or not reacheable
118:                    debugLogger.log(Level.SEVERE, "", wce);
119:                    return;
120:                }
121:
122:                String idType = pe.getIdentityPropagationType();
123:                String endPointURLs = processEndPoints(endPoints);
124:                //getUsername and Password from Old SSOAdapter
125:                String userName = null;
126:                String password = null;
127:
128:                Properties props = adapter.getProperties();
129:                Object temp = props.get(WEBSERVICE_USERNAME);
130:                if (temp != null) {
131:                    userName = temp.toString();
132:                }
133:                temp = props.get(WEBSERVICE_PASSWORD);
134:                if (temp != null) {
135:                    password = temp.toString();
136:                }
137:
138:                //create a new SSOAdapter
139:                SSOAdapter migratedAdapter = getDefaultSSOAdapter();
140:                if (migratedAdapter == null) {
141:                    return;
142:                }
143:                String newName = getNewSSOAdapterName(wsURL);
144:                Properties migratedProps = migratedAdapter.getProperties();
145:                migratedProps.put(WEBSERVICE_WSDL_URL, wsURL.toString());
146:                migratedProps.put(WEBSERVICE_IDENTITY_TYPE, idType);
147:                migratedProps.put(WEBSERVICE_NAME, DEFAULT_WSRP_NAME);
148:                migratedProps.put(WEBSERVICE_ENDPOINT_URLS, endPointURLs);
149:                migratedProps.put(WEBSERVICE_DESC, DEFAULT_WSRP_DESC);
150:                if (userName != null) {
151:                    migratedProps.put(WEBSERVICE_USERNAME, userName);
152:                }
153:                if (password != null && password.trim().length() != 0) {
154:                    migratedProps.put(WEBSERVICE_PASSWORD, password);
155:                }
156:                migratedProps.put(CHANNEL_NAME, newName);
157:                try {
158:                    SSOAdapter newssoAdapter = (SSOAdapter) adapterFactory
159:                            .setSSOAdapter(migratedAdapter, migratedProps,
160:                                    session);
161:                } catch (SSOAdapterException sae) {
162:                    debugLogger.log(Level.SEVERE, "", sae);
163:                    //Abort deletion as new SSOAdapter creation failed
164:                    return;
165:                }
166:                //delete the Old SSOAdapter
167:                deleteSSOAdapter(adapter);
168:            }
169:
170:            private String processEndPoints(List endPoints) {
171:                Iterator it = endPoints.iterator();
172:                StringBuffer buf = new StringBuffer();
173:                while (it.hasNext()) {
174:                    buf.append(it.next().toString()).append("^");
175:                }
176:                return buf.toString();
177:            }
178:
179:            private String getNewSSOAdapterName(URL wsURL) {
180:                int port = wsURL.getPort();
181:                if (port == -1) {
182:                    port = wsURL.getDefaultPort();
183:                }
184:                String newURL = wsURL.getProtocol() + "://" + wsURL.getHost()
185:                        + ":" + port + wsURL.getPath();
186:                try {
187:                    String encoded = URLEncoder.encode(newURL, "UTF-8");
188:                    return portalId + SEPARATOR + encoded;
189:                } catch (UnsupportedEncodingException e) {
190:                    debugLogger.log(Level.SEVERE, "", e);
191:                }
192:
193:                return null;
194:            }
195:
196:            private void deleteSSOAdapter(SSOAdapter adapter) {
197:                try {
198:                    adapterFactory.removeConfiguration(adapter.getName(),
199:                            session);
200:                } catch (SSOAdapterException sae) {
201:                    debugLogger.log(Level.SEVERE, "", sae);
202:                }
203:            }
204:
205:            private SSOAdapter getDefaultSSOAdapter() {
206:                SSOAdapter adapter = null;
207:                try {
208:                    adapter = adapterFactory
209:                            .getSSOAdapter(CONFIG_NAME, session);
210:                    return adapter;
211:                } catch (SSOAdapterException e) {
212:                    debugLogger.log(Level.SEVERE, "", e);
213:                }
214:                return null;
215:            }
216:
217:            private SSOToken getAdminSSOToken() {
218:                return SSOUtil.getAdminSSOToken();
219:            }
220:
221:            private String getUserOrganization(SSOToken token)
222:                    throws SSOException, AMException {
223:                String userDN = token.getPrincipal().getName();
224:                AMStoreConnection amsc = new AMStoreConnection(
225:                        getAdminSSOToken());
226:                AMUser user = amsc.getUser(userDN);
227:                return user.getOrganizationDN();
228:            }
229:
230:            private String getWSRPConsumerName() {
231:                if (locales == null || locales.size() == 0) {
232:                    return DEFAULT_WSRP_NAME;
233:                }
234:                Object temp = locales.getProperty(WSSSO_NAME_PROPERTY);
235:                if (temp != null) {
236:                    return temp.toString();
237:                }
238:                return null;
239:
240:            }
241:
242:            private String getWSRPConsumerDesc() {
243:                if (locales == null || locales.size() == 0) {
244:                    return DEFAULT_WSRP_DESC;
245:                }
246:                Object temp = locales.getProperty(WSSSO_DESC_PROPERTY);
247:                if (temp != null) {
248:                    return temp.toString();
249:                }
250:                return null;
251:            }
252:
253:            private static Properties getWSSSOProperties() {
254:                Properties props = null;
255:
256:                ResourceLoader resourceLoader = ResourceLoader
257:                        .getInstance(System.getProperties());
258:
259:                try {
260:                    props = resourceLoader.getProperties(WSSSO_PROPERTIES);
261:
262:                } catch (FileNotFoundException fnfe) {
263:                    debugLogger.log(Level.SEVERE, "", fnfe);
264:                } catch (IOException ioe) {
265:                    debugLogger.log(Level.SEVERE, "", ioe);
266:                }
267:                return props;
268:            }
269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.