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


001:        /**
002:         * $Id: LDAPUtil.java,v 1.2 2005/11/11 15:55:31 rc135440 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.util;
014:
015:        import java.io.IOException;
016:
017:        import netscape.ldap.LDAPAttributeSet;
018:        import netscape.ldap.LDAPConnection;
019:        import netscape.ldap.LDAPEntry;
020:        import netscape.ldap.LDAPException;
021:        import netscape.ldap.LDAPModification;
022:        import netscape.ldap.LDAPSchema;
023:        import netscape.ldap.factory.JSSESocketFactory;
024:        import netscape.ldap.util.LDIF;
025:        import netscape.ldap.util.LDIFAddContent;
026:        import netscape.ldap.util.LDIFAttributeContent;
027:        import netscape.ldap.util.LDIFContent;
028:        import netscape.ldap.util.LDIFModDNContent;
029:        import netscape.ldap.util.LDIFModifyContent;
030:        import netscape.ldap.util.LDIFRecord;
031:
032:        /**
033:         * This class provides LDAP utility methods for Portal Admin Server
034:         * clients and MBeans.
035:         */
036:        public class LDAPUtil {
037:
038:            public static LDAPConnection getLDAPConnection(String host,
039:                    String port, String principal, String credentials,
040:                    boolean secure) {
041:                int portInt = 0;
042:                LDAPConnection connection = null;
043:
044:                try {
045:                    portInt = Integer.parseInt(port);
046:                    if (secure) {
047:                        connection = new LDAPConnection(new JSSESocketFactory(
048:                                null));
049:                    } else {
050:                        connection = new LDAPConnection();
051:                    }
052:                    connection.getSearchConstraints().setReferrals(true);
053:                    connection.connect(host, portInt, principal, credentials);
054:                } catch (NumberFormatException e) {
055:                    // Ignore it.
056:                } catch (LDAPException e) {
057:                    // Ignore it.
058:                }
059:
060:                return connection;
061:            }
062:
063:            /**
064:             * Loads the given ldif file into the LDAP server with the given
065:             * connection.
066:             *
067:             * @param  ldifFile  the ldif file to be loaded.
068:             * @param  connection  the connection of the LDAP server.
069:             * @exception IOException if an I/O error occurs.
070:             * @exception LDAPException if an opertion cannot be performed on
071:             *            the LDAP server.
072:             */
073:            public static void loadLDIF(String ldifFile,
074:                    LDAPConnection connection) throws IOException,
075:                    LDAPException {
076:
077:                LDIF ldif = new LDIF(ldifFile);
078:                LDIFRecord nextRecord = ldif.nextRecord();
079:
080:                while (nextRecord != null) {
081:                    String dn = nextRecord.getDN();
082:                    LDIFContent content = nextRecord.getContent();
083:                    LDAPAttributeSet attrs = null;
084:
085:                    switch (content.getType()) {
086:                    case LDIFContent.ATTRIBUTE_CONTENT:
087:                        LDIFAttributeContent attributeContent = (LDIFAttributeContent) content;
088:
089:                        attrs = new LDAPAttributeSet(attributeContent
090:                                .getAttributes());
091:                        connection.add(new LDAPEntry(dn, attrs));
092:                        break;
093:                    case LDIFContent.ADD_CONTENT:
094:                        LDIFAddContent addContent = (LDIFAddContent) content;
095:                        attrs = new LDAPAttributeSet(addContent.getAttributes());
096:                        connection.add(new LDAPEntry(dn, attrs));
097:                        break;
098:                    case LDIFContent.DELETE_CONTENT:
099:                        connection.delete(dn);
100:                        break;
101:                    case LDIFContent.MODIFICATION_CONTENT:
102:                        LDAPModification[] modifications = ((LDIFModifyContent) content)
103:                                .getModifications();
104:
105:                        connection.modify(dn, modifications);
106:                        break;
107:                    case LDIFContent.MODDN_CONTENT:
108:                        LDIFModDNContent modDNContent = (LDIFModDNContent) content;
109:                        String rdn = modDNContent.getRDN();
110:                        String newParent = modDNContent.getNewParent();
111:                        boolean deleteOldRDN = modDNContent.getDeleteOldRDN();
112:                        connection.rename(dn, rdn, newParent, deleteOldRDN);
113:                        break;
114:                    }
115:
116:                    nextRecord = ldif.nextRecord();
117:                }
118:            }
119:
120:            /**
121:             * Checks if the given object class exists in the LDAP server with
122:             * the given connection.
123:             *
124:             * @param  objectClass  the object class to be checked for existence.
125:             * @param  connection  the connection to the LDAP server.
126:             * @return <code>true</code> if the given object class exists in
127:             *         the LDAP server; <code>false</code> otherwise.
128:             * @exception LDAPException if fetching the schema from the LDAP
129:             *                          server fails.
130:             */
131:            public static boolean objectClassExists(String objectClass,
132:                    LDAPConnection connection) throws LDAPException {
133:
134:                LDAPSchema schema = new LDAPSchema();
135:                schema.fetchSchema(connection);
136:                return schema.getObjectClass(objectClass) != null;
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.