Source Code Cross Referenced for GatewayConvert.java in  » Portal » Open-Portal » migration » modules » srap » ldap » 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 » migration.modules.srap.ldap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: GatewayConvert.java,v 1.6 2003/07/04 09:20:59 mm132998 Exp $
003:         * $Source: /m/portal/ps/srap/src/migration/modules/srap/ldap/Attic/GatewayConvert.java,v $
004:         * $Log: GatewayConvert.java,v $
005:         * Revision 1.6  2003/07/04 09:20:59  mm132998
006:         * 3.0 -> 6.2 migration changes
007:         *
008:         * Revision 1.5  2003/06/20 11:39:57  mm132998
009:         * Initial changes for 6.2
010:         *
011:         * Revision 1.2.8.2.6.2  2003/04/10 14:35:09  mm132998
012:         * Bug ID : 4845550
013:         *
014:         * Revision 1.2.8.2.6.1  2003/04/04 09:49:12  mm132998
015:         * Migration changes for 3.0 -> 6.0.1
016:         *
017:         * Revision 1.2.8.2  2002/11/19 11:01:46  bv131302
018:         * CRT#2047 - looking for installdir
019:         *
020:         * Revision 1.2.8.1  2002/09/30 10:48:25  bv131302
021:         * LihueRtm_branch changes
022:         *
023:         * Revision 1.2.6.1  2002/09/23 19:46:12  mm132998
024:         * CRT #1987
025:         *
026:         * Revision 1.3  2002/09/23 19:44:00  mm132998
027:         * CRT #1987
028:         *
029:         * Revision 1.2  2002/07/22 08:47:29  mm132998
030:         * Bug ID - 4718198 , Desc - Initial code changes
031:         *
032:         *
033:         */
034:        /**
035:         * $Id: GatewayConvert.java,v 1.6 2003/07/04 09:20:59 mm132998 Exp $
036:         * Copyright 2002 Sun Microsystems, Inc. All
037:         * rights reserved. Use of this product is subject
038:         * to license terms. Federal Acquisitions:
039:         * Commercial Software -- Government Users
040:         * Subject to Standard License Terms and
041:         * Conditions.
042:         *
043:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
044:         * are trademarks or registered trademarks of Sun Microsystems,
045:         * Inc. in the United States and other countries.
046:         */package migration.modules.srap.ldap;
047:
048:        import netscape.ldap.util.*;
049:
050:        import netscape.ldap.LDAPAttribute;
051:        import netscape.ldap.LDAPAttributeSet;
052:
053:        import java.util.*;
054:        import java.io.*;
055:
056:        public class GatewayConvert {
057:
058:            static FileWriter outFile;
059:            static String rootsuffix;
060:            static LinkedList orgList = new LinkedList();
061:
062:            public static void main(String args[]) {
063:
064:                String outputDir, ldifDir;
065:
066:                ldifDir = new String();// Input file, the LDIF file to be converted....
067:                outputDir = new String();
068:                if (args.length == 2) {
069:                    outputDir = args[1];
070:                    ldifDir = args[0];
071:                } else if (args.length == 1) {
072:                    outputDir = new String("/tmp/xml");
073:                    ldifDir = args[0];
074:                } else if (args.length == 0) {
075:                    System.out
076:                            .println("Input file to be converted not specified!");
077:                    System.out
078:                            .println("Invokation Format is:java GatewayConvert ldif_directory output_dir");
079:                    System.exit(1);
080:                }
081:
082:                doConvert(ldifDir + "/domain.ldif", outputDir
083:                        + "/GatewayOrgAttrs.xml");
084:                doConvert(ldifDir + "/role.ldif", outputDir
085:                        + "/GatewayRoleAttrs.xml");
086:                dumpPolicyList(outputDir + "/GatewayPolicies.xml");
087:                System.exit(0);
088:            }
089:
090:            private static void dumpPolicyList(String fileName) {
091:                try {
092:                    outFile = new FileWriter(fileName);
093:                    printHeader();
094:
095:                    List orgContainerList = OrgContainerParser.parse(orgList,
096:                            rootsuffix);
097:                    Iterator iter = orgContainerList.iterator();
098:
099:                    while (iter.hasNext()) {
100:                        OrgContainer org = (OrgContainer) iter.next();
101:
102:                        OrgContainerParser.writeReferalPolicy(outFile, org,
103:                                "srapGatewayAccessService", "GatewayAccess");
104:                        if (!org.isDummyOrg()) {
105:                            // This is not a dummy root org that we added for populating referal policies.
106:                            // So assign the policies.
107:                            writePolicies(org);
108:                        }
109:                    }
110:
111:                    outFile.write("\n</Requests>");
112:                    outFile.close();
113:                } catch (Exception ex) {
114:                    System.out
115:                            .println("Exception while dumping policies xml file.\n");
116:                    ex.printStackTrace();
117:                }
118:            }
119:
120:            private static void writePolicies(OrgContainer org)
121:                    throws IOException {
122:                // To create and assign the policy
123:
124:                outFile.write("\n <OrganizationRequests DN=\""
125:                        + org.getOrgName() + "\">\n");
126:                outFile.write("\n<CreatePolicy createDN=\"" + org.getOrgName()
127:                        + "\">\n");
128:
129:                outFile
130:                        .write("    <Policy name=\"To enable Basic Authentication through Gateway\" referralPolicy=\"false\">\n");
131:                outFile
132:                        .write("    <Rule name=\"To enable Basic Authentication through Gateway\">\n");
133:                outFile
134:                        .write("    <ServiceName name=\"srapGatewayAccessService\"/>\n");
135:                outFile.write("        <AttributeValuePair>\n");
136:                outFile
137:                        .write("        <Attribute name=\"sunPortalGatewayEnableSSO\"/>\n");
138:                outFile.write("            <Value>true</Value>\n");
139:                outFile.write("        </AttributeValuePair>\n");
140:                outFile.write("    </Rule>\n");
141:                outFile
142:                        .write("    <Subjects name=\"OrgEnableNetlet\" description=\"\">\n");
143:                outFile
144:                        .write("      <Subject name=\"OrgEnableNetlet\" type=\"Organization\">\n");
145:                outFile.write("        <AttributeValuePair>\n");
146:                outFile.write("          <Attribute name=\"Values\"/>\n");
147:                outFile.write("          <Value>" + org.getOrgName()
148:                        + "</Value>\n");
149:                outFile.write("        </AttributeValuePair>\n");
150:                outFile.write("      </Subject>\n");
151:                outFile.write("    </Subjects>\n");
152:                outFile.write("</Policy>\n");
153:                outFile.write("</CreatePolicy>\n");
154:                outFile.write("</OrganizationRequests>\n");
155:            }
156:
157:            public static void doConvert(String ldiffile, String outputfile) {
158:                LDIFRecord out;
159:                int count = 0;
160:                LDIF l1;
161:
162:                try {
163:                    l1 = new LDIF(ldiffile);
164:
165:                    outFile = new FileWriter(outputfile);
166:
167:                    System.out
168:                            .println("Converting LDIF entries corr. to users from file:"
169:                                    + ldiffile + ".....\n");
170:
171:                    LDIFRecord tmp = l1.nextRecord();
172:
173:                    printHeader();
174:                    while (tmp != null) {
175:                        ProcessRecord(tmp);
176:                        tmp = l1.nextRecord();
177:                    }
178:                    outFile.write("\n</Requests>");
179:                    outFile.close();
180:                    //System.out.println("Processed "+count+" entries");
181:                    System.out
182:                            .println("Output available in file " + outputfile);
183:                } catch (Exception e) {
184:                    System.out.println("Error:" + e.toString());
185:                    e.printStackTrace();
186:                }
187:            }
188:
189:            static void printHeader() throws Exception {
190:
191:                Locale locale = Locale.getDefault();
192:                ResourceBundle ambundle;
193:                ambundle = ResourceBundle.getBundle("AMConfig");
194:                String IDSAMEBaseDir = new String();
195:
196:                if (ambundle.getObject("com.iplanet.am.rootsuffix") != null)
197:                    rootsuffix = (String) (ambundle
198:                            .getObject("com.iplanet.am.rootsuffix"));
199:                if (ambundle.getObject("com.iplanet.am.installdir") != null) {
200:                    IDSAMEBaseDir = (String) (ambundle
201:                            .getObject("com.iplanet.am.installdir"));
202:                    IDSAMEBaseDir = IDSAMEBaseDir.substring(0, IDSAMEBaseDir
203:                            .indexOf("SUNWam"));
204:                }
205:                outFile
206:                        .write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
207:                outFile
208:                        .write("\n<!--  PROPRIETARY/CONFIDENTIAL/ Use of this product is subject");
209:                outFile
210:                        .write("\n to license terms. Copyright 2001 Sun Microsystems Inc.");
211:                outFile
212:                        .write("Some preexisting portions Copyright 2001 Netscape");
213:                outFile.write("Communications Corp. All rights reserved. -->");
214:                outFile
215:                        .write("\n<!DOCTYPE Requests PUBLIC \"-//iPlanet//iDSAME 5.0 Admin CLI DTD//EN \" ");
216:                outFile.write("\"file:" + IDSAMEBaseDir
217:                        + "SUNWam/dtd/amAdmin.dtd\">");
218:
219:                outFile.write("\n<Requests>");
220:                return;
221:            }
222:
223:            static void ProcessRecord(LDIFRecord toConvert) throws Exception {
224:                LDIFAttributeContent con;
225:                LDAPAttributeSet theAttrSet;
226:                String[] allAttrs, accesslist, denylist;
227:                String attrName;
228:                String org, profiletype, rolename, parent, dn, profileid;
229:                boolean tabContainerFound = false;
230:                boolean authModulesToAdd = false;
231:                boolean alist_set, dlist_set;
232:
233:                LDAPAttribute[] attrList;
234:
235:                profiletype = parent = rolename = profileid = null;
236:                org = getOrgName(toConvert.getDN());
237:                dn = new String();
238:
239:                alist_set = dlist_set = false;
240:                org = getOrgName(toConvert.getDN());
241:                con = (LDIFAttributeContent) toConvert.getContent();
242:                attrList = con.getAttributes();
243:                theAttrSet = new LDAPAttributeSet(attrList);
244:                accesslist = null;
245:                denylist = null;
246:
247:                for (int i = 0; i < attrList.length; ++i) {
248:                    if ((attrList[i].getName()).equalsIgnoreCase("profiletype")) {
249:                        allAttrs = (((LDAPAttribute) (theAttrSet
250:                                .getAttribute(attrList[i].getName())))
251:                                .getStringValueArray());
252:                        profiletype = allAttrs[0];
253:                    }
254:                    if ((attrList[i].getName()).equalsIgnoreCase("profileid")) {
255:                        allAttrs = (((LDAPAttribute) (theAttrSet
256:                                .getAttribute(attrList[i].getName())))
257:                                .getStringValueArray());
258:                        profileid = allAttrs[0];
259:                    }
260:                    if ((attrList[i].getName()).equalsIgnoreCase("cn")) {
261:                        allAttrs = (((LDAPAttribute) (theAttrSet
262:                                .getAttribute(attrList[i].getName())))
263:                                .getStringValueArray());
264:                        rolename = allAttrs[0];
265:                    }
266:                    if ((attrList[i].getName()).equalsIgnoreCase("parent")) {
267:                        allAttrs = (((LDAPAttribute) (theAttrSet
268:                                .getAttribute(attrList[i].getName())))
269:                                .getStringValueArray());
270:                        parent = allAttrs[0];
271:                    }
272:                }
273:                if (profiletype.equalsIgnoreCase("role"))
274:                    dn = ConstructDN(profileid);
275:
276:                String fqOrgDN = null;
277:                if (profiletype.equalsIgnoreCase("domain")) {
278:                    fqOrgDN = "o=" + org + "," + rootsuffix;
279:                } else if (profiletype.equalsIgnoreCase("role")) {
280:                    fqOrgDN = dn.substring(1) + "," + rootsuffix;
281:                } else {
282:                    System.out.println("Unknown org type : " + profiletype
283:                            + " !!\n");
284:                    throw new RuntimeException("Unknown org type");
285:                }
286:
287:                if (fqOrgDN != null && !orgList.contains(fqOrgDN)) {
288:                    orgList.add(fqOrgDN);
289:                }
290:
291:                if (profiletype.equalsIgnoreCase("domain"))
292:                    outFile.write("\n <OrganizationRequests DN=\"o=" + org
293:                            + "," + rootsuffix + "\">");
294:                if (profiletype.equalsIgnoreCase("role"))
295:                    outFile.write("\n <OrganizationRequests DN=\""
296:                            + dn.substring(1) + "," + rootsuffix + "\">");
297:                outFile.write("\n    <RegisterServices>");
298:                outFile
299:                        .write("\n        <Service_Name>srapGatewayAccessService</Service_Name>");
300:                outFile.write("\n    </RegisterServices>");
301:                outFile.write("\n </OrganizationRequests>");
302:
303:                /* Creating the Service template stuff..*/
304:                if (profiletype.equalsIgnoreCase("domain"))
305:                    outFile.write("\n <OrganizationRequests DN=\"o=" + org
306:                            + "," + rootsuffix + "\">");
307:                if (profiletype.equalsIgnoreCase("role"))
308:                    outFile.write("\n <OrganizationRequests DN=\""
309:                            + dn.substring(1) + "," + rootsuffix + "\">");
310:
311:                //outFile.write("<CreateServiceTemplate ServiceName=\"srapGatewayAccessService\"/>");
312:                outFile.write("<CreateServiceTemplate>\n");
313:                outFile
314:                        .write("    <Service_Name>srapGatewayAccessService</Service_Name>\n");
315:                outFile.write("</CreateServiceTemplate>");
316:                outFile.write("\n </OrganizationRequests>");
317:
318:                for (int i = 0; i < attrList.length; ++i) {
319:                    attrName = attrList[i].getName();
320:                    allAttrs = (((LDAPAttribute) (theAttrSet
321:                            .getAttribute(attrList[i].getName())))
322:                            .getStringValueArray());
323:                    if (attrName.equalsIgnoreCase("iwtUser-URLPrivList-pv-al-")) {
324:                        accesslist = allAttrs;
325:                        alist_set = true;
326:                    }
327:                    if (attrName.equalsIgnoreCase("iwtUser-URLPrivList-pv-de-")) {
328:                        denylist = allAttrs;
329:                        dlist_set = true;
330:                    }
331:                }
332:
333:                if (alist_set && accesslist.length == 1) {
334:                    // See whether this is a empty value ?
335:                    if (accesslist[0].trim().length() == 0) {
336:                        alist_set = false;
337:                    }
338:                }
339:                if (dlist_set && denylist.length == 1) {
340:                    // See whether this is a empty value ?
341:                    if (denylist[0].trim().length() == 0) {
342:                        dlist_set = false;
343:                    }
344:                }
345:
346:                if (dlist_set || alist_set) {
347:                    if (profiletype.equalsIgnoreCase("domain"))
348:                        outFile.write("\n <OrganizationRequests DN=\"o=" + org
349:                                + "," + rootsuffix + "\">");
350:                    if (profiletype.equalsIgnoreCase("role"))
351:                        outFile.write("\n <OrganizationRequests DN=\"" + dn
352:                                + "," + rootsuffix + "\">");
353:                    outFile
354:                            .write("\n   <ModifyServiceTemplate serviceName=\"srapGatewayAccessService\" schemaType=\"Dynamic\">");
355:                    if (alist_set) {
356:                        outFile.write("\n     <AttributeValuePair>");
357:                        outFile
358:                                .write("\n        <Attribute name=\"sunPortalGatewayAccessAllowList\"/>");
359:                        for (int k = 0; k < accesslist.length; ++k) {
360:                            outFile.write("\n        <Value>");
361:                            outFile.write(accesslist[k]);
362:                            outFile.write("</Value>");
363:                        }
364:                        outFile.write("\n    </AttributeValuePair>");
365:                    }
366:                    if (dlist_set) {
367:                        outFile.write("\n     <AttributeValuePair>");
368:                        outFile
369:                                .write("\n        <Attribute name=\"sunPortalGatewayAccessDenyList\"/>");
370:                        for (int k = 0; k < denylist.length; ++k) {
371:                            outFile.write("\n        <Value>");
372:                            outFile.write(denylist[k]);
373:                            outFile.write("</Value>");
374:                        }
375:                        outFile.write("\n    </AttributeValuePair>");
376:                    }
377:                    outFile.write("\n   </ModifyServiceTemplate>");
378:                    outFile.write("\n </OrganizationRequests>");
379:                }
380:
381:                return;
382:            }
383:
384:            static String getOrgName(String dn) {
385:                String orgName = new String();
386:
387:                orgName = dn.substring(3, dn.indexOf(","));
388:                return orgName;
389:            }
390:
391:            static String ConstructDN(String roleFileName) {
392:                String rolename;
393:                String tmp;
394:                String dnToRet;//The DN to be returned
395:
396:                // Given the relative path of the current file. This function constructs the DN of the required Role i.e SUbORganization..*
397:
398:                dnToRet = new String();
399:                tmp = roleFileName;
400:                while (tmp.indexOf("/") >= 0) {
401:                    dnToRet += ",o=" + tmp.substring(tmp.lastIndexOf("/") + 1);
402:                    tmp = tmp.substring(0, tmp.lastIndexOf("/"));
403:                }
404:
405:                return dnToRet;
406:            }
407:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.