Source Code Cross Referenced for CreateTemplates.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:         * CreateTemplates.java
003:         *
004:         * Created on April 1, 2003, 11:51 AM
005:         */
006:
007:        package migration.modules.srap.ldap;
008:
009:        import netscape.ldap.util.*;
010:
011:        import netscape.ldap.LDAPAttribute;
012:        import netscape.ldap.LDAPAttributeSet;
013:
014:        import java.util.*;
015:        import java.io.*;
016:
017:        /**
018:         *
019:         * @author  Mridul Muralidharan
020:         * @version 
021:         */
022:        public class CreateTemplates {
023:            static FileWriter outFile;
024:            static String rootsuffix = "o=isp";
025:            static LinkedList orgList = new LinkedList();
026:
027:            public static void main(String args[]) {
028:
029:                String outputDir, ldifDir;
030:
031:                ldifDir = new String();// Input file, the LDIF file to be converted....
032:                outputDir = new String();
033:                if (args.length == 2) {
034:                    outputDir = args[1];
035:                    ldifDir = args[0];
036:                } else if (args.length == 1) {
037:                    outputDir = new String("/tmp/xml");
038:                    ldifDir = args[0];
039:                } else if (args.length == 0) {
040:                    System.out
041:                            .println("Input file to be converted not specified!");
042:                    System.out
043:                            .println("Invokation Format is:java CreateTemplates ldif_directory output_dir");
044:                    System.exit(1);
045:                }
046:                try {
047:                    ResourceBundle ambundle;
048:                    ambundle = ResourceBundle.getBundle("AMConfig");
049:
050:                    if (ambundle.getObject("com.iplanet.am.rootsuffix") != null) {
051:                        rootsuffix = ambundle.getObject(
052:                                "com.iplanet.am.rootsuffix").toString();
053:                    }
054:                } catch (Exception ex) {
055:                    System.out.println("Error getting resource bundle !\n");
056:                    ex.printStackTrace();
057:                }
058:
059:                doConvert(ldifDir + "/domain.ldif");
060:                doConvert(ldifDir + "/role.ldif");
061:                dumpXmls(outputDir + "/authConfig.xml");
062:                System.out.println("Exiting ...");
063:                System.exit(0);
064:            }
065:
066:            private static void dumpXmls(String fileName) {
067:                try {
068:                    outFile = new FileWriter(fileName);
069:                    printHeader();
070:
071:                    List orgContainerList = OrgContainerParser.parse(orgList,
072:                            rootsuffix);
073:                    Iterator iter = orgContainerList.iterator();
074:
075:                    while (iter.hasNext()) {
076:                        // OrgContainer's toString returns the org name.
077:                        String org = iter.next().toString();
078:                        System.out.println("dumpXmls :: org : " + org);
079:                        writeAuthConfigTemplate(org);
080:                        writePolicyTemplate(org);
081:                    }
082:                    System.out.println("dumpXmls :: Done !!");
083:                    outFile.write("\n</Requests>");
084:                    outFile.close();
085:                } catch (Exception ex) {
086:                    System.out
087:                            .println("Exception while dumping policies xml file.\n");
088:                    ex.printStackTrace();
089:                }
090:            }
091:
092:            private static void writeAuthConfigTemplate(String org)
093:                    throws IOException {
094:                /*
095:                outFile.write("  <OrganizationRequests DN=\""+org+"\">\n");
096:                outFile.write("    <RegisterServices>\n");
097:                outFile.write("      <Service_Name>iPlanetAMAuthConfiguration</Service_Name>\n");
098:                outFile.write("    </RegisterServices>\n");
099:                outFile.write("  </OrganizationRequests>\n");
100:                outFile.write("\n  <OrganizationRequests DN=\""+org+"\">\n");
101:                outFile.write("    <AddSubConfiguration subConfigName = \"Configurations/gatewaypdc\"\n");
102:                outFile.write("        subConfigId = \"NamedConfiguration\"\n");
103:                outFile.write("        priority = \"0\"\n");
104:                outFile.write("        serviceName=\"iPlanetAMAuthConfiguration\">\n");
105:                outFile.write("      <AttributeValuePair>\n");
106:                outFile.write("        <Attribute name=\"iplanet-am-auth-configuration\"/>\n");
107:                outFile.write("        <Value>&lt;AttributeValuePair&gt;&lt;");
108:                outFile.write("Value&gt;com.sun.identity.authentication.modules.cert.Cert REQUIRED &lt;/Value");
109:                outFile.write("&gt;&lt;/AttributeValuePair&gt;</Value>\n");
110:                outFile.write("      </AttributeValuePair>\n");
111:                outFile.write("    </AddSubConfiguration>\n");
112:                outFile.write("  </OrganizationRequests>\n");
113:                 */
114:            }
115:
116:            private static void writePolicyTemplate(String org)
117:                    throws IOException {
118:                outFile.write("  <OrganizationRequests DN=\"" + org + "\">\n");
119:                outFile.write("    <RegisterServices>\n");
120:                outFile
121:                        .write("      <Service_Name>iPlanetAMPolicyConfigService</Service_Name>\n");
122:                outFile.write("    </RegisterServices>\n");
123:                outFile.write("  </OrganizationRequests>\n");
124:                outFile.write("  <OrganizationRequests DN=\"" + org + "\">\n");
125:                outFile.write("    <CreateServiceTemplate>\n");
126:                outFile
127:                        .write("      <Service_Name>iPlanetAMPolicyConfigService</Service_Name>\n");
128:                outFile.write("    </CreateServiceTemplate>\n");
129:                outFile.write("  </OrganizationRequests>\n");
130:            }
131:
132:            public static void doConvert(String ldiffile) {
133:                LDIFRecord out;
134:                int count = 0;
135:                LDIF l1;
136:
137:                try {
138:                    l1 = new LDIF(ldiffile);
139:
140:                    System.out
141:                            .println("Converting LDIF entries corr. to users from file:"
142:                                    + ldiffile + ".....\n");
143:
144:                    LDIFRecord tmp = l1.nextRecord();
145:
146:                    while (tmp != null) {
147:                        ProcessRecord(tmp);
148:                        tmp = l1.nextRecord();
149:                        count++;
150:                    }
151:                    System.out.println("Processed " + count + " entries");
152:                } catch (Exception e) {
153:                    System.out.println("Error:" + e.toString());
154:                    e.printStackTrace();
155:                }
156:            }
157:
158:            static void printHeader() throws Exception {
159:
160:                Locale locale = Locale.getDefault();
161:                ResourceBundle ambundle;
162:                ambundle = ResourceBundle.getBundle("AMConfig");
163:                String IDSAMEBaseDir = new String();
164:
165:                if (ambundle.getObject("com.iplanet.am.installdir") != null) {
166:                    IDSAMEBaseDir = (String) (ambundle
167:                            .getObject("com.iplanet.am.installdir"));
168:                    IDSAMEBaseDir = IDSAMEBaseDir.substring(0, IDSAMEBaseDir
169:                            .indexOf("SUNWam"));
170:                }
171:                outFile
172:                        .write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
173:                outFile
174:                        .write("\n<!--  PROPRIETARY/CONFIDENTIAL/ Use of this product is subject");
175:                outFile
176:                        .write("\n to license terms. Copyright 2001 Sun Microsystems Inc.");
177:                outFile
178:                        .write("Some preexisting portions Copyright 2001 Netscape");
179:                outFile.write("Communications Corp. All rights reserved. -->");
180:                outFile
181:                        .write("\n<!DOCTYPE Requests PUBLIC \"-//iPlanet//iDSAME 5.0 Admin CLI DTD//EN \" ");
182:                outFile.write("\"file:" + IDSAMEBaseDir
183:                        + "SUNWam/dtd/amAdmin.dtd\">");
184:
185:                outFile.write("\n<Requests>");
186:                return;
187:            }
188:
189:            static void ProcessRecord(LDIFRecord toConvert) throws Exception {
190:                LDIFAttributeContent con;
191:                LDAPAttributeSet theAttrSet;
192:                String[] allAttrs, accesslist, denylist;
193:                String attrName;
194:                String org, profiletype, rolename, parent, dn, profileid;
195:                boolean tabContainerFound = false;
196:                boolean authModulesToAdd = false;
197:                boolean alist_set, dlist_set;
198:
199:                LDAPAttribute[] attrList;
200:
201:                profiletype = parent = rolename = profileid = null;
202:                System.out.print("ProcessRecord : ");
203:                System.out.flush();
204:                org = getOrgName(toConvert.getDN());
205:                System.out.println("org : " + org);
206:                dn = new String();
207:
208:                alist_set = dlist_set = false;
209:                org = getOrgName(toConvert.getDN());
210:                con = (LDIFAttributeContent) toConvert.getContent();
211:                attrList = con.getAttributes();
212:                theAttrSet = new LDAPAttributeSet(attrList);
213:                accesslist = null;
214:                denylist = null;
215:
216:                for (int i = 0; i < attrList.length; ++i) {
217:                    if ((attrList[i].getName()).equalsIgnoreCase("profiletype")) {
218:                        allAttrs = (((LDAPAttribute) (theAttrSet
219:                                .getAttribute(attrList[i].getName())))
220:                                .getStringValueArray());
221:                        profiletype = allAttrs[0];
222:                    }
223:                    if ((attrList[i].getName()).equalsIgnoreCase("profileid")) {
224:                        allAttrs = (((LDAPAttribute) (theAttrSet
225:                                .getAttribute(attrList[i].getName())))
226:                                .getStringValueArray());
227:                        profileid = allAttrs[0];
228:                    }
229:                    if ((attrList[i].getName()).equalsIgnoreCase("cn")) {
230:                        allAttrs = (((LDAPAttribute) (theAttrSet
231:                                .getAttribute(attrList[i].getName())))
232:                                .getStringValueArray());
233:                        rolename = allAttrs[0];
234:                    }
235:                    if ((attrList[i].getName()).equalsIgnoreCase("parent")) {
236:                        allAttrs = (((LDAPAttribute) (theAttrSet
237:                                .getAttribute(attrList[i].getName())))
238:                                .getStringValueArray());
239:                        parent = allAttrs[0];
240:                    }
241:                }
242:                if (profiletype.equalsIgnoreCase("role"))
243:                    dn = ConstructDN(profileid);
244:
245:                String fqOrgDN = null;
246:                if (profiletype.equalsIgnoreCase("domain")) {
247:                    fqOrgDN = "o=" + org + "," + rootsuffix;
248:                } else if (profiletype.equalsIgnoreCase("role")) {
249:                    fqOrgDN = dn.substring(1) + "," + rootsuffix;
250:                } else {
251:                    System.out.println("Unknown org type : " + profiletype
252:                            + " !!\n");
253:                    throw new RuntimeException("Unknown org type");
254:                }
255:
256:                if (fqOrgDN != null && !orgList.contains(fqOrgDN)) {
257:                    orgList.add(fqOrgDN);
258:                }
259:                return;
260:            }
261:
262:            static String getOrgName(String dn) {
263:                String orgName = new String();
264:
265:                orgName = dn.substring(3, dn.indexOf(","));
266:                return orgName;
267:            }
268:
269:            static String ConstructDN(String roleFileName) {
270:                String rolename;
271:                String tmp;
272:                String dnToRet;//The DN to be returned
273:
274:                // Given the relative path of the current file. This function constructs the DN of the required Role i.e SUbORganization..*
275:
276:                dnToRet = new String();
277:                tmp = roleFileName;
278:                while (tmp.indexOf("/") >= 0) {
279:                    dnToRet += ",o=" + tmp.substring(tmp.lastIndexOf("/") + 1);
280:                    tmp = tmp.substring(0, tmp.lastIndexOf("/"));
281:                }
282:
283:                return dnToRet;
284:            }
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.