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


001:        package migration.modules.ldap;
002:
003:        import java.util.*;
004:        import java.io.*;
005:
006:        import netscape.ldap.LDAPAttribute;
007:        import netscape.ldap.LDAPAttributeSet;
008:        import netscape.ldap.util.LDIF;
009:        import netscape.ldap.util.LDIFRecord;
010:        import netscape.ldap.util.LDIFAttributeContent;
011:
012:        public class Common {
013:            public static String rootsuffix = "";
014:            public static String orgNaming = "o=";
015:            public static String roleNaming = "cn=";
016:            public static String uidNaming = "uid=";
017:            public static String fs = System.getProperty("file.separator");
018:            public static String IDSAMEBaseDir = fs + "opt";
019:            public static String hostname = "";
020:
021:            public static final String cBasicOrgFile = "BasicOrganization.ldif";
022:            public static final String cBasicUserFile = "BasicUser.ldif";
023:            public static final String cBasicGroupFile = "BasicGroup.ldif";
024:            public static final String cLdif = "ldif";
025:            public static final String cAMConfigFileName = "AMConfig";
026:
027:            /*
028:             * Set Organization Naming Attribute
029:             *
030:             * @param attr representing the organization naming attribute, i.e. o=
031:             */
032:            public static void setOrgNaming(String attr) {
033:                orgNaming = attr;
034:            }
035:
036:            /*
037:             * Set Role Naming Attribute
038:             *
039:             * @param attr representing the role naming attribute, i.e. cn=
040:             */
041:            public static void setRoleNaming(String attr) {
042:                roleNaming = attr;
043:            }
044:
045:            /*
046:             * Set User Id Naming Attribute
047:             *
048:             * @param attr representing the uid naming attribute, i.e. uid=
049:             */
050:            public static void setUidNaming(String attr) {
051:                uidNaming = attr;
052:            }
053:
054:            /*
055:             * Construct Role DN with naming attributes
056:             *
057:             * @param role representing role
058:             * @param org representing org
059:             * @return String representing dn value
060:             */
061:            public static String constructRoleDN(String role, String org) {
062:                return constructRoleDN(role, org, null, false);
063:            }
064:
065:            /*
066:             * Construct Role DN with naming attributes
067:             *
068:             * @param role representing role
069:             * @param org representing org
070:             * @param rootSuffix representing the root suffix
071:             * @return String representing dn value
072:             */
073:            public static String constructRoleDN(String role, String org,
074:                    String rootSuffix) {
075:                return constructRoleDN(role, org, rootSuffix, false);
076:            }
077:
078:            /*
079:             * Construct Role DN with naming attributes
080:             *
081:             * @param role representing role
082:             * @param org representing org
083:             * @param rootSuffix representing the root suffix
084:             * @param noOrgNaming if true do not attach organization naming 
085:             *                    attribute to org value
086:             * @return String representing dn value
087:             */
088:            public static String constructRoleDN(String role, String org,
089:                    String rootSuffix, boolean noOrgNaming) {
090:
091:                String dn = roleNaming + role;
092:
093:                if (noOrgNaming) {
094:                    dn += "," + org;
095:                } else {
096:                    dn += "," + constructOrgDN(org);
097:                }
098:
099:                if (rootSuffix != null) {
100:                    dn += "," + rootSuffix;
101:                }
102:
103:                return dn;
104:            }
105:
106:            /*
107:             * Construct Org DN with naming attributes
108:             *
109:             * @param org representing org
110:             * @param rootSuffix representing the rootSuffix
111:             * @return String representing dn value
112:             */
113:            public static String constructOrgDN(String org) {
114:                return constructOrgDN(org, null);
115:            }
116:
117:            /*
118:             * Construct Org DN with naming attributes
119:             *
120:             * @param org representing org
121:             * @param rootSuffix representing the root suffix
122:             * @return String representing dn value
123:             */
124:            public static String constructOrgDN(String org, String rootSuffix) {
125:                String dn = orgNaming + org;
126:
127:                if (rootSuffix != null) {
128:                    dn += "," + rootSuffix;
129:                }
130:
131:                return dn;
132:            }
133:
134:            /*
135:             * Responsible for getting and setting the Naming Atributes
136:             *
137:             * @param importDir String representing the importDir
138:             */
139:            public static void getNamingAttributes(String importDir) {
140:
141:                orgNaming = getNamingAttribute(importDir + fs + cLdif + fs
142:                        + cBasicOrgFile, orgNaming);
143:                uidNaming = getNamingAttribute(importDir + fs + cLdif + fs
144:                        + cBasicUserFile, uidNaming);
145:                roleNaming = getNamingAttribute(importDir + fs + cLdif + fs
146:                        + cBasicGroupFile, roleNaming);
147:
148:            }
149:
150:            /*
151:             * Responsible for getting the Naming Attribute from the ldif record
152:             *
153:             * @param namingFile String representing the naming file location (ldif record)
154:             * @param def String representing the default naming attribute if not found
155:             * @return String representing the naming attribute
156:             */
157:            public static String getNamingAttribute(String namingFile,
158:                    String def) {
159:                LDIFRecord lrecord = null;
160:                LDIF ldif = null;
161:                String naming = null;
162:
163:                try {
164:                    ldif = new LDIF(namingFile);
165:
166:                    while ((lrecord = ldif.nextRecord()) != null) {
167:                        LDIFAttributeContent lattrContent = (LDIFAttributeContent) lrecord
168:                                .getContent();
169:                        LDAPAttributeSet lattrSet = new LDAPAttributeSet(
170:                                lattrContent.getAttributes());
171:
172:                        if (lattrSet != null) {
173:                            LDAPAttribute lattr = lattrSet
174:                                    .getAttribute("sunkeyvalue");
175:
176:                            if (lattr != null) {
177:                                String[] keys = lattr.getStringValueArray();
178:
179:                                for (int i = 0; i < keys.length; i++) {
180:                                    String key = keys[i];
181:
182:                                    if (key.indexOf("namingattribute") != -1) {
183:                                        StringTokenizer tokenizer = new StringTokenizer(
184:                                                key, "=");
185:
186:                                        if (tokenizer.countTokens() >= 2) {
187:                                            naming = tokenizer.nextToken();
188:                                            naming = tokenizer.nextToken()
189:                                                    + "=";
190:                                        }
191:
192:                                    }
193:                                }
194:
195:                            }
196:                        }
197:                    }
198:
199:                } catch (IOException e) {
200:                    System.out.println("Error:" + e.toString());
201:                    e.printStackTrace();
202:                }
203:
204:                if (naming == null) {
205:                    naming = def;
206:                }
207:
208:                return naming;
209:            }
210:
211:            /*
212:             * Responsible for getting properties within AMConfig.properties 
213:             *
214:             */
215:            public static void getAMConfigProperties() {
216:
217:                Locale locale = Locale.getDefault();
218:                ResourceBundle ambundle = ResourceBundle
219:                        .getBundle(cAMConfigFileName);
220:
221:                if (ambundle.getObject("com.iplanet.am.rootsuffix") != null) {
222:                    rootsuffix = (String) (ambundle
223:                            .getObject("com.iplanet.am.rootsuffix"));
224:                }
225:
226:                if (ambundle.getObject("com.iplanet.am.installdir") != null) {
227:                    IDSAMEBaseDir = (String) (ambundle
228:                            .getObject("com.iplanet.am.installdir"));
229:                }
230:
231:                if (ambundle.getObject("com.iplanet.am.directory.host") != null) {
232:                    hostname = (String) (ambundle
233:                            .getObject("com.iplanet.am.directory.host"));
234:                }
235:
236:            }
237:
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.